#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
class SGT {
public:
vector<ll> seg, arr, lazy, cap;
SGT(ll n, vector<ll> v, vector<ll> c) {
seg.resize(4 * n + 3);
lazy.resize(4 * n + 3);
arr = v;
cap = c;
}
void build(ll l, ll r, ll ind) {
if (l == r) {
seg[ind] = arr[l];
return;
}
ll mid = (l + r) / 2;
build(l, mid, 2 * ind + 1);
build(mid + 1, r, 2 * ind + 2);
seg[ind] = seg[2 * ind + 1] + seg[2 * ind + 2];
}
void propagate(ll l, ll r, ll ind) {
if (lazy[ind] != 0) {
for (ll i = l; i <= r; ++i) {
seg[ind] = min(cap[i], seg[ind] + lazy[ind]);
}
if (l != r) {
lazy[2 * ind + 1] += lazy[ind];
lazy[2 * ind + 2] += lazy[ind];
}
lazy[ind] = 0;
}
}
ll query(ll l, ll r, ll ind, ll pos) {
propagate(l, r, ind);
if (l == r) {
return seg[ind];
}
ll mid = (l + r) / 2;
if (mid >= pos) return query(l, mid, 2 * ind + 1, pos);
else return query(mid + 1, r, 2 * ind + 2, pos);
}
void update(ll l, ll r, ll ind, ll left, ll right, ll val) {
propagate(l, r, ind);
if (r < left || l > right) return;
if (l >= left && r <= right) {
for (ll i = l; i <= r; ++i) {
seg[ind] = min(cap[i], seg[ind] + val);
}
if (l != r) {
lazy[2 * ind + 1] += val;
lazy[2 * ind + 2] += val;
}
return;
}
ll mid = (l + r) / 2;
update(l, mid, 2 * ind + 1, left, right, val);
update(mid + 1, r, 2 * ind + 2, left, right, val);
seg[ind] = seg[2 * ind + 1] + seg[2 * ind + 2];
}
};
vector<int> distribute_candies(vector<int> c, vector<int> l,
vector<int> r, vector<int> v) {
int n = c.size();
int q = l.size();
vector<ll> vec(n + 1, 0);
SGT sg(n, vec, vector<ll>(c.begin(), c.end()));
sg.build(0, n - 1, 0);
for (ll i = 0; i < q; i++) {
sg.update(0, n - 1, 0, l[i], r[i], v[i]);
}
vector<int> s(n);
for (ll i = 0; i < n; i++) {
s[i] = sg.query(0, n - 1, 0, i);
}
return s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5085 ms |
29784 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |