#include <iostream>
#include <vector>
#include <map>
using namespace std;
typedef long long int ll;
int N, K, P;
long long int attacked;
map<pair<int, int>, int> rooks;
map<int, int> valRows, valCols, rowXOR, colXOR;
void init() {
attacked = 0;
valRows[0] = N;
valCols[0] = N;
}
void include(int r, int c, int p) {
attacked -= (ll) (N - valRows[colXOR[c]]);
attacked -= (ll) (N - valCols[rowXOR[r]]);
valRows[rowXOR[r]]--;
valCols[colXOR[c]]--;
rooks[{r, c}] = p;
rowXOR[r] ^= p;
colXOR[c] ^= p;
valRows[rowXOR[r]]++;
valCols[colXOR[c]]++;
attacked += (ll) (N - valRows[colXOR[c]]);
attacked += (ll) (N - valCols[rowXOR[r]]);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int r, c, p, r2, c2;
cin >> N >> K >> P;
init();
for (int i = 0; i < K; i++) {
cin >> r >> c >> p;
include(r-1, c-1, p);
//cout << attacked << '\n';
}
for (int i = 0; i < P; i++) {
cin >> r >> c >> r2 >> c2;
p = rooks[{r-1, c-1}];
include(r-1, c-1, p);
include(r2-1, c2-1, p);
cout << attacked << '\n';
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
112 ms |
5740 KB |
Output is correct |
7 |
Correct |
94 ms |
5228 KB |
Output is correct |
8 |
Correct |
70 ms |
4332 KB |
Output is correct |
9 |
Correct |
75 ms |
4460 KB |
Output is correct |
10 |
Correct |
82 ms |
4588 KB |
Output is correct |
11 |
Correct |
1071 ms |
36928 KB |
Output is correct |
12 |
Correct |
1065 ms |
36588 KB |
Output is correct |
13 |
Correct |
1075 ms |
36588 KB |
Output is correct |
14 |
Correct |
1085 ms |
36792 KB |
Output is correct |
15 |
Correct |
1082 ms |
36552 KB |
Output is correct |
16 |
Correct |
1075 ms |
36612 KB |
Output is correct |
17 |
Correct |
1080 ms |
36588 KB |
Output is correct |
18 |
Correct |
1064 ms |
36588 KB |
Output is correct |
19 |
Correct |
1060 ms |
36780 KB |
Output is correct |
20 |
Correct |
1059 ms |
36784 KB |
Output is correct |