# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
98645 | duy_tran | Topovi (COCI15_topovi) | C++14 | 2066 ms | 33756 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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';
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |