Submission #489751

#TimeUsernameProblemLanguageResultExecution timeMemory
489751cpp219Topovi (COCI15_topovi)C++14
120 / 120
627 ms32792 KiB
#include<bits/stdc++.h> #define ll long long #define ld long double #define fs first #define sc second #define debug(y) cout<<y,exit(0) using namespace std; typedef pair<ll,ll> LL; const ll N = 1e6 + 9; const ll inf = 1e9 + 7; map<LL,ll> power; unordered_map<ll,ll> cntA,cntB,r,c; ll n,k,Q,ans; void update(ll x,ll y,ll val){ ll nwB = r[x] ^ val,nwA = c[y] ^ val; ans += cntA[r[x]] - cntA[nwB]; cntB[r[x]]--; cntB[nwB]++; r[x] = nwB; ans += cntB[c[y]] - cntB[nwA]; cntA[c[y]]--; cntA[nwA]++; c[y] = nwA; } ll x,y,w; int main(){ ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0); #define task "tst" if (fopen(task".inp","r")){ freopen(task".inp","r",stdin); //freopen(task".out","w",stdout); } cin>>n>>k>>Q; cntA[0] = cntB[0] = n; while(k--){ cin>>x>>y>>w; update(x,y,w); power[{x,y}] = w; } //debug(ans); while(Q--){ ll x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2; update(x1,y1,power[{x1,y1}]); update(x2,y2,power[{x1,y1}]); swap(power[{x2,y2}],power[{x1,y1}]); cout<<ans<<"\n"; } } /* stuff you should look for * int overflow, array bounds * special cases (n=1?) * do smth instead of nothing and stay organized * WRITE STUFF DOWN * DON'T GET STUCK ON ONE APPROACH */

Compilation message (stderr)

topovi.cpp: In function 'int main()':
topovi.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...