#include<bits/stdc++.h>
using namespace std;
int k,p;
long long n,safe;
map<pair<int,int>,int> val;
map<int,int> rowv,colv,nrow,ncol;
void Move(int r,int c,int x)
{
safe-=ncol[rowv[r]];
safe-=nrow[colv[c]];
if(ncol[colv[c]])--ncol[colv[c]];
if(nrow[rowv[r]])--nrow[rowv[r]];
if(rowv[r]==colv[c])++safe;
rowv[r]^=x;
colv[c]^=x;
++ncol[colv[c]];
++nrow[rowv[r]];
safe+=nrow[colv[c]];
safe+=ncol[rowv[r]];
if(colv[c]==rowv[r] && safe)--safe;
}
int main()
{
cin>>n>>k>>p;
safe=n*n;
ncol[0]=n;
nrow[0]=n;
for(int i=1;i<=k;++i)
{
int r,c,x;
cin>>r>>c>>x;
val[{r,c}]=x;
Move(r,c,x);
}
for(int i=1;i<=p;++i)
{
int r1,c1,r2,c2;
cin>>r1>>c1>>r2>>c2;
Move(r1,c1,val[{r1,c1}]);
val[{r2,c2}]=val[{r1,c1}];
val[{r1,c1}]=0;
Move(r2,c2,val[{r2,c2}]);
cout<<n*n-safe<<'\n';
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
3 ms |
384 KB |
Output is correct |
6 |
Correct |
262 ms |
5244 KB |
Output is correct |
7 |
Correct |
214 ms |
4728 KB |
Output is correct |
8 |
Correct |
157 ms |
4020 KB |
Output is correct |
9 |
Correct |
171 ms |
4088 KB |
Output is correct |
10 |
Correct |
236 ms |
4220 KB |
Output is correct |
11 |
Execution timed out |
2043 ms |
32912 KB |
Time limit exceeded |
12 |
Execution timed out |
2051 ms |
33716 KB |
Time limit exceeded |
13 |
Execution timed out |
2040 ms |
33264 KB |
Time limit exceeded |
14 |
Execution timed out |
2066 ms |
33528 KB |
Time limit exceeded |
15 |
Execution timed out |
2037 ms |
33720 KB |
Time limit exceeded |
16 |
Execution timed out |
2059 ms |
33012 KB |
Time limit exceeded |
17 |
Execution timed out |
2059 ms |
33756 KB |
Time limit exceeded |
18 |
Execution timed out |
2054 ms |
32740 KB |
Time limit exceeded |
19 |
Execution timed out |
2047 ms |
33048 KB |
Time limit exceeded |
20 |
Execution timed out |
2025 ms |
31344 KB |
Time limit exceeded |