#include <bits/stdc++.h>
#define ll long long
#define N 100005
using namespace std;
int n,k,p,i,j,x,y,x2,y2,a,o;
ll t;
unordered_map<int,int> r,c,f,g;
map<pair<int,int> ,int> m;
int main()
{
cin>>n>>k>>p;
f[0]=g[0]=n;
for(i=1;i<=k;++i)
{
cin>>x>>y>>a;
m[{x,y}]=a;
r[x]^=a;
c[y]^=a;
}
for(auto e:r)
{
if(!e.second) continue;
f[e.second]++;
o++;
f[0]--;
}
for(auto e:c)
{
if(!e.second) continue;
g[e.second]++;
g[0]--;
}
for(auto e:r)
{
if(!a) continue;
a=e.second;
t+=(n-g[a]);
t-=(n-g[a]-g[0]);
}
for(auto e:c)
{
if(!a) continue;
a=e.second;
t+=(n-f[a]);
}
while(p--)
{
cin>>x>>y>>x2>>y2;
if(x==x2 && y==y2) continue;
t-=n-f[c[y]];
t-=n-g[r[x]];
t-=n-f[c[y2]];
t-=n-g[r[x2]];
if(r[x]!=c[y]) t++;
if(r[x2]!=c[y2]) t++;
if(y==y2) t+=n-f[c[y]];
if(x==x2) t+=n-g[r[x]];
if(x!=x2 && y!=y2)
{
if(r[x2]!=c[y]) t++;
if(r[x]!=c[y2]) t++;
}
if(x!=x2)
{
f[r[x]]--;
r[x]^=m[{x,y}];
f[r[x]]++;
f[r[x2]]--;
r[x2]^=m[{x,y}];
f[r[x2]]++;
}
if(y!=y2)
{
g[c[y]]--;
c[y]^=m[{x,y}];
g[c[y]]++;
g[c[y2]]--;
c[y2]^=m[{x,y}];
g[c[y2]]++;
}
m[{x2,y2}]=m[{x,y}];
m.erase({x,y});
t+=n-f[c[y]];
t+=n-g[r[x]];
t+=n-f[c[y2]];
t+=n-g[r[x2]];
if(r[x]!=c[y]) t--;
if(r[x2]!=c[y2]) t--;
if(y==y2) t-=n-f[c[y]];
if(x==x2) t-=n-g[r[x]];
if(x!=x2 && y!=y2)
{
if(r[x2]!=c[y]) t--;
if(r[x]!=c[y2]) t--;
}
cout<<t<<'\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
6 |
Incorrect |
79 ms |
4544 KB |
Output isn't correct |
7 |
Incorrect |
58 ms |
4472 KB |
Output isn't correct |
8 |
Incorrect |
48 ms |
3804 KB |
Output isn't correct |
9 |
Incorrect |
53 ms |
3852 KB |
Output isn't correct |
10 |
Incorrect |
58 ms |
3864 KB |
Output isn't correct |
11 |
Incorrect |
626 ms |
32340 KB |
Output isn't correct |
12 |
Correct |
616 ms |
32556 KB |
Output is correct |
13 |
Correct |
628 ms |
32328 KB |
Output is correct |
14 |
Incorrect |
669 ms |
32424 KB |
Output isn't correct |
15 |
Incorrect |
611 ms |
32412 KB |
Output isn't correct |
16 |
Incorrect |
629 ms |
32416 KB |
Output isn't correct |
17 |
Incorrect |
643 ms |
32352 KB |
Output isn't correct |
18 |
Incorrect |
670 ms |
32372 KB |
Output isn't correct |
19 |
Incorrect |
631 ms |
32448 KB |
Output isn't correct |
20 |
Correct |
619 ms |
32416 KB |
Output is correct |