Submission #98645

#TimeUsernameProblemLanguageResultExecution timeMemory
98645duy_tranTopovi (COCI15_topovi)C++14
60 / 120
2066 ms33756 KiB
#include<bits/stdc++.h>
using namespace std;

int k,p;
long long n,safe;
map<pair<int,int>,int> val;
map<int,int> rowv,colv,nrow,ncol;

void Move(int r,int c,int x)
{
    safe-=ncol[rowv[r]];
    safe-=nrow[colv[c]];

    if(ncol[colv[c]])--ncol[colv[c]];
    if(nrow[rowv[r]])--nrow[rowv[r]];

    if(rowv[r]==colv[c])++safe;

    rowv[r]^=x;
    colv[c]^=x;

    ++ncol[colv[c]];
    ++nrow[rowv[r]];

    safe+=nrow[colv[c]];
    safe+=ncol[rowv[r]];

    if(colv[c]==rowv[r] && safe)--safe;
}

int main()
{
    cin>>n>>k>>p;

    safe=n*n;

    ncol[0]=n;
    nrow[0]=n;

    for(int i=1;i<=k;++i)
    {
        int r,c,x;
        cin>>r>>c>>x;

        val[{r,c}]=x;

        Move(r,c,x);
    }

    for(int i=1;i<=p;++i)
    {
        int r1,c1,r2,c2;
        cin>>r1>>c1>>r2>>c2;

        Move(r1,c1,val[{r1,c1}]);
        val[{r2,c2}]=val[{r1,c1}];
        val[{r1,c1}]=0;
        Move(r2,c2,val[{r2,c2}]);

        cout<<n*n-safe<<'\n';
    }
}
#Verdict Execution timeMemoryGrader output
Fetching results...