Submission #113316

#TimeUsernameProblemLanguageResultExecution timeMemory
113316IVIosabTopovi (COCI15_topovi)C++17
120 / 120
1737 ms46080 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define f first #define s second ll n,k,p; ll ans=0; map<pair<int,int>,long long> mpr; map<int,long long> rows,cols,cntrows,cntcols; void update(int r,int c,int x){ ans-=(n-cntrows[cols[c]]); ans-=(n-cntcols[rows[r]]); if(rows[r]==cols[c]){ ans++; } cntrows[rows[r]]--; rows[r]^=x; cntrows[rows[r]]++; cntcols[cols[c]]--; cols[c]^=x; cntcols[cols[c]]++; ans+=(n-cntrows[cols[c]]); ans+=(n-cntcols[rows[r]]); if(rows[r]==cols[c]){ ans--; } } int main() { //freopen("sample-8.in", "r", stdin); //freopen("output8.txt", "w", stdout); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n>>k>>p; cntcols[0]=cntrows[0]=n; for(int i=0;i<k;i++){ int a,b,x; cin>>a>>b>>x; mpr[{a,b}]=x; update(a,b,x); } for(int i=0;i<p;i++){ int a,b,c,d; cin>>a>>b>>c>>d; long long x=mpr[{a,b}]; update(a,b,x); update(c,d,x); mpr[{c,d}]=x; cout<<ans<<endl; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...