#include <bits/stdc++.h>
using namespace std;
#include "candies.h"
#define fi first
#define se second
const int nax=2e5+5;
pair<int,int> segtree[nax*4];
long long lazy[nax*4];
int mx;
void upd(int pos,int value){
segtree[pos].fi+=value;
segtree[pos].se+=value;
segtree[pos].fi=min(segtree[pos].fi,mx);
segtree[pos].se=min(segtree[pos].se,mx);
segtree[pos].fi=max(segtree[pos].fi,0);
segtree[pos].se=max(segtree[pos].se,0);
lazy[pos]+=value;
lazy[pos]=min(lazy[pos],1ll*mx);
lazy[pos]=max(lazy[pos],1ll*0);
return;
}
void propagate(int pos){
if(lazy[pos]!=0){
upd(pos*2+1,lazy[pos]);
upd(pos*2+2,lazy[pos]);
}lazy[pos]=0;
}
void update(int pos,int l,int r,int left,int right,int value){
if(l>r||l>right||r<left) return;
if(l>=left&&r<=right){
upd(pos,value);
return;
}
int mid=(r+l)/2;
propagate(pos);
update(pos*2+1,l,mid,left,right,value);
update(pos*2+2,mid+1,r,left,right,value);
segtree[pos].fi=max(segtree[pos*2+1].fi,segtree[pos*2+2].se);
segtree[pos].se=min(segtree[pos*2+1].se,segtree[pos*2+2].se);
}
int query(int pos,int l,int r,int idx){
if(l==r&&segtree[pos].fi==segtree[pos].se) return segtree[pos].fi;
int mid=(r+l)/2;
propagate(pos);
if(idx<=mid) return query(pos*2+1,l,mid,idx);
else return query(pos*2+2,mid+1,r,idx);
}
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();
mx=c[0];
vector<int> ans(n);
for (int i = 0; i < (int)l.size(); ++i)
{
update(0,0,n-1,l[i],r[i],v[i]);
}
for (int i = 0; i < n; ++i)
{
ans[i]=query(0,0,n-1,i);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
171 ms |
17556 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 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 |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |