제출 #541970

#제출 시각아이디문제언어결과실행 시간메모리
541970OlympiaTopovi (COCI15_topovi)C++17
6 / 120
2091 ms45496 KiB
#include <vector> #include <algorithm> #include <iostream> #include <set> #include <cmath> #include <map> #include <random> #include <cassert> #include <ctime> #include <cstdlib> #include <limits.h> #include <queue> using namespace std; const int MOD = 10007; class DynamicThing { map<int,int> oc1; map<int,int> oc2; public: int tot = 0; void remove (int type, int index, int quantity) { if (type == 1) { tot -= oc1[index] * oc2[index]; oc1[index] -= quantity; tot += oc1[index] * oc2[index]; } else { tot -= oc1[index] * oc2[index]; oc2[index] -= quantity; tot += oc1[index] * oc2[index]; } } void add (int type, int index, int quantity) { if (type == 1) { tot -= oc1[index] * oc2[index]; oc1[index] += quantity; tot += oc1[index] * oc2[index]; } else { tot -= oc1[index] * oc2[index]; oc2[index] += quantity; tot += oc1[index] * oc2[index]; } } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); map<int,int> row_xor; map<int,int> col_xor; int N, K, P; cin >> N >> K >> P; DynamicThing dt; dt.add(1, 0, N); dt.add(2, 0, N); map<pair<int,int>,int> loc; for (int i = 0; i < N; i++) { int r, c, x; cin >> r >> c >> x; dt.remove(1, row_xor[r], 1 ); dt.remove(2, col_xor[c], 1); row_xor[r] ^= x; col_xor[c] ^= x; dt.add(1, row_xor[r], 1 ); dt.add(2, col_xor[c], 1); loc[{r, c}] = x; } while (P--) { int r1, c1, r2, c2; cin >> r1 >> c1 >> r2 >> c2; if (r1 != r2) { dt.remove(1, row_xor[r1], 1); dt.remove(1, row_xor[r2], 1); } if (c1 != c2) { dt.remove(2, col_xor[c1], 1); dt.remove(2, col_xor[c2], 1); } row_xor[r1] ^= loc[{r1, c1}]; col_xor[c1] ^= loc[{r1, c1}]; row_xor[r2] ^= loc[{r1, c1}]; col_xor[c2] ^= loc[{r1, c1}]; loc[{r2, c2}] = loc[{r1, c1}]; loc[{r1, c1}] = 0; if (r1 != r2) { dt.add(1, row_xor[r1], 1); dt.add(1, row_xor[r2], 1 ); } if (c1 != c2) { dt.add(2, col_xor[c1], 1); dt.add(2, col_xor[c2], 1); } cout << N * N - dt.tot << '\n'; } //cout << dt.tot << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...