Submission #959264

#TimeUsernameProblemLanguageResultExecution timeMemory
959264nihonTopovi (COCI15_topovi)C++14
18 / 120
670 ms32556 KiB
#include <bits/stdc++.h>
#define ll long long
#define N 100005
using namespace std;
int n,k,p,i,j,x,y,x2,y2,a,o;
ll t;
unordered_map<int,int> r,c,f,g;
map<pair<int,int> ,int> m;
int main()
{
    cin>>n>>k>>p;
    f[0]=g[0]=n;
    for(i=1;i<=k;++i)
    {
        cin>>x>>y>>a;
        m[{x,y}]=a;
        r[x]^=a;
        c[y]^=a;
    }
    for(auto e:r)
    {
        if(!e.second) continue;
        f[e.second]++;
        o++;
        f[0]--;
    }
    for(auto e:c)
    {
        if(!e.second) continue;
        g[e.second]++;
        g[0]--;
    }
    for(auto e:r)
    {
        if(!a) continue;
        a=e.second;
        t+=(n-g[a]);
        t-=(n-g[a]-g[0]);
    }
    for(auto e:c)
    {
        if(!a) continue;
        a=e.second;
        t+=(n-f[a]);

    }
    while(p--)
    {
        cin>>x>>y>>x2>>y2;
        if(x==x2 && y==y2) continue;
        t-=n-f[c[y]];
        t-=n-g[r[x]];
        t-=n-f[c[y2]];
        t-=n-g[r[x2]];
        if(r[x]!=c[y]) t++;
        if(r[x2]!=c[y2]) t++;
        if(y==y2) t+=n-f[c[y]];
        if(x==x2) t+=n-g[r[x]];
        if(x!=x2 && y!=y2)
        {
            if(r[x2]!=c[y]) t++;
            if(r[x]!=c[y2]) t++;
        }

        if(x!=x2)
        {
            f[r[x]]--;
            r[x]^=m[{x,y}];
            f[r[x]]++;

            f[r[x2]]--;
            r[x2]^=m[{x,y}];
            f[r[x2]]++;
        }
        if(y!=y2)
        {
            g[c[y]]--;
            c[y]^=m[{x,y}];
            g[c[y]]++;

            g[c[y2]]--;
            c[y2]^=m[{x,y}];
            g[c[y2]]++;
        }

        m[{x2,y2}]=m[{x,y}];
        m.erase({x,y});

        t+=n-f[c[y]];
        t+=n-g[r[x]];
        t+=n-f[c[y2]];
        t+=n-g[r[x2]];
        if(r[x]!=c[y]) t--;
        if(r[x2]!=c[y2]) t--;
        if(y==y2) t-=n-f[c[y]];
        if(x==x2) t-=n-g[r[x]];
        if(x!=x2 && y!=y2)
        {
            if(r[x2]!=c[y]) t--;
            if(r[x]!=c[y2]) t--;
        }
        cout<<t<<'\n';
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...