QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#673794 | #5278. Mex and Cards | IllusionaryDominance# | WA | 1ms | 5688kb | C++20 | 2.3kb | 2024-10-25 10:17:21 | 2024-10-25 10:17:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MAX_N = 200000 + 5;
int N, Q, cnt[MAX_N];
struct SegmentNode{
int minv;
ll sum;
}node[1 << 19];
// find the first element < x in [l, r]
int segment_find(int i, int l, int r, int x) {
if (node[i].minv >= x) return r + 1;
while (l < r) {
int mid = l + r >> 1;
if (node[i << 1].minv < x) {
r = mid;
i <<= 1;
}else {
l = mid + 1;
i = i << 1 | 1;
}
}
assert(node[i].minv < x);
return l;
}
ll segment_query(int i, int l, int r, int ql, int qr) {
if (l < ql || r > qr) {
ll res = 0;
int mid = l + r >> 1;
if (ql <= mid) res = segment_query(i << 1, l, mid, ql, qr);
if (mid < qr) res += segment_query(i << 1 | 1, mid + 1, r, ql, qr);
return res;
}else {
return node[i].sum;
}
}
void maintain(int i, int l, int mid, int r) {
node[i].minv = min(node[i << 1].minv, node[i << 1 | 1].minv);
int pos = segment_find(i << 1 | 1, mid + 1, r, node[i << 1].minv);
node[i].sum = node[i << 1].sum + (pos - mid - 1ll) * node[i << 1].minv + (pos <= r ? segment_query(i << 1 | 1, mid + 1, r, pos, r) : 0);
}
void segment_build(int i, int l, int r) {
if (l == r) {
node[i].minv = cnt[l];
node[i].sum = cnt[l];
return ;
}
int mid = l + r >> 1;
segment_build(i << 1, l, mid);
segment_build(i << 1 | 1, mid + 1, r);
maintain(i, l, mid, r);
}
void segment_modify(int i, int l, int r, int x, int v) {
if (l == r) {
node[i].minv += v;
node[i].sum += v;
return ;
}
int mid = l + r >> 1;
mid < x ? segment_modify(i << 1 | 1, mid + 1, r, x, v) : segment_modify(i << 1, l, mid, x, v);
maintain(i, l, mid, r);
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> N;
for (int i = 1; i <= N; i ++) {
cin >> cnt[i];
}
segment_build(1, 1, N);
cout << node[1].sum << '\n';
cin >> Q;
while (Q --) {
int ty, v;
cin >> ty >> v;
if (ty == 2) ty = -1;
segment_modify(1, 1, N, v + 1, ty);
cout << node[1].sum << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 5676kb
input:
5 2 1 3 0 2 6 1 0 1 1 2 4 1 3 2 1 2 1
output:
4 5 7 7 9 7 3
result:
ok 7 numbers
Test #2:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
1 0 0
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
10 3 8 1 4 10 3 10 9 7 10 20 2 5 1 4 1 2 1 4 1 3 1 3 1 0 2 8 1 5 1 4 1 0 1 3 1 8 1 6 1 4 1 1 1 5 1 9 1 6 2 7
output:
14 14 14 22 22 22 22 24 24 24 24 26 26 26 26 26 26 26 26 26 26
result:
ok 21 numbers
Test #4:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
10 9 8 7 5 5 4 3 2 1 1 20 2 4 1 8 2 6 1 2 1 2 2 5 2 2 1 0 1 6 1 6 2 9 1 2 2 7 2 8 2 3 1 9 1 7 1 4 2 6 1 7
output:
45 44 45 44 45 45 44 44 45 46 46 45 45 43 43 42 43 44 44 44 45
result:
ok 21 numbers
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 5688kb
input:
100 969 519 608 546 957 82 670 100 92 581 974 529 970 54 639 216 238 620 966 162 430 10 446 884 895 292 450 180 619 389 943 855 204 605 514 997 325 98 643 915 744 249 333 431 160 434 714 976 168 573 682 69 873 285 668 561 159 858 864 683 266 564 350 214 461 421 213 568 279 624 749 433 735 437 978 95...
output:
6819 6819 6819 6819 6819 6819 6819 6819 6819 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6823 6827 6827 6827 6827 6827 6827 6827 6827 6827 6827 6827 6827 6827 6827 6827 6826 6826 6826 6826 6826 6826 6826 6826 6826 ...
result:
wrong answer 1st numbers differ - expected: '4923', found: '6819'