#include "candies.h"
#include <bits/stdc++.h>
#include <vector>
#define ll long long
using namespace std;
vector <ll> tree;
int sz=1, ans;
bool ok=0;
void init(ll n){
while (sz < n) sz*=2;
tree.assign(2*sz, 0);
return ;
}
void add(ll l, ll r, ll v, ll x, ll lx, ll rx){
// cout << l <<" " << r <<"\n";
if (lx >= r || rx <= l) return ;
if (l <= lx && rx <= r) {
tree[x]+=v;
return ;
}
ll m=(lx+rx)/2;
add(l, r, v, 2*x+1, lx, m);
add(l, r, v, 2*x+2, m, rx);
return ;
}
void help(ll i, ll x, ll lx, ll rx, ll res=0){
if (rx-lx == 1){
if (!ok) ans=res+tree[x];
ok=1;
return;
}
ll m=(lx+rx)/2;
ll x1=x;
if (i < m) help(i, 2*x+1, lx, m, res+tree[x1]);
else help(i, 2*x+2, m, rx, res+tree[x1]);
return ;
}
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();
init(n);
vector<int> s(n);
s=c;
for (int i=0;i<l.size();i++){
add(l[i], r[i]+1, v[i], 0, 0, sz);
}
for (int i=0;i<n;i++){
ok=0;
help(i, 0, 0, sz);
// cout << ans <<" ";
s[i]=min(c[i], ans);
}
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:46:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
46 | for (int i=0;i<l.size();i++){
| ~^~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
174 ms |
11452 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 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |