QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#724605 | #5441. Quartz Collection | Alorithm | WA | 20ms | 65760kb | C++17 | 2.0kb | 2024-11-08 14:01:30 | 2024-11-08 14:01:35 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
using i64 = long long;
const i64 INF = 1e5 + 5;
struct SegTree {
#define ls (p << 1)
#define rs ((p << 1) | 1)
#define mid ((l + r) >> 1)
int n, cnt;
vector<i64> siz;
vector<vector<i64> > val;
SegTree(int N = (INF << 1)) : n(N) {
siz.resize(n << 2);
val = vector(n << 2, vector<i64>(4));
}
void update(int p) {
siz[p] = siz[ls] + siz[rs];
for (int i = 0; i < 4; i++) {
val[p][i] = val[ls][i];
val[p][(i + siz[ls]) % 4] += val[rs][i];
}
}
void add(i64 x, int k, int p = 1, i64 l = -INF, i64 r = INF) {
if (l == r) {
if (k == 1)
val[p][siz[p] % 4] += x;
else
val[p][(siz[p] - 1) % 4] -= x;
siz[p] += k;
return;
}
if (x <= mid)
add(x, k, ls, l, mid);
else
add(x, k, rs, mid + 1, r);
update(p);
}
i64 query(int p = 1) {
i64 resl = val[ls][0] + val[ls][3], resr = 0;
if (siz[ls] * 2 % 4 == 0)
resr = val[rs][0] + val[rs][2];
else
resr = val[rs][1] + val[rs][3];
return resl + resr;
}
};
void solve() {
int n, m;
cin >> n >> m;
SegTree tr;
i64 sumb = 0;
vector<i64> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
sumb += b[i];
tr.add(a[i] - b[i], 1);
}
cout << tr.query() + sumb << endl;
while (m--) {
int x, aa, bb;
cin >> x >> aa >> bb;
sumb -= b[x];
tr.add(a[x] - b[x], -1);
a[x] = aa;
b[x] = bb;
sumb += b[x];
tr.add(a[x] - b[x], 1);
cout << tr.query() + sumb << endl;
}
// cout << "YES\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 15ms
memory: 65660kb
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: 11ms
memory: 65736kb
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: 20ms
memory: 65760kb
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:
5047 5019 5009 4952 4906 5078 5050 4885 4954 4985 5098 4945 4953 4750 4786 4755 4753 4822 4774 4781 4756 4744 4685 4655 4578 4717 4609 4589 4570 4584 4630 4588 4565 4531 4488 4414 4421 4482 4564 4687 4762 4883 4761 4594 4610 4671 4598 4572 4578 4572 4533 4498 4446 4436 4457 4441 4398 4342 4333 4310 ...
result:
wrong answer 1st numbers differ - expected: '5109', found: '5047'