#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef vector<int> vi;
typedef vector<signed> vi32;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef set<int> si;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<vii> vvii;
#define pb push_back
#define loop(x, i) for (int i = 0; i < x; i++)
#define ALL(x) begin(x), end(x)
#define sz(x) (int)x.size()
vi lazy;
vi tree;
void applyLazy(int i, int l, int r, int v)
{
tree[i] += v * (r - l + 1);
lazy[i] = v;
}
int operation(int i, int l, int r, int ql, int qr, int v)
{
if (qr < l || r < ql)
return 0;
int m = l + (r - l) / 2;
// propagate
{
if (l != r)
{
applyLazy(2 * i, l, m, lazy[i]);
applyLazy(2 * i + 1, m + 1, r, lazy[i]);
}
lazy[i] = 0;
}
if (ql <= l && r <= qr)
{
if (v != 0)
{
applyLazy(i, l, r, v);
}
return tree[i];
}
int res = operation(2 * i, l, m, ql, qr, v) +
operation(2 * i + 1, m + 1, r, ql, qr, v);
tree[i] = tree[2 * i] + tree[2 * i + 1];
return res;
}
vi32 distribute_candies(vi32 c, vi32 l, vi32 r, vi32 v)
{
int n = c.size();
int q = sz(l);
if (n <= 2000 && q <= 2000)
{
vi32 s(n);
loop(q, i)
{
for (int p = l[i]; p <= r[i]; p++)
{
s[p] += v[i];
s[p] = min(v[i], c[p]);
s[p] = max(v[i], 0);
}
}
return s;
}
int treeSz = 1;
while (treeSz < n)
treeSz *= 2;
tree = lazy = vi(treeSz * 2);
loop(q, i)
{
operation(1, 0, treeSz - 1, l[i], r[i], v[i]);
}
vi32 s(n);
loop(n, i)
{
s[i] = min(operation(1, 0, treeSz = 1, i, i, 0), (int)c[i]);
}
return s;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
142 ms |
15700 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |