답안 #98625

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
98625 2019-02-25T02:03:19 Z minhtung0404 Topovi (COCI15_topovi) C++17
120 / 120
1372 ms 33776 KB
#include<bits/stdc++.h>
const int N = 1e5 + 5;
using namespace std;

typedef pair <int, int> ii;
map <int, int> mp[2], val[2];
map <ii, int> ro;
int n, k, p;
long long ans;

void add(int i, int num, int x){
    int& cur = val[i][num];
    ans += 1LL * mp[0][cur] * mp[1][cur];
    mp[i][cur]--;
    ans -= 1LL * mp[0][cur] * mp[1][cur];

    cur ^= x;

    ans += 1LL * mp[0][cur] * mp[1][cur];
    mp[i][cur]++;
    ans -= 1LL * mp[0][cur] * mp[1][cur];
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> k >> p;
    mp[0][0] = mp[1][0] = n;
    while (k--){
        int r, c, x;
        cin >> r >> c >> x;
        add(0, r, x); add(1, c, x);
        ro[ii(r,c)] = x;
    }
    while (p--){
        int r1, c1, r2, c2;
        cin >> r1 >> c1 >> r2 >> c2;
        int x = ro[ii(r1,c1)];
        ro[ii(r1,c1)] = 0; ro[ii(r2,c2)] = x;
        add(0, r1, x); add(1, c1, x);
        add(0, r2, x); add(1, c2, x);
        cout << ans << "\n";
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 384 KB Output is correct
2 Correct 3 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 3 ms 384 KB Output is correct
6 Correct 128 ms 5456 KB Output is correct
7 Correct 93 ms 4860 KB Output is correct
8 Correct 80 ms 4088 KB Output is correct
9 Correct 88 ms 4020 KB Output is correct
10 Correct 85 ms 4276 KB Output is correct
11 Correct 1347 ms 33632 KB Output is correct
12 Correct 1328 ms 33776 KB Output is correct
13 Correct 1372 ms 33532 KB Output is correct
14 Correct 1294 ms 33656 KB Output is correct
15 Correct 1284 ms 33728 KB Output is correct
16 Correct 1242 ms 33508 KB Output is correct
17 Correct 1290 ms 33656 KB Output is correct
18 Correct 1131 ms 33604 KB Output is correct
19 Correct 1315 ms 33656 KB Output is correct
20 Correct 1244 ms 33640 KB Output is correct