Submission #98651

#TimeUsernameProblemLanguageResultExecution timeMemory
98651duy_tranTopovi (COCI15_topovi)C++14
120 / 120
1799 ms33668 KiB
#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=val[{r,c}]; int vr=rowv[r]; int vc=colv[c]; int nr=nrow[vc]; int nc=ncol[vr]; safe-=nc; safe-=nr; if(ncol[vc])--ncol[vc]; if(nrow[vr])--nrow[vr]; if(vr==vc)++safe; vr^=x; vc^=x; rowv[r]=vr; colv[c]=vc; ++ncol[vc]; ++nrow[vr]; safe+=nrow[vc]; safe+=ncol[vr]; if(vc==vr && 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); } for(int i=1;i<=p;++i) { int r1,c1,r2,c2; cin>>r1>>c1>>r2>>c2; Move(r1,c1); val[{r2,c2}]=val[{r1,c1}]; val[{r1,c1}]=0; Move(r2,c2); cout<<n*n-safe<<'\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...