#include "candies.h"
#include <bits/stdc++.h>
#define fs first
#define sc second
#define p_q priority_queue
using namespace std;
vector<int> c,b;
vector<int> ans;
struct ST{
struct no{
int mn=0,mx=0,tag1=0,tag2=0,tag3=0;
};
vector<no> st;
void init(int x){
st.resize(4*x);
}
void pull(int v){
st[v].mn=min(st[2*v+1].mn,st[2*v+2].mn);
st[v].mx=max(st[2*v+1].mx,st[2*v+2].mx);
}
void upd1(int v,int x){
st[v].mn+=x;
st[v].mx+=x;
st[v].tag1+=x;
}
void upd2(int v){
st[v].mn=st[v].mx=0;
st[v].tag3=0;
st[v].tag2=1;
st[v].tag1=0;
}
void upd3(int v,int L,int R){
st[v].mn=c[L];
st[v].mx=c[R];
st[v].tag3=1;
st[v].tag2=0;
st[v].tag1=0;
}
void pudo(int v,int L,int R){
int m=(L+R)/2;
if(st[v].tag3){
upd3(2*v+1,L,m);
upd3(2*v+2,m+1,R);
st[v].tag3=0;
}
if(st[v].tag2){
upd2(2*v+1);
upd2(2*v+2);
st[v].tag2=0;
}
upd1(2*v+1,st[v].tag1);
upd1(2*v+2,st[v].tag1);
st[v].tag1=0;
}
void dec(int v,int L,int R,int x){
if(L==R){
upd2(v);
return;
}
pudo(v,L,R);
int m=(L+R)/2;
if(st[2*v+2].mn+x<=0){
upd2(2*v+1);
dec(2*v+2,m+1,R,x);
}
else{
upd1(2*v+2,x);
dec(2*v+1,L,m,x);
}
pull(v);
}
void add(int v,int L,int R,int x){
cout << v << " " << L << " " << R << " " << x << endl;
if(L==R){
upd3(v,L,R);
return;
}
pudo(v,L,R);
int m=(L+R)/2;
if(st[2*v+2].mn+x>=c[m+1]){
upd3(2*v+1,L,m);
add(2*v+2,m+1,R,x);
}
else{
upd1(2*v+2,x);
add(2*v+1,L,m,x);
}
pull(v);
}
void trav(int v,int L,int R){
if(L==R){
ans[b[L]]=st[v].mn;
return;
}
pudo(v,L,R);
int m=(L+R)/2;
trav(2*v+1,L,m);
trav(2*v+2,m+1,R);
}
}st;
vector<int> distribute_candies(vector<int> w, vector<int> l,
vector<int> r, vector<int> v) {
int n=w.size();
b.resize(n);
c.resize(n);
ans.resize(n);
vector<pair<int,int> > z;
for(int i=0;i<n;i++){
z.push_back({w[i],i});
}
sort(z.begin(),z.end());
for(int i=0;i<n;i++){
c[i]=z[i].fs;
b[i]=z[i].sc;
}
int q=l.size();
st.init(n);
for(int i=0;i<q;i++){
if(v[i]<0){
st.dec(0,0,n-1,v[i]);
}
else{
st.add(0,0,n-1,v[i]);
}
}
st.trav(0,0,n-1);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4780 ms |
114136 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |