#include <bits/stdc++.h>
#include "candies.h"
using namespace std;
typedef long long ll;
const int maxn = 2e5+10;
struct FenwickTree
{
ll bit[maxn];
void upd(int x, ll v)
{
for (; x < maxn; x += (x&-x))
bit[x] += v;
}
ll soma(int x)
{
ll ans = 0;
for (; x > 0; x -= (x&-x))
ans += bit[x];
return ans;
}
ll get(int l, int r)
{
return soma(r)-soma(l-1);
}
} BIT;
ll value(ll v, ll add, int C)
{
if (add + v > 1ll*C) return C;
if (add + v < 0) return 0;
return add+v;
}
int a[maxn];
vector<int> distribute_candies(vector<int> c, vector<int> L, vector<int> R, vector<int> V)
{
int n = c.size(), q = L.size();
if (max(n, q) <= 2000)
{
for (int i = 0; i < q; i++)
{
for (int j = L[i]; j <= R[i]; j++)
a[j] = value(a[j], V[i], c[j]);
}
vector<int> ans;
for (int i = 0; i < n; i++)
ans.push_back(a[i]);
return ans;
}
for (int i = 0; i < q; i++)
{
BIT.upd(L[i]+1, 1ll*V[i]);
BIT.upd(R[i]+2, -1ll*V[i]);
}
vector<int> ans;
for (int i = 1; i <= n; i++)
{
if (BIT.soma(i) >= c[i-1]) ans.push_back(c[i-1]);
else ans.push_back(BIT.soma(i));
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
6 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
137 ms |
9252 KB |
Output is correct |
2 |
Correct |
130 ms |
9188 KB |
Output is correct |
3 |
Correct |
133 ms |
9264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
75 ms |
4956 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
69 ms |
4960 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
6 ms |
332 KB |
Output is correct |
6 |
Correct |
137 ms |
9252 KB |
Output is correct |
7 |
Correct |
130 ms |
9188 KB |
Output is correct |
8 |
Correct |
133 ms |
9264 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Incorrect |
75 ms |
4956 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |