답안 #156357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
156357 2019-10-05T10:26:20 Z Moses Topovi (COCI15_topovi) C++14
120 / 120
1456 ms 39776 KB
// Created by AboAbdoMC
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,n) for(int i=0;i<(n);++i)
#define repA(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long

using namespace std;
using namespace __gnu_pbds;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;

map<int,int> xorr,xorc;
map<int,int> cntr,cntc;
map<pair<int,int>,int> rook;
ll ans = 0;
int n,k,p;
void add(int r,int c,int x)
{
    rook[{r,c}] ^= x;
    ans -= n-cntc[xorr[r]];
    ans -= n-cntr[xorc[c]];
    if (xorr[r] != xorc[c]) ans++;
    cntc[xorc[c]]--;
    cntr[xorr[r]]--;
    xorr[r] ^= x;
    xorc[c] ^= x;
    cntc[xorc[c]]++;
    cntr[xorr[r]]++;
    ans += n-cntc[xorr[r]];
    ans += n-cntr[xorc[c]];
    if (xorr[r] != xorc[c]) ans--;
    //db2(xorr[r],xorc[c]);
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    
    cin >> n >> k >> p;
    cntr[0] = n;
    cntc[0] = n;
    rep(i,k)
    {
    	int r,c,x;
    	cin >> r >> c >> x;
    	add(r,c,x);
        //db1(ans);
    }
    
    
    
    while(p--)
    {
    	int r1,c1,r2,c2;
    	cin >> r1 >> c1 >> r2 >> c2;
        int x = rook[{r1,c1}];
    	add(r1,c1,x);
        add(r2,c2,x);
    	cout << ans << '\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 504 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 157 ms 6040 KB Output is correct
7 Correct 122 ms 5444 KB Output is correct
8 Correct 99 ms 4472 KB Output is correct
9 Correct 104 ms 4540 KB Output is correct
10 Correct 123 ms 4860 KB Output is correct
11 Correct 1401 ms 39456 KB Output is correct
12 Correct 1456 ms 39456 KB Output is correct
13 Correct 1377 ms 39600 KB Output is correct
14 Correct 1368 ms 39644 KB Output is correct
15 Correct 1354 ms 39564 KB Output is correct
16 Correct 1402 ms 39652 KB Output is correct
17 Correct 1409 ms 39420 KB Output is correct
18 Correct 1407 ms 39388 KB Output is correct
19 Correct 1401 ms 39724 KB Output is correct
20 Correct 1419 ms 39776 KB Output is correct