#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(s[p], c[p]);
s[p] = max(s[p], 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] = (signed)min(operation(1, 0, treeSz - 1, i, i, 0), (int)c[i]);
}
return s;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
171 ms |
15700 KB |
Output is correct |
2 |
Correct |
171 ms |
15700 KB |
Output is correct |
3 |
Correct |
179 ms |
15700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
74 ms |
5116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
45 ms |
5108 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
2 ms |
504 KB |
Output is correct |
6 |
Correct |
171 ms |
15700 KB |
Output is correct |
7 |
Correct |
171 ms |
15700 KB |
Output is correct |
8 |
Correct |
179 ms |
15700 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Incorrect |
74 ms |
5116 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |