답안 #961691

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
961691 2024-04-12T10:28:19 Z tudor_costin Topovi (COCI15_topovi) C++11
120 / 120
1230 ms 39668 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
map<int,int> xor_col,xor_lin;
map<int,int> cnt_col,cnt_lin;
map<pair<int,int>,int> rooks;
void update(int l,int c,ll& sol,int n)
{
    sol=sol-n+cnt_col[xor_lin[l]];
    sol=sol-n+cnt_lin[xor_col[c]];
    if(xor_lin[l]^xor_col[c]) sol++;

    cnt_lin[xor_lin[l]]--;
    xor_lin[l]^=rooks[{l,c}];
    cnt_lin[xor_lin[l]]++;

    cnt_col[xor_col[c]]--;
    xor_col[c]^=rooks[{l,c}];
    cnt_col[xor_col[c]]++;

    sol=sol+n-cnt_col[xor_lin[l]];
    sol=sol+n-cnt_lin[xor_col[c]];
    if(xor_lin[l]^xor_col[c]) sol--;
    return;
}
signed main()
{
    int n,k,p;
    cin>>n>>k>>p;
    cnt_col[0]=n;
    cnt_lin[0]=n;
    ll sol=0;
    while(k--)
    {
        int l,c,x;
        cin>>l>>c>>x;
        rooks[{l,c}]=x;
        update(l,c,sol,n);
    }
    while(p--)
    {
        int r1,c1,r2,c2;
        cin>>r1>>c1>>r2>>c2;
        update(r1,c1,sol,n);
        rooks[{r2,c2}]=rooks[{r1,c1}];
        update(r2,c2,sol,n);
        rooks[{r1,c1}]=0;
        cout<<sol<<'\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 1 ms 348 KB Output is correct
4 Correct 1 ms 456 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 151 ms 6036 KB Output is correct
7 Correct 112 ms 5444 KB Output is correct
8 Correct 95 ms 4344 KB Output is correct
9 Correct 90 ms 4504 KB Output is correct
10 Correct 103 ms 4688 KB Output is correct
11 Correct 1194 ms 39504 KB Output is correct
12 Correct 1183 ms 39424 KB Output is correct
13 Correct 1172 ms 39516 KB Output is correct
14 Correct 1177 ms 39364 KB Output is correct
15 Correct 1160 ms 39360 KB Output is correct
16 Correct 1191 ms 39432 KB Output is correct
17 Correct 1169 ms 39464 KB Output is correct
18 Correct 1200 ms 39536 KB Output is correct
19 Correct 1182 ms 39532 KB Output is correct
20 Correct 1230 ms 39668 KB Output is correct