Submission #113316

# Submission time Handle Problem Language Result Execution time Memory
113316 2019-05-24T20:50:25 Z IVIosab Topovi (COCI15_topovi) C++17
120 / 120
1737 ms 46080 KB
#include <bits/stdc++.h>

using namespace std;
#define ll long long
#define f first
#define s second
ll n,k,p;
ll ans=0;
map<pair<int,int>,long long> mpr;
map<int,long long> rows,cols,cntrows,cntcols;

void update(int r,int c,int x){
    ans-=(n-cntrows[cols[c]]);
    ans-=(n-cntcols[rows[r]]);
    if(rows[r]==cols[c]){
        ans++;
    }
    cntrows[rows[r]]--;
    rows[r]^=x;
    cntrows[rows[r]]++;
    cntcols[cols[c]]--;
    cols[c]^=x;
    cntcols[cols[c]]++;
    ans+=(n-cntrows[cols[c]]);
    ans+=(n-cntcols[rows[r]]);
    if(rows[r]==cols[c]){
        ans--;
    }
}

int main() {
    //freopen("sample-8.in", "r", stdin);
    //freopen("output8.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>k>>p;
    cntcols[0]=cntrows[0]=n;
    for(int i=0;i<k;i++){
        int a,b,x;
        cin>>a>>b>>x;
        mpr[{a,b}]=x;
        update(a,b,x);
    }
    for(int i=0;i<p;i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        long long x=mpr[{a,b}];
        update(a,b,x);
        update(c,d,x);
        mpr[{c,d}]=x;
        cout<<ans<<endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 384 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 184 ms 7032 KB Output is correct
7 Correct 152 ms 6300 KB Output is correct
8 Correct 114 ms 5240 KB Output is correct
9 Correct 122 ms 5224 KB Output is correct
10 Correct 134 ms 5608 KB Output is correct
11 Correct 1585 ms 45856 KB Output is correct
12 Correct 1663 ms 46020 KB Output is correct
13 Correct 1700 ms 45944 KB Output is correct
14 Correct 1726 ms 45932 KB Output is correct
15 Correct 1737 ms 45820 KB Output is correct
16 Correct 1681 ms 46080 KB Output is correct
17 Correct 1665 ms 45888 KB Output is correct
18 Correct 1551 ms 45944 KB Output is correct
19 Correct 1688 ms 45892 KB Output is correct
20 Correct 1686 ms 45872 KB Output is correct