Submission #95225

#TimeUsernameProblemLanguageResultExecution timeMemory
95225zeyad49Topovi (COCI15_topovi)C++17
120 / 120
1617 ms39820 KiB
#include <cstdio> #include <iostream> #include <map> using namespace std; map<int,int> rows,cols,cntRows,cntCols; map <pair<int, int>, int> power; long long ans; int n; void update(int r,int c,int x) { // subtract all cols with xor !=original xor of row r int original; original=rows[r]; int y=n-cntCols[original]; ans-=y; // add all cols with xor != new xor of row r int newXor=original^x; rows[r]=newXor; int z=cols[c]; cntCols[z^x]++; cntCols[z]--; y=n-cntCols[newXor]; ans+=y; cntRows[original]--; // subtract all rows with xor!=original xor of column c original=z; y=n-1-cntRows[original]; ans-=y; newXor=original^x; cols[c]=newXor; //add all rows with xor!=new xor y=n-1-cntRows[newXor]; ans+=y; z=rows[r]; cntRows[z]++; power[make_pair(r, c)] ^= x; } int main() { cin>>n; int k,p; cin>>k>>p; int r,c,x; cntRows[0]=n; cntCols[0]=n; while(k--){ cin>>r>>c>>x; r--; c--; update(r,c, x); } while(p-->0) { int r1,c1,r2,c2; cin>>r1>>c1>>r2>>c2; r1--; c1--; r2--; c2--; int x=power[make_pair(r1, c1)]; update(r1, c1, x); update(r2,c2,x); cout<<ans<<'\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...