#include "candies.h"
#include <vector>
#include <iostream>
std::vector<int> st(8e5+1,0);
void upd(int cur, int l, int r, int a, int b, int v)
{
if(b<l || a>r)
return;
if(l<=a&&r>=b)
{
st[cur]+=v;
return;
}
int mid=(a+b)/2;
st[2*cur]=st[2*cur+1]=st[cur];
st[cur]=0;
upd(2*cur,l,r,a,mid,v);
upd(2*cur+1,l,r,mid+1,b,v);
}
void prop(int cur, int a, int b, std::vector<int>& l)
{
if(a==b)
{
l[a]+=st[cur];
return;
}
st[2*cur]+=st[cur];
st[2*cur+1]+=st[cur];
st[cur]=0;
int mid=(a+b)/2;
prop(2*cur,a,mid,l);
prop(2*cur+1,mid+1,b,l);
}
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();
std::vector s(c);
for(int i=0;i<v.size();i++)
upd(1,l[i],r[i],0,n-1,v[i]);
prop(1,0,n-1,s);
return s;
}
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:43:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
43 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3412 KB |
Output is correct |
2 |
Incorrect |
1 ms |
3412 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
139 ms |
10492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
3412 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
3412 KB |
Output is correct |
2 |
Incorrect |
1 ms |
3412 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |