Submission #887266

# Submission time Handle Problem Language Result Execution time Memory
887266 2023-12-14T07:08:19 Z vjudge1 Topovi (COCI15_topovi) C++17
120 / 120
431 ms 35580 KB
#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
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 600 KB Output is correct
6 Correct 24 ms 5084 KB Output is correct
7 Correct 21 ms 4712 KB Output is correct
8 Correct 18 ms 4116 KB Output is correct
9 Correct 21 ms 4208 KB Output is correct
10 Correct 19 ms 4208 KB Output is correct
11 Correct 298 ms 35188 KB Output is correct
12 Correct 357 ms 35124 KB Output is correct
13 Correct 331 ms 35168 KB Output is correct
14 Correct 367 ms 35076 KB Output is correct
15 Correct 398 ms 35324 KB Output is correct
16 Correct 431 ms 35192 KB Output is correct
17 Correct 365 ms 35580 KB Output is correct
18 Correct 350 ms 35196 KB Output is correct
19 Correct 357 ms 35364 KB Output is correct
20 Correct 303 ms 35192 KB Output is correct