#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ll long long
using namespace std;
map<int,int> xorr,xorc,cntr,cntc;
map<pair<int,int>,int> rook;
ll ans=0;
int n,k,p;
void add(int r,int c,int x){
rook[{r,c}]^=x;
ans-=n-cntc[xorr[r]];
ans-=n-cntr[xorc[c]];
if(xorr[r]!=xorc[c])
ans++;
cntc[xorc[c]]--;
cntr[xorr[r]]--;
xorr[r]^=x;
xorc[c]^=x;
cntc[xorc[c]]++;
cntr[xorr[r]]++;
ans+=n-cntc[xorr[r]];
ans+=n-cntr[xorc[c]];
if(xorr[r]!=xorc[c])
ans--;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>k>>p;
cntr[0]=n;
cntc[0]=n;
rep(i,k){
int r,c,x;
cin >> r >> c >> x;
add(r,c,x);
}
while(p--){
int r1,c1,r2,c2;
cin>>r1>>c1>>r2>>c2;
int x=rook[{r1,c1}];
add(r1,c1,x);
add(r2,c2,x);
cout<<ans<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
376 KB |
Output is correct |
3 |
Correct |
3 ms |
508 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
3 ms |
376 KB |
Output is correct |
6 |
Correct |
175 ms |
6008 KB |
Output is correct |
7 |
Correct |
133 ms |
5368 KB |
Output is correct |
8 |
Correct |
112 ms |
4472 KB |
Output is correct |
9 |
Correct |
105 ms |
4504 KB |
Output is correct |
10 |
Correct |
128 ms |
4728 KB |
Output is correct |
11 |
Correct |
1530 ms |
35124 KB |
Output is correct |
12 |
Correct |
1630 ms |
35068 KB |
Output is correct |
13 |
Correct |
1512 ms |
35084 KB |
Output is correct |
14 |
Correct |
1497 ms |
35020 KB |
Output is correct |
15 |
Correct |
1483 ms |
35152 KB |
Output is correct |
16 |
Correct |
1482 ms |
34940 KB |
Output is correct |
17 |
Correct |
1468 ms |
35192 KB |
Output is correct |
18 |
Correct |
1514 ms |
35164 KB |
Output is correct |
19 |
Correct |
1543 ms |
35252 KB |
Output is correct |
20 |
Correct |
1559 ms |
35012 KB |
Output is correct |