#include <bits/stdc++.h>
using namespace std;
#include "candies.h"
#define fi first
#define se second
const int nax=2e5+5;
vector<int> tab;
int segtree[nax*4];
int lazy[nax*4];
int mx;
void upd(int pos,int l,int r,int value){
segtree[pos]+=value;
segtree[pos]=max(segtree[pos],0);
segtree[pos]=min(segtree[pos],tab[r]);
lazy[pos]+=value;
return;
}
void propagate(int pos,int l,int r){
if(lazy[pos]!=0){
int mid=(r+l)/2;
upd(pos*2+1,l,mid,lazy[pos]);
upd(pos*2+2,mid+1,r,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,l,r,value);
return;
}
int mid=(r+l)/2;
propagate(pos,l,r);
update(pos*2+1,l,mid,left,right,value);
update(pos*2+2,mid+1,r,left,right,value);
segtree[pos]=max(segtree[pos*2+1],segtree[pos*2+2]);
}
int query(int pos,int l,int r,int idx){
if(l==r) return segtree[pos];
int mid=(r+l)/2;
propagate(pos,l,r);
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();
tab=c;
sort(tab.begin(),tab.end());
mx=c[0];
vector<int> ans(n);
for (int i = 0; i < (int)l.size(); ++i)
{
int l=-1;
int r=n;
while(r-l>1){
int mid=(r+l)/2;
if(v[i]>0){
if(query(0,0,n-1,mid)+v[i]>=tab[i]) l=mid;
else r=mid;
}else{
if(query(0,0,n-1,mid)+v[i]<=0) l=mid;
else r=mid;
}
}
update(0,0,n-1,0,l,v[i]);
update(0,0,n-1,r,n-1,v[i]);
}
for (int i = 0; i < n; ++i)
{
ans[i]=query(0,0,n-1,i);
}
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
322 ms |
16788 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |