#include<bits/stdc++.h>
using namespace std;
#define ll long long
map<ll,int>num;
const ll base=1e9;
struct node{
ll x,y,k,t;
bool operator<(const node&u)const{
return k<u.k;
}
};
struct node1{
set<ll>st;
};
map<ll,node1>hori;
map<ll,node1>ver;
map<ll,node1>skew1;
map<ll,node1>skew2;
int dxy[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};
ll sum_xor=0;
void solve(ll x,ll y,set<ll>&t,vector<node>&S,int ty){
ll v;
if(ty==2)v=y;
else v=x;
auto it=t.lower_bound(v);
if(it==t.begin()&&it==t.end())return ;
if(it!=t.end()){
if(*it==v){
it++;
}
if(it!=t.end()){
ll w=*it;
switch (ty) {
case 1:
S.push_back({w,y,abs(w-x),0});
break;
case 2:
S.push_back({x,w,abs(w-y),2});
break;
case 3:
S.push_back({w,y-(w-x),abs(w-x),7});
break;
default:
S.push_back({w,y+w-x,abs(w-x),1});
break;
}
}
}
it=t.lower_bound(v);
if(it!=t.begin()){
it--;
ll w=*it;
switch (ty) {
case 1:
S.push_back({w,y,abs(w-x),4});
break;
case 2:
S.push_back({x,w,abs(w-y),6});
break;
case 3:
S.push_back({w,y+x-w,abs(w-x),3});
break;
default:
S.push_back({w,y-(x-w),abs(w-x),5});
break;
}
}
// cout<<x<<' '<<y<<' '<<ty<<endl;
}
void update(ll x,ll y,int nnum){
hori[y].st.insert(x);
ver[x].st.insert(y);
skew1[x+y].st.insert(x);
skew2[x-y].st.insert(x);
sum_xor^=x*nnum+y;
}
int main(){
freopen("1.txt","r",stdin);
int n,m,p,q;
cin>>n>>m>>p>>q;
for(int i=1;i<=p;i++){
ll x,y;
cin>>x>>y;
update(x,y,i);
num[x*base+y]=i;
}
while(q--){
ll x,y;
int t;
cin>>x>>y>>t;
vector<node>S;
solve(x,y,hori[y].st,S,1);
solve(x,y,ver[x].st,S,2);
solve(x,y,skew1[x+y].st,S,3);
solve(x,y,skew2[x-y].st,S,4);
sort(S.begin(),S.end());
vector<node>L;
for(int i=0;i<(int)S.size();i++){
if(x-1<S[i].k||y-1<S[i].k||n-x<S[i].k||m-y<S[i].k){
break;
}
if(i==0||S[i].k==S[i-1].k){
ll xx=S[i].x,yy=S[i].y,id=S[i].t,d=S[i].k;
hori[yy].st.erase(xx);
ver[xx].st.erase(yy);
skew1[xx+yy].st.erase(xx);
skew2[xx-yy].st.erase(xx);
int nnum=num[xx*base+yy];
num[xx*base+yy]=0;
sum_xor^=xx*nnum+yy;
ll n_xx=xx-d*dxy[id][0]+d*dxy[(id+t)%8][0];
ll n_yy=yy-d*dxy[id][1]+d*dxy[(id+t)%8][1];
L.push_back({n_xx,n_yy,nnum,0});
// cout<<xx<<' '<<yy<<' '<<nnum<<endl;
}
else {
break;
}
}
for(int i=0;i<(int)L.size();i++){
ll n_xx=L[i].x,n_yy=L[i].y,nnum=L[i].k;
num[n_xx*base+n_yy]=nnum;
update(n_xx,n_yy,nnum);
}
}
cout<<sum_xor<<endl;
return 0;
}
csp31-4
最新推荐文章于 2024-11-09 21:51:15 发布