#include "candies.h"
#include <bits/stdc++.h>
using namespace std;
int tree[1<<19], lazy[1<<19], ans[200009];
void update(int v, int l, int r, int s, int e, int val){
if(lazy[v]){
tree[v] += lazy[v];
if(l != r){
lazy[2*v] += lazy[v];
lazy[2*v+1] += lazy[v];
}
lazy[v] = 0;
}
if(e<l || r<s)
return;
if(s<=l && r<=e){
tree[v] += val;
if(l != r){
lazy[2*v] += val;
lazy[2*v+1] += val;
}
}
else{
int mid = (l+r)/2;
update(2*v, l, mid,s, e, val);
update(2*v+1, mid+1, r, s, e, val);
tree[v] = tree[2*v] + tree[2*v+1];
}
}
void solve(int v, int l, int r){
if(lazy[v]){
tree[v] += lazy[v];
if(l != r){
lazy[2*v] += lazy[v];
lazy[2*v+1] += lazy[v];
}
lazy[v] = 0;
}
if(l==r){
ans[l] = tree[v];
return;
}
int mid = (l+r)/2;
solve(2*v, l, mid);
solve(2*v+1, mid+1, r);
}
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
int n = c.size(), q = l.size(), i, j;
for(i=0; i<q; i++){
update(1, 0, n-1, l[i], r[i], v[i]);
}
solve(1, 0, n-1);
vector<int> ret;
for(i=0; i<n; i++)
ret.push_back(min(ans[i], c[i]));
return ret;
}
Compilation message
candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:50:40: warning: unused variable 'j' [-Wunused-variable]
50 | int n = c.size(), q = l.size(), i, j;
| ^
# |
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 |
160 ms |
16560 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 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
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 |
- |