Submission #961691

#TimeUsernameProblemLanguageResultExecution timeMemory
961691tudor_costinTopovi (COCI15_topovi)C++11
120 / 120
1230 ms39668 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; map<int,int> xor_col,xor_lin; map<int,int> cnt_col,cnt_lin; map<pair<int,int>,int> rooks; void update(int l,int c,ll& sol,int n) { sol=sol-n+cnt_col[xor_lin[l]]; sol=sol-n+cnt_lin[xor_col[c]]; if(xor_lin[l]^xor_col[c]) sol++; cnt_lin[xor_lin[l]]--; xor_lin[l]^=rooks[{l,c}]; cnt_lin[xor_lin[l]]++; cnt_col[xor_col[c]]--; xor_col[c]^=rooks[{l,c}]; cnt_col[xor_col[c]]++; sol=sol+n-cnt_col[xor_lin[l]]; sol=sol+n-cnt_lin[xor_col[c]]; if(xor_lin[l]^xor_col[c]) sol--; return; } signed main() { int n,k,p; cin>>n>>k>>p; cnt_col[0]=n; cnt_lin[0]=n; ll sol=0; while(k--) { int l,c,x; cin>>l>>c>>x; rooks[{l,c}]=x; update(l,c,sol,n); } while(p--) { int r1,c1,r2,c2; cin>>r1>>c1>>r2>>c2; update(r1,c1,sol,n); rooks[{r2,c2}]=rooks[{r1,c1}]; update(r2,c2,sol,n); rooks[{r1,c1}]=0; cout<<sol<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...