답안 #961817

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961817 2024-04-12T13:48:49 Z ASN49K Topovi (COCI15_topovi) C++14
120 / 120
798 ms 33836 KB
#include <bits/stdc++.h>

using namespace std;
#define pb push_back
#define all(x) x.begin(),x.end()
#define LINE 0
#define COLOUMN 1
using i64=long long;
map<int,int>value[2],cnt[2];
map<pair<int,int>,int>mpp;
int n;
i64 cost;

void calculate(int poz,int tip,int sign)
{
    cnt[tip][value[tip][poz]]+=sign;
    cost+=sign*(n-cnt[tip^1][value[tip][poz]]);
}
void add(int poz,int val,bool tip)
{
    calculate(poz,tip,-1);
    value[tip][poz]^=val;
    calculate(poz,tip,1);
}

void change(int l1,int r1,int l2,int r2)
{
    int vall=mpp[make_pair(l1,r1)];
    add(l1,vall,LINE);
    add(r1,vall,COLOUMN);
    add(l2,vall,LINE);
    add(r2,vall,COLOUMN);
    mpp[make_pair(l2,r2)]=vall;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int k,q;
    cin>>n>>k>>q;
    cnt[LINE][0]=n;
    cnt[COLOUMN][0]=n;
    for(int i=0;i<k;i++)
    {
        int x,y,k;
        cin>>x>>y>>k;
        add(x,k,LINE);
        add(y,k,COLOUMN);
        mpp[make_pair(x,y)]=k;
    }

    while(q--)
    {
        int l1,r1,l2,r2;
        cin>>l1>>r1>>l2>>r2;
        change(l1,r1,l2,r2);
        cout<<cost<<'\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 73 ms 5256 KB Output is correct
7 Correct 60 ms 4844 KB Output is correct
8 Correct 48 ms 3916 KB Output is correct
9 Correct 49 ms 4152 KB Output is correct
10 Correct 53 ms 4176 KB Output is correct
11 Correct 747 ms 33364 KB Output is correct
12 Correct 798 ms 33600 KB Output is correct
13 Correct 791 ms 33816 KB Output is correct
14 Correct 753 ms 33836 KB Output is correct
15 Correct 712 ms 33588 KB Output is correct
16 Correct 742 ms 33376 KB Output is correct
17 Correct 740 ms 33364 KB Output is correct
18 Correct 726 ms 33424 KB Output is correct
19 Correct 727 ms 33468 KB Output is correct
20 Correct 746 ms 33356 KB Output is correct