#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vs vector<signed>
#define vi vector<int>
#define pii pair<int,int>
#define vii vector<pii>
#define pb push_back
#include "candies.h"
struct st {
int n;
vi v;
st(int x) {
n=x;
v.resize(4*n);
}
void _add(int i,int l,int r,int tg,int val) {
v[i]+=val;
if (r==l+1) return;
int mid = (l+r)/2;
if (tg<mid) _add(i*2,l,mid,tg,val);
}
void add(int p,int x) {
_add(1,0,n,p,x);
}
int _sum(int i,int cl,int cr,int tl,int tr) {
if (i==-1) return 0;
if (cr<=tl) return 0;
if (tr<=cl) return 0;
if ((tl<=cl)&&(cr<=tr)) {
return v[i];
}
int mid = (cl+cr)/2;
return _sum(i*2,cl,mid,tl,tr)+_sum(i*2+1,mid,cr,tl,tr);
}
int sum(int k) {
return _sum(1,0,n,0,k);
}
};
vs distribute_candies(vs c,vs l,vs r,vs v) {
int n = c.size();
st s(n+3);
for (int i=0;i<l.size();i++) {
s.add(l[i],v[i]);
s.add(r[i]+1,-v[i]);
}
vs ans;
for (int i=0;i<n;i++) {
ans.pb(min((int)c[i],s.sum(i+1)));
}
return ans;
}
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:44:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | for (int i=0;i<l.size();i++) {
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
119 ms |
14112 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |