#include "candies.h"
#include <vector>
using namespace std;
long long lazy[524288];
void propagate(int i, int b, int e) {
if (!lazy[i]) return;
if (b != e) {
lazy[i * 2 + 1] += lazy[i];
lazy[i * 2 + 2] += lazy[i];
lazy[i] = 0;
}
}
void update(int i, int b, int e, int l, int r, int v) {
propagate(i, b, e);
if (r < l || e < l || r < b) return;
if (l <= b && e <= r) {
lazy[i] += v;
propagate(i, b, e);
return;
}
int m = (b + e) / 2;
update(i * 2 + 1, b, m, l, r, v);
update(i * 2 + 2, m + 1, e, l, r, v);
}
long long query(int i, int b, int e, int p) {
propagate(i, b, e);
if (p < b || e < p) return 0;
if (b == e) return lazy[i];
int m = (b + e) / 2;
return query(i * 2 + 1, b, m, p) + query(i * 2 + 2, m + 1, e, p);
}
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
int n = (int)c.size(), q = (int)v.size();
vector<int> s(n);
for (int t = 0; t < q; t++) update(0, 0, 262143, l[t], r[t], v[t]);
for (int i = 0; i < n; i++) s[i] = min(query(0, 0, 262143, i), (long long)c[i]);
return s;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
315 ms |
10496 KB |
Output is correct |
2 |
Correct |
297 ms |
10532 KB |
Output is correct |
3 |
Correct |
293 ms |
10544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
- |