# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
887266 | vjudge1 | Topovi (COCI15_topovi) | C++17 | 431 ms | 35580 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.
#ifndef Local
#pragma GCC optimize("O3,unroll-loops")
const int lim=1e6+100;
#else
const int lim=2e3+100;
#endif
#include "bits/stdc++.h"
using namespace std;
#define int int64_t
#define pb push_back
const int mod=1e9+7;
using pii=pair<int,int>;
int n,k,p;
unordered_map<int,int>row,col,countcol,countrow;
int ans=0;
void insert(int x,int y,int z){
int rowy=row[x],coly=col[y];
ans-=2*n-countcol[rowy]-countrow[coly]-2*(rowy!=coly);
countrow[rowy]--;
countcol[coly]--;
rowy=(row[x]^=z);
coly=(col[y]^=z);
countrow[rowy]++;
countcol[coly]++;
ans+=2*n-countcol[rowy]-countrow[coly]-2*(rowy!=coly);
}
inline void solve(){
cin>>n>>k>>p;
unordered_map<int,int>val;
countcol[0]=n;
countrow[0]=n;
for(int i=0;i<k;i++){
int x,y,z;
cin>>x>>y>>z;
insert(x,y,z);
val[x*(1e9+1)+y]=z;
}
for(int i=0;i<p;i++){
int x1,y1,x2,y2;
cin>>x1>>y1>>x2>>y2;
insert(x1,y1,val[x1*(1e9+1)+y1]);
insert(x2,y2,val[x1*(1e9+1)+y1]);
val[x2*(1e9+1)+y2]=val[x1*(1e9+1)+y1];
val[x1*(1e9+1)+y1]=0;
cout<<ans<<"\n";
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);cout.tie(NULL);
#ifdef Local
freopen(".in","r",stdin);
freopen(".out","w",stdout);
#else
//freopen("grass.in","r",stdin);
//freopen("grass.out","w",stdout);
#endif
int t=1;
//cin>>t;
while (t--)
{
solve();
}
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |