QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#620710 | #5441. Quartz Collection | Cipherxzc | WA | 20ms | 65796kb | C++20 | 3.2kb | 2024-10-07 20:41:07 | 2024-10-07 20:41:08 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
const int N = 1e5 + 5;
struct SegmentTree {
struct segment {
int cnt = 0;
LL val[4] = {};
void rot(int x) {
x = 4 - (x & 3);
rotate(val, val + x, val + 4);
}
};
friend segment operator+(const segment &a, const segment &b) {
segment c = b;
c.rot(a.cnt);
c.cnt += a.cnt;
for (int i = 0; i < 4; i++) {
c.val[i] += a.val[i];
}
return c;
}
int n;
vector<segment> st;
SegmentTree(int n_ = 0) : n(n_) { st.resize(n * 8); }
inline void push_up(int p) {
int lson = p << 1, rson = p << 1 | 1;
st[p] = st[lson] + st[rson];
}
void build(int p, int l, int r) {
if (l == r) {
st[p] = segment();
return;
}
int mid = (l + r) >> 1, lson = p << 1, rson = p << 1 | 1;
build(lson, l, mid);
build(rson, mid + 1, r);
push_up(p);
}
void add(int p, int l, int r, int tar, int x) {
if (l == r) {
if (x == 1) {
st[p].val[st[p].cnt & 3] += tar;
st[p].cnt++;
} else {
st[p].cnt--;
st[p].val[st[p].cnt & 3] -= tar;
}
// for (int i = 0; i < 4; i++) {
// cout << st[p].val[i] << ' ';
// }
// cout << endl;
return;
}
int mid = (l + r) >> 1, lson = p << 1, rson = p << 1 | 1;
if (tar <= mid) {
add(lson, l, mid, tar, x);
} else {
add(rson, mid + 1, r, tar, x);
}
push_up(p);
}
void build() { build(1, -n, n); }
void add(int tar, int x) { add(1, -n, n, tar, x); }
};
int n, q, tot, ax[N], ay[N];
array<int, 3> ques[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> q;
LL sum = 0;
for (int i = 1; i <= n; i++) {
cin >> ax[i] >> ay[i];
sum += ay[i];
}
for (int i = 1; i <= q; i++) {
for (int j = 0; j < 3; j++) {
cin >> ques[i][j];
}
}
SegmentTree st(2e5);
st.build();
int cnt = 0;
for (int i = 1; i <= n; i++) {
if (ax[i] <= ay[i]) {
cnt += 2;
}
st.add(ax[i] - ay[i], 1);
}
auto get = [&]() {
SegmentTree::segment x = st.st[2], y = st.st[3];
y.rot(cnt);
return sum + x.val[0] + x.val[3] + y.val[0] + y.val[3];
};
cout << get() << endl;
for (int i = 1; i <= q; i++) {
auto [t, x, y] = ques[i];
sum -= ay[t];
st.add(ax[t] - ay[t], -1);
if (ax[t] <= ay[t]) {
cnt -= 2;
}
ax[t] = x, ay[t] = y;
if (ax[t] <= ay[t]) {
cnt += 2;
}
sum += ay[t];
st.add(ax[t] - ay[t], 1);
// for (int i = 1; i <= n; i++) {
// cout << ax[i] << ' ' << ay[i] << endl;
// }
cout << get() << endl;
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 8ms
memory: 65528kb
input:
4 5 2 4 5 7 1 7 2 1 4 5 2 1 6 2 4 4 3 2 1 3 3 6 6
output:
13 14 15 14 10 13
result:
ok 6 numbers
Test #2:
score: 0
Accepted
time: 20ms
memory: 65508kb
input:
1 1 1 1 1 1 1
output:
1 1
result:
ok 2 number(s): "1 1"
Test #3:
score: -100
Wrong Answer
time: 12ms
memory: 65796kb
input:
100 100 6 7 100 8 5 61 5 75 59 65 51 47 83 37 34 54 87 46 4 26 21 87 12 97 86 68 60 11 62 76 14 83 29 31 91 62 57 80 47 75 85 97 62 77 91 86 14 25 48 77 83 65 39 61 78 77 45 46 90 74 100 91 86 98 55 5 84 42 91 69 100 4 74 98 60 37 75 44 41 12 15 34 36 1 99 16 7 87 36 26 79 42 41 84 17 98 72 16 38 55...
output:
5133 5032 5028 5029 4997 5017 4974 5004 4951 5012 4975 4942 4912 4896 4978 4944 4861 4811 4813 4750 4752 4686 4636 4648 4577 4650 4628 4709 4699 4707 4736 4811 4757 4779 4738 4709 4705 4759 4822 4856 4793 4797 4776 4736 4743 4822 4750 4765 4719 4682 4644 4620 4556 4525 4630 4612 4559 4596 4562 4528 ...
result:
wrong answer 1st numbers differ - expected: '5109', found: '5133'