# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
489751 | cpp219 | Topovi (COCI15_topovi) | C++14 | 627 ms | 32792 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |