#include "candies.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
const int N = 2e5;
int n, seg[4 * N], lazy[4 * N], MX;
#define mid (L + R) / 2
void pull (int idx, int v) {
if (v > 0) {
seg[idx] = min(MX, seg[idx] + v);
lazy[idx] = min(MX, lazy[idx] + v);
}
else {
seg[idx] = max(0, seg[idx] + v);
lazy[idx] = max(0, lazy[idx] + v);
}
}
void push_down (int idx) {
pull(2 * idx, lazy[idx]);
pull(2 * idx + 1, lazy[idx]);
lazy[idx] = 0;
}
void update (int st, int en, int v, int idx = 1, int L = 0, int R = n - 1) {
if (L > en || R < st) {
return;
}
if (L >= st && R <= en) {
return pull(idx, v);
}
push_down(idx);
update(st, en, v, 2 * idx, L, mid);
update(st, en, v, 2 * idx + 1, mid + 1, R);
}
int query (int st, int idx = 1, int L = 0, int R = n - 1) {
if (L == R) {
return seg[idx];
}
push_down(idx);
if (st <= mid) return query(st, 2 * idx, L, mid);
return query(st, 2 * idx + 1, mid + 1, R);
}
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
MX = c[0];
n = c.size();
int q = l.size();
vector<int> a(n);
vector<long long> b(n + 1);
for (int qs = 0; qs < q; ++qs) {
update(l[qs], r[qs], v[qs]);
}
for (int i = 0; i < n; ++i) {
a[i] = query(i);
}
return a;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
236 ms |
13048 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |