QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#521232 | #1140. Distributing Candies | arbuzick | 27 | 593ms | 34940kb | C++20 | 6.8kb | 2024-08-16 00:54:35 | 2024-08-16 00:54:35 |
Judging History
answer
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
constexpr long long inf = (long long)1e18 + 7;
struct Node {
long long min, second_min, max, second_max;
bool push_min, push_max;
long long push_add;
Node() {
min = max = 0;
second_min = inf;
second_max = -inf;
push_min = push_max = false;
push_add = 0;
}
};
constexpr int R = 1 << 18;
Node tree[R * 2];
void push(int node) {
if (node >= R) {
tree[node].push_min = tree[node].push_max = false;
tree[node].push_add = 0;
return;
}
if (tree[node].push_add != 0) {
tree[node * 2].min += tree[node].push_add;
if (tree[node * 2].second_min != inf) {
tree[node * 2].second_min += tree[node].push_add;
}
tree[node * 2].max += tree[node].push_add;
if (tree[node * 2].second_max != -inf) {
tree[node * 2].second_max += tree[node].push_add;
}
tree[node * 2].push_add += tree[node].push_add;
tree[node * 2 + 1].min += tree[node].push_add;
if (tree[node * 2 + 1].second_min != inf) {
tree[node * 2 + 1].second_min += tree[node].push_add;
}
tree[node * 2 + 1].max += tree[node].push_add;
if (tree[node * 2 + 1].second_max != -inf) {
tree[node * 2 + 1].second_max += tree[node].push_add;
}
tree[node * 2 + 1].push_add += tree[node].push_add;
}
tree[node].push_add = 0;
if (tree[node].push_min) {
if (tree[node].max < tree[node * 2].max) {
tree[node * 2].max = tree[node].max;
tree[node * 2].min = min(tree[node * 2].min, tree[node].max);
if (tree[node * 2].second_min != inf) {
tree[node * 2].second_min = min(tree[node * 2].second_min, tree[node].max);
}
tree[node * 2].push_min = true;
}
if (tree[node].max < tree[node * 2 + 1].max) {
tree[node * 2 + 1].max = tree[node].max;
tree[node * 2 + 1].min = min(tree[node * 2 + 1].min, tree[node].max);
if (tree[node * 2 + 1].second_min != inf) {
tree[node * 2 + 1].second_min = min(tree[node * 2 + 1].second_min, tree[node].max);
}
tree[node * 2 + 1].push_min = true;
}
}
tree[node].push_min = false;
if (tree[node].push_max) {
if (tree[node].min > tree[node * 2].min) {
tree[node * 2].min = tree[node].min;
tree[node * 2].max = max(tree[node * 2].max, tree[node].min);
if (tree[node * 2].second_max != -inf) {
tree[node * 2].second_max = max(tree[node * 2].second_max, tree[node].min);
}
tree[node * 2].push_max = true;
}
if (tree[node].min > tree[node * 2 + 1].min) {
tree[node * 2 + 1].min = tree[node].min;
tree[node * 2 + 1].max = max(tree[node * 2 + 1].max, tree[node].min);
if (tree[node * 2 + 1].second_max != -inf) {
tree[node * 2 + 1].second_max = max(tree[node * 2 + 1].second_max, tree[node].min);
}
tree[node * 2 + 1].push_max = true;
}
}
tree[node].push_max = false;
}
void relax(int node) {
tree[node].min = min(tree[node * 2].min, tree[node * 2 + 1].min);
if (tree[node].min != tree[node * 2].min) {
tree[node].second_min = min(tree[node * 2].min, tree[node * 2 + 1].second_min);
} else if (tree[node].min != tree[node * 2 + 1].min) {
tree[node].second_min = min(tree[node * 2].second_min, tree[node * 2 + 1].min);
} else {
tree[node].second_min = min(tree[node * 2].second_min, tree[node * 2 + 1].second_min);
}
tree[node].max = max(tree[node * 2].max, tree[node * 2 + 1].max);
if (tree[node].max != tree[node * 2].max) {
tree[node].second_max = max(tree[node * 2].max, tree[node * 2 + 1].second_max);
} else if (tree[node].max != tree[node * 2 + 1].max) {
tree[node].second_max = max(tree[node * 2].second_max, tree[node * 2 + 1].max);
} else {
tree[node].second_max = max(tree[node * 2].second_max, tree[node * 2 + 1].second_max);
}
}
void add_val(int ql, int qr, int val, int node = 1, int nl = 0, int nr = R) {
if (ql <= nl && nr <= qr) {
tree[node].min += val;
if (tree[node].second_min != inf) {
tree[node].second_min += val;
}
tree[node].max += val;
if (tree[node].second_max != -inf) {
tree[node].second_max += val;
}
tree[node].push_add += val;
return;
}
if (qr <= nl || nr <= ql) {
return;
}
push(node);
int nm = (nl + nr) / 2;
add_val(ql, qr, val, node * 2, nl, nm);
add_val(ql, qr, val, node * 2 + 1, nm, nr);
relax(node);
}
void fix_mn(long long mn, int node = 1, int nl = 0, int nr = R) {
push(node);
if (mn <= tree[node].min) {
return;
}
if (mn < tree[node].second_min) {
tree[node].min = mn;
tree[node].max = max(tree[node].max, mn);
if (tree[node].second_max != -inf) {
tree[node].second_max = max(tree[node].second_max, mn);
}
tree[node].push_max = true;
return;
}
int nm = (nl + nr) / 2;
fix_mn(mn, node * 2, nl, nm);
fix_mn(mn, node * 2 + 1, nm, nr);
relax(node);
}
void fix_mx(long long mx, int node = 1, int nl = 0, int nr = R) {
push(node);
if (tree[node].max <= mx) {
return;
}
if (mx > tree[node].second_max) {
tree[node].max = mx;
tree[node].min = min(tree[node].min, mx);
if (tree[node].second_min != inf) {
tree[node].second_min = min(tree[node].second_min, mx);
}
tree[node].push_min = true;
return;
}
push(node);
int nm = (nl + nr) / 2;
fix_mx(mx, node * 2, nl, nm);
fix_mx(mx, node * 2 + 1, nm, nr);
relax(node);
}
long long get(int pos, int node = 1, int nl = 0, int nr = R) {
if (nl == pos && nr == pos + 1) {
return tree[node].min;
}
if (nr <= pos || pos < nl) {
return 0;
}
push(node);
int nm = (nl + nr) / 2;
long long ans = get(pos, node * 2, nl, nm) + get(pos, node * 2 + 1, nm, nr);
relax(node);
return ans;
}
vector<int> distribute_candies(vector<int> c, vector<int> l,
vector<int> r, vector<int> v) {
int n = c.size();
int q = v.size();
vector<int> ans(n);
for (int i = 0; i < q; ++i) {
r[i]++;
add_val(l[i], r[i], v[i]);
fix_mn(0);
fix_mx(c[0]);
}
for (int i = 0; i < n; ++i) {
ans[i] = get(i);
}
return ans;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 0ms
memory: 28456kb
input:
lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg 8 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 8 0 7 1 0 7 1 0 7 300000000 0 7 994967293 0 7 1 0 7 1000000000 0 7 1000000000 0 7 1000000000
output:
4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq OK 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000
result:
ok 3 lines
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 28460kb
input:
lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg 10 283 43634 101056 10340 6009 5133 30 2 3677888 210 10 1 8 26416 2 7 -51219 2 4 17793 3 7 75426 3 7 22307 1 1 60258 3 7 -29824 0 8 24839 2 8 -60304 0 1 -26411
output:
4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq OK 0 0 0 0 0 0 0 0 0 0
result:
wrong answer 3rd lines differ - expected: '0 17223 0 0 0 0 0 0 0 0', found: '0 0 0 0 0 0 0 0 0 0'
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 470ms
memory: 34916kb
input:
lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg 200000 11408901 370732653 37843 28 53693 15782410 103 297546 1112427 170319071 26 1 6172 11614171 431 884673599 1 3 50085 154 57 28200 145886 898969 74758 72 845768 6 69787 11 31012465 55362 253 2363145 47186217 1103 19622 594 7867 1 4299 28130 48 4689582 12 ...
output:
4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq OK 87153 87153 243257 250497 325876 406667 525479 655951 766665 971468 1073487 1084603 1144515 1257294 1514842 1536484 1739854 1833903 1950484 1950484 2050477 2096517 2213442 2241808 2453123 2551636 2688712 2735237 2969818 2969818 3043755 3043755 3113712 3297...
result:
wrong answer 3rd lines differ - expected: '87153 87153 37843 28 53693 406...46468 9 1756 429030 247071 1629', found: '87153 87153 243257 250497 3258...1546 474919 429030 247071 16020'
Subtask #3:
score: 27
Accepted
Test #9:
score: 27
Accepted
time: 6ms
memory: 28676kb
input:
lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000...
output:
4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq OK 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 3 lines
Test #10:
score: 27
Accepted
time: 141ms
memory: 32568kb
input:
lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg 2000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1...
output:
4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq OK 1049802 936230 884511 204101 406074 550834 961642 2076245 1975297 2101513 2254310 1990108 1398298 1917785 2864344 2475931 2270774 401698970 402327667 402506418 401068637 399388438 398687119 398672863 397137012 397262070 396255448 395961553 394643443 394646...
result:
ok 3 lines
Test #11:
score: 27
Accepted
time: 85ms
memory: 30152kb
input:
lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg 200000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000...
output:
4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq OK 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 3 lines
Test #12:
score: 27
Accepted
time: 332ms
memory: 34940kb
input:
lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg 200000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000...
output:
4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq OK 27608 64753 120270 150200 99177 99177 69754 163659 163659 234722 182586 182586 182586 115212 115212 36356 36356 6028 6028 972950338 973018128 973018128 973018128 973018128 973123904 973123904 973124098 973020904 973039972 973136885 973173147 973200808 9730...
result:
ok 3 lines
Test #13:
score: 27
Accepted
time: 416ms
memory: 34840kb
input:
lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg 200000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000...
output:
4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq OK 0 3907113 13718455 22058386 22058386 22058386 17250429 17250429 22661114 22661114 13718455 26434847 24657287 31478180 40855091 34489940 34489940 34489940 34489940 34489940 34489940 34489940 41385683 41385683 45763396 45763396 45763396 45763396 40987755 409...
result:
ok 3 lines
Test #14:
score: 27
Accepted
time: 593ms
memory: 34928kb
input:
lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg 200000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000...
output:
4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq OK 0 0 0 0 0 0 0 0 0 0 0 920673668 920673668 920673668 920673668 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 555951031 55595103...
result:
ok 3 lines
Test #15:
score: 27
Accepted
time: 480ms
memory: 34912kb
input:
lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg 200000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000...
output:
4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq OK 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 2 2 2 2 3 3 3 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 5 5 5 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 2 2 2 2 2 2 2 2 ...
result:
ok 3 lines
Subtask #4:
score: 0
Wrong Answer
Test #16:
score: 0
Wrong Answer
time: 0ms
memory: 28348kb
input:
lrts0z0ktpqc670i0etyqgyb45dt1dysq5ap2mzg 10 11 440 51 41 11 1 3 108 148 14 10 0 9 60 0 9 -9 0 9 -30 0 9 41 0 9 82 0 9 69 0 9 -79 0 9 -39 0 9 72 0 9 41
output:
4lpv73iykswp9e3nppi3jw2qggm5dfz29yy9nzpq OK 11 11 11 11 11 11 11 11 11 11
result:
wrong answer 3rd lines differ - expected: '11 208 51 41 11 1 3 108 143 14', found: '11 11 11 11 11 11 11 11 11 11'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%