#include <bits/stdc++.h>
#define ST first
#define ND second
#define PB push_back
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
const int nax = 200 * 1000 + 10;
int n, q;
ll pref[nax], mi[nax], mx[nax];
vi distribute_candies(vi c, vi la, vi ra, vi v) {
n = (int)c.size();
q = (int)la.size();
pref[0] = 0;
for(int i = 1; i <= q; ++i) {
pref[i] = pref[i - 1] + v[i - 1];
}
mi[q] = mx[q] = pref[q];
for(int i = q - 1; i >= 0; --i) {
mi[i] = min(mi[i + 1], pref[i]);
mx[i] = max(mx[i + 1], pref[i]);
}
vi ans(n);
for(int i = 0; i < n; ++i) {
int l = 0, r = q, mid;
while(l <= r) {
mid = (l + r) / 2;
if(mx[mid] - mi[mid] <= c[i]) {
r = mid - 1;
} else {
l = mid + 1;
}
}
if(r == -1) {
ans[i] = pref[q] - mi[0];
} else {
int pre = r + 1;
if(mi[r] < mi[pre]) {
// mx[pre] -> c[i];
ans[i] = c[i] - (mx[pre] - pref[q]);
} else {
// mi[pre] -> 0
ans[i] = pref[q] - mi[pre];
}
}
}
return ans;
}
//int main() {
//ios_base::sync_with_stdio(0);
//cin.tie(0);
//int N, Q;
//cin >> N >> Q;
//vi c(N), l(Q), r(Q), v(Q);
//for(int i = 0; i < N; ++i) {
//cin >> c[i];
//}
//for(int i = 0; i < Q; ++i) {
//cin >> l[i] >> r[i] >> v[i];
//}
//auto ans = distribute_candies(c,l,r,v);
//for(int x : ans) cout << x << " ";
//}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
139 ms |
11956 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
61 ms |
9692 KB |
Output is correct |
4 |
Correct |
60 ms |
2848 KB |
Output is correct |
5 |
Correct |
129 ms |
11972 KB |
Output is correct |
6 |
Correct |
134 ms |
16196 KB |
Output is correct |
7 |
Correct |
135 ms |
16812 KB |
Output is correct |
8 |
Correct |
123 ms |
15328 KB |
Output is correct |
9 |
Correct |
128 ms |
16984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |