Submission #1015985

# Submission time Handle Problem Language Result Execution time Memory
1015985 2024-07-07T08:12:46 Z May27_th Topovi (COCI15_topovi) C++17
6 / 120
2000 ms 62212 KB
#include<bits/stdc++.h>
using namespace std;
#define i64 long long
#define i128 __int128
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
map<int, i64> sumR, sumC, cntR, cntC;
map<pair<int, int>, int> rock;
void Solve(void) {
  int N, K, P; cin >> N >> K >> P;
  i64 ans = 0;
  cntR[0] = cntC[0] = N;
  auto Move = [&] (int r, int c) {
    ans = ans - (N - cntC[sumR[r]]);
    ans = ans - (N - cntR[sumC[c]]);
    if (sumR[r] != sumC[c]) ans ++;

    cntR[sumR[r]] --;
    cntC[sumC[c]] --;
    sumR[r] ^= rock[mp(r, c)];
    sumC[c] ^= rock[mp(r, c)];
    cntR[sumR[r]] ++;
    cntC[sumC[c]] ++;

    ans = ans + (N - cntC[sumR[r]]);
    ans = ans + (N - cntR[sumC[c]]);
    if (sumR[r] != sumC[c]) ans --;
  };
  
  for (int i = 1; i <= N; i ++) {
    int r, c, x; cin >> r >> c >> x;
    rock[mp(r, c)] = x;
    Move(r, c);
  }
  while (P --) {
    int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2;
    Move(r1, c1);
    rock[mp(r2, c2)] = rock[mp(r1, c1)];
    rock.erase(mp(r1, c1));
    Move(r2, c2);
    cout << ans << "\n";
  }
}
signed main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout << fixed << setprecision(10);
  int Tests = 1; // cin >> Tests;
  while (Tests --) {
    Solve();
  }
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 348 KB Output isn't correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Incorrect 1 ms 348 KB Output isn't correct
5 Incorrect 1 ms 344 KB Output isn't correct
6 Incorrect 642 ms 10736 KB Output isn't correct
7 Incorrect 370 ms 8496 KB Output isn't correct
8 Incorrect 482 ms 6992 KB Output isn't correct
9 Incorrect 478 ms 7104 KB Output isn't correct
10 Incorrect 588 ms 8016 KB Output isn't correct
11 Execution timed out 2028 ms 62212 KB Time limit exceeded
12 Execution timed out 2076 ms 62036 KB Time limit exceeded
13 Execution timed out 2055 ms 61952 KB Time limit exceeded
14 Execution timed out 2098 ms 62148 KB Time limit exceeded
15 Execution timed out 2041 ms 62084 KB Time limit exceeded
16 Execution timed out 2044 ms 62032 KB Time limit exceeded
17 Execution timed out 2011 ms 62080 KB Time limit exceeded
18 Execution timed out 2095 ms 62004 KB Time limit exceeded
19 Execution timed out 2080 ms 62036 KB Time limit exceeded
20 Execution timed out 2060 ms 62140 KB Time limit exceeded