#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
#include <unordered_map>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
#define FOR(i,start,end) for(int i=start;i<(int)(end);i++)
#define FORE(i,start,end) for(int i=start;i<=(int)end;i++)
#define RFOR(i,start,end) for(int i = start; i>end; i--)
#define RFORE(i,start,end) for(int i = start; i>=end; i--)
#define all(a) a.begin(), a.end()
#define mt make_tuple
#define v vector
#define sf scanf
#define pf printf
#define dvar(x) cout << #x << " := " << x << "\n"
#define darr(x,n) FOR(i,0,n) cout << #x << "[" << i << "]" << " := " << x[i] << "\n"
typedef long long ll;
typedef long double ld;
typedef pair<int, int > pii;
typedef pair<ll, ll> pll;
//template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<class T> void minn(T &a, T b) { a = min(a, b); }
template<class T> void maxx(T &a, T b) { a = max(a, b); }
inline void io() {
#ifdef LOCAL_PROJECT
freopen("input.in", "r", stdin); freopen("output.out", "w", stdout);
#else
/* online submission */
#endif
ios_base::sync_with_stdio(false); cin.tie(NULL);
}
/***************************************************/
// R, C
ll ans = 0;
int N;
int K, P; // initial, moves
v<pair<pii, int>> initial;
v<pair<pii, pii>> moves;
v<int> colCum, rowCum;
map<int, int> colCnt, rowCnt; // XOR value, cnt
map<pii, int> rooks;
ll contri(int r, int c) {
ll ret = 0;
if (rowCum[r] > 0)
ret += N - colCum.size();
ret += colCum.size() - colCnt[rowCum[r]];
if (colCum[c] > 0)
ret += N - rowCum.size();
ret += rowCum.size() - rowCnt[colCum[c]];
if ((colCum[c] ^ rowCum[r]))
ret--;
return ret;
}
void update(int r, int c, int x) {
ans -= contri(r, c);
rowCnt[rowCum[r]]--;
colCnt[colCum[c]]--;
rowCum[r] ^= x;
colCum[c] ^= x;
rowCnt[rowCum[r]]++;
colCnt[colCum[c]]++;
ans += contri(r, c);
}
void compressCoord() {
v<int> rdat, cdat;
for (auto& x : initial) {
rdat.emplace_back(x.first.first);
cdat.emplace_back(x.first.second);
}
for (auto& x : moves) {
rdat.emplace_back(x.first.first);
cdat.emplace_back(x.first.second);
rdat.emplace_back(x.second.first);
cdat.emplace_back(x.second.second);
}
sort(all(rdat));
rdat.erase(unique(all(rdat)), rdat.end());
sort(all(cdat));
cdat.erase(unique(all(cdat)), cdat.end());
for (auto& x : initial) {
x.first.first = lower_bound(all(rdat), x.first.first) - rdat.begin();
x.first.second = lower_bound(all(cdat), x.first.second) - cdat.begin();
}
for (auto& x : moves) {
x.first.first = lower_bound(all(rdat), x.first.first) - rdat.begin();
x.first.second = lower_bound(all(cdat), x.first.second) - cdat.begin();
x.second.first = lower_bound(all(rdat), x.second.first) - rdat.begin();
x.second.second = lower_bound(all(cdat), x.second.second) - cdat.begin();
}
colCum.resize(cdat.size());
rowCum.resize(rdat.size());
}
int main() {
io();
cin >> N >> K >> P;
initial.resize(K);
moves.resize(P);
FOR(i, 0, K) {
cin >> initial[i].first.first >> initial[i].first.second >> initial[i].second;
}
FOR(i, 0, P) {
cin >> moves[i].first.first >> moves[i].first.second >> moves[i].second.first >> moves[i].second.second;
}
compressCoord();
/* FOR(i, 0, K) {
cout << " " << initial[i].first.first << " " << initial[i].first.second << " " << initial[i].second << "\n";
}
FOR(i, 0, P) {
cout << " " << moves[i].first.first << " " << moves[i].first.second << " " << moves[i].second.first << " " << moves[i].second.second << "\n";
}*/
rowCnt[0] = rowCum.size();
colCnt[0] = colCum.size();
for (auto& op : initial) {
update(op.first.first, op.first.second, op.second);
rooks[op.first] = op.second;
}
for (auto &op : moves) {
int x = rooks[op.first];
update(op.first.first, op.first.second, x);
update(op.second.first, op.second.second, x);
rooks[op.second] = x;
cout << ans << "\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
3 ms |
512 KB |
Output is correct |
3 |
Correct |
2 ms |
512 KB |
Output is correct |
4 |
Correct |
2 ms |
548 KB |
Output is correct |
5 |
Correct |
2 ms |
548 KB |
Output is correct |
6 |
Correct |
60 ms |
4024 KB |
Output is correct |
7 |
Correct |
48 ms |
4416 KB |
Output is correct |
8 |
Correct |
39 ms |
4416 KB |
Output is correct |
9 |
Correct |
40 ms |
4956 KB |
Output is correct |
10 |
Correct |
48 ms |
5696 KB |
Output is correct |
11 |
Correct |
542 ms |
28112 KB |
Output is correct |
12 |
Correct |
628 ms |
34140 KB |
Output is correct |
13 |
Correct |
673 ms |
40024 KB |
Output is correct |
14 |
Correct |
635 ms |
46240 KB |
Output is correct |
15 |
Correct |
640 ms |
52132 KB |
Output is correct |
16 |
Correct |
628 ms |
58104 KB |
Output is correct |
17 |
Correct |
643 ms |
64092 KB |
Output is correct |
18 |
Runtime error |
649 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
19 |
Runtime error |
681 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |
20 |
Runtime error |
698 ms |
66560 KB |
Memory limit exceeded: We have a known bug that the memory usage is measured incorrectly (possibly because of Meltdown/Spectre patch), so your solution may be correct. Please submit again. Sorry for the inconvenience. |