#include "candies.h"
#define ll long long
#include <bits/stdc++.h>
using namespace std;
const int mxN=200100;
int N, Q;
ll seg[4*mxN];
vector <int> ans;
void upd(int idx, int s1, int e1, int s2, int e2, ll x)
{
if(s2<=s1 && e1<=e2)
{
seg[idx]+=x;
return;
}
if(s2>e1 || s1>e2) return;
int mid=(s1+e1)/2;
upd(2*idx, s1, mid, s2, e2, x);
upd(2*idx+1, mid+1, e1, s2, e2, x);
}
ll solv(int idx, int s, int e, int pos)
{
if(s==e) return seg[idx];
int mid=(s+e)/2;
if(pos<=mid) return seg[idx]+solv(2*idx, s, mid, pos);
else return seg[idx]+solv(2*idx+1, mid+1, e, pos);
}
std::vector<int> distribute_candies(vector <int> c, vector <int> l,
vector <int> r, vector <int> v) {
N=c.size();
Q=v.size();
ans.resize(N);
for(int i=0;i<Q;i++)
{
upd(1, 0, N-1, l[i], r[i], v[i]);
}
for(int i=0;i<N;i++) ans[i]=min(solv(1, 0, N-1, i), (ll)c[i]);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
226 ms |
12260 KB |
Output is correct |
2 |
Correct |
208 ms |
13256 KB |
Output is correct |
3 |
Correct |
245 ms |
13372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |