Submission #153943

#TimeUsernameProblemLanguageResultExecution timeMemory
153943nicolaalexandraTopovi (COCI15_topovi)C++14
60 / 120
2106 ms38360 KiB
#include <iostream> #include <set> #include <map> #define INF 2000000000 using namespace std; int n,k,q,sol,l,c,val,l1,l2,c1,c2,i; map <int,int> dp_l,dp_c,fr_l,fr_c; map <pair<int,int>,int> value; int main (){ cin>>n>>k>>q; /// numar cate casute au valorea 0 long long sol = 1LL*n*n; fr_l[0] = n, fr_c[0] = n; for (i=1;i<=k;i++){ cin>>l>>c>>val; sol -= fr_l[dp_c[c]]; sol -= fr_c[dp_l[l]]; fr_l[dp_l[l]]--, fr_c[dp_c[c]]--; dp_l[l] ^= val, dp_c[c] ^= val; fr_l[dp_l[l]]++, fr_c[dp_c[c]]++; /// tin minte frecv pt linii si coloane sol += fr_l[dp_c[c]]; sol += fr_c[dp_l[l]]; value[make_pair(l,c)] = val; } for (;q--;){ cin>>l1>>c1>>l2>>c2; int val = value[make_pair(l1,c1)]; /// sterg value[make_pair(l1,c1)] = 0; sol -= fr_l[dp_c[c1]]; sol -= fr_c[dp_l[l1]]; fr_l[dp_l[l1]]--, fr_c[dp_c[c1]]--; dp_l[l1] ^= val, dp_c[c1] ^= val; fr_l[dp_l[l1]]++, fr_c[dp_c[c1]]++; sol += fr_l[dp_c[c1]]; sol += fr_c[dp_l[l1]]; /// adaug value[make_pair(l2,c2)] = val; sol -= fr_l[dp_c[c2]]; sol -= fr_c[dp_l[l2]]; fr_l[dp_l[l2]]--, fr_c[dp_c[c2]]--; dp_l[l2] ^= val, dp_c[c2] ^= val; fr_l[dp_l[l2]]++, fr_c[dp_c[c2]]++; sol += fr_l[dp_c[c2]]; sol += fr_c[dp_l[l2]]; cout<<1LL*n*n-sol<<"\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...