QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#321966 | #5441. Quartz Collection | duckindog | WA | 0ms | 32496kb | C++14 | 2.1kb | 2024-02-05 23:52:45 | 2024-02-05 23:52:45 |
Judging History
answer
//from duckindog wth depression
#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 3e5 + 10;
int n, m;
int a[N], b[N];
struct IT {
//0->11; 1->01; 2->00; 3->10;
int f4[N << 2][4], f2[N << 2][2], sz[N];
void update(int s, int l, int r, int i, int x) {
if (i < l || i > r) return;
if (l == r) {
sz[s] += x;
int val = sz[s] / 4 * 2;
f4[s][0] = val + sz[s] % 4;
f4[s][1] = val + (sz[s] % 4 == 2);
f4[s][2] = val + (sz[s] % 4 == 3);
f4[s][3] = val + (sz[s] % 4 >= 1);
for (int j = 0; j < 4; ++j) f4[s][j] *= i;
for (int j = 0; j < 2; ++j) f2[s][j] = (sz[s] + j) / 2 * i;
return;
}
int mid = l + r >> 1;
update(s << 1, l, mid, i, x); update(s << 1 | 1, mid + 1, r, i, x);
sz[s] = sz[s << 1] + sz[s << 1 | 1];
for (int j = 0; j < 4; ++j) {
int t = (j + sz[s << 1]) % 4;
f4[s][t] = f4[s << 1][t] + f4[s << 1 | 1][j];
}
for (int j = 0; j < 2; ++j) {
int t = (j + sz[s << 1]) % 2;
f2[s][t] = f2[s << 1][t] + f2[s << 1 | 1][j];
}
}
} pos, neg;
int sum = 0;
int cal() {
if (pos.sz[1] == 1) return sum + neg.f4[1][3] + pos.f2[1][!(neg.sz[1] - 1) % 2];
if (neg.sz[1]) return sum + neg.f4[1][3] + pos.f2[1][neg.sz[1] % 2 == 0];
return sum + pos.f2[1][1];
}
int32_t main() {
cin.tie(0)->sync_with_stdio(0);
if (fopen("duck.inp", "r")) {
freopen("duck.inp", "r", stdin);
freopen("duck.out", "w", stdout);
}
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> a[i] >> b[i];
sum += b[i];
if (a[i] - b[i] <= 0) neg.update(1, -1e5, 0, a[i] - b[i], 1);
else pos.update(1, 1, 1e5, a[i] - b[i], 1);
}
cout << cal() << "\n";
for (int i = 1; i <= m; ++i) {
int t, x, y; cin >> t >> x >> y;
sum = sum - b[t] + y;
if (a[t] - b[t] <= 0) neg.update(1, -1e5, 0, a[t] - b[t], -1);
else pos.update(1, 1, 1e5, a[t] - b[t], -1);
a[t] = x; b[t] = y;
if (a[t] - b[t] <= 0) neg.update(1, -1e5, 0, a[t] - b[t], 1);
else pos.update(1, 1, 1e5, a[t] - b[t], 1);
cout << cal() << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 32496kb
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: 0ms
memory: 18076kb
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: 0ms
memory: 30412kb
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 5087 5082 5007 4975 4993 4950 4928 4922 4926 4956 4923 4893 4871 4875 4841 4839 4789 4795 4819 4732 4753 4704 4594 4580 4652 4661 4674 4679 4725 4754 4771 4728 4739 4698 4669 4666 4663 4724 4815 4802 4810 4792 4797 4696 4744 4684 4699 4681 4630 4649 4536 4523 4554 4605 4585 4532 4500 4469 4545 ...
result:
wrong answer 1st numbers differ - expected: '5109', found: '5133'