답안 #646975

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
646975 2022-10-01T09:34:58 Z Trisanu_Das Topovi (COCI15_topovi) C++17
120 / 120
1040 ms 39512 KB
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);  
  int n, k, p;
  cin >> n >> k >> p;
  long long ans = n * n;
  map<int, int> cx;
  map<int, int> cy;
  cx[0] = n;   
  cy[0] = n;
  map<int, int> xs;
  map<int, int> ys;
  map<pair<int, int>, int> val;
  function<void(int, int, int)> Add = [&](int x, int y, int v) {
    ans -= cx[ys[y]];
    ans -= cy[xs[x]];
    val[{x, y}] = v;
    cx[xs[x]] -= 1;
    cy[ys[y]] -= 1;
    xs[x] ^= v;
    ys[y] ^= v;
    cx[xs[x]] += 1;
    cy[ys[y]] += 1;
    ans += cx[ys[y]];
    ans += cy[xs[x]];
  };
  function<void(int, int, int)> Remove = [&](int x, int y, int v) {
    ans -= cx[ys[y]];
    ans -= cy[xs[x]];
    val[{x, y}] = 0;
    cx[xs[x]] -= 1;
    cy[ys[y]] -= 1;
    xs[x] ^= v;
    ys[y] ^= v;
    cx[xs[x]] += 1;
    cy[ys[y]] += 1;
    ans += cx[ys[y]];
    ans += cy[xs[x]];
  };
  for (int i = 0; i < k; i++) {
    int x, y, a;
    cin >> x >> y >> a;
    Add(x, y, a);
  }
  ans = 0;
  for (auto& p : cx) {
    ans += p.second * 1LL * cy[p.first];
  }
  while (p--) {
    int xa, ya, xb, yb;
    cin >> xa >> ya >> xb >> yb;
    Add(xb, yb, val[{xa, ya}]);
    Remove(xa, ya, val[{xa, ya}]);
    cout << n * 1LL * n - ans << '\n';
  }                                                                  
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 320 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 110 ms 6016 KB Output is correct
7 Correct 103 ms 5300 KB Output is correct
8 Correct 67 ms 4376 KB Output is correct
9 Correct 67 ms 4496 KB Output is correct
10 Correct 79 ms 4672 KB Output is correct
11 Correct 1018 ms 39420 KB Output is correct
12 Correct 1040 ms 39420 KB Output is correct
13 Correct 1026 ms 39380 KB Output is correct
14 Correct 923 ms 39392 KB Output is correct
15 Correct 941 ms 39464 KB Output is correct
16 Correct 922 ms 39332 KB Output is correct
17 Correct 1006 ms 39380 KB Output is correct
18 Correct 953 ms 39512 KB Output is correct
19 Correct 967 ms 39508 KB Output is correct
20 Correct 963 ms 39384 KB Output is correct