#include "candies.h"
#include<bits/stdc++.h>
using namespace std;
int CONS;
vector<int>ans;
struct segtree{
struct DATA{
int mx,mn,add;
DATA(){
mx=1e9;
mn=0;
add=0;
}
DATA(int a,int b,int c){
mx=a,mn=b,add=c;
}
void apply(DATA k){
mx+=k.add,mn+=k.add,add+=k.add;
mx=min(mx,k.mx),mn=min(mn,k.mx);
mx=max(mx,k.mn),mn=max(mn,k.mn);
add=min(max(add,-CONS),CONS);
}
} T[1<<19];
void pd(int i){
T[i*2].apply(T[i]);
T[i*2+1].apply(T[i]);
T[i]=DATA();
}
void upd(int i,int l,int r,int ll,int rr,int v){
if(ll<=l&&r<=rr)
return T[i].apply((DATA){CONS,0,v});
if(ll>r||l>rr) return;
pd(i);upd(i*2,l,l+r>>1,ll,rr,v);
upd(i*2+1,l+r+2>>1,r,ll,rr,v);
}
void traverse(int i,int l,int r){ if(l==r)
return ans.push_back(max(T[i].mn,min(T[i].mx,T[i].add)));
pd(i);traverse(i*2,l,l+r>>1);
traverse(i*2+1,l+r+2>>1,r);
}
} seg;
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
std::vector<int> r, std::vector<int> v) {
CONS=c[0];
int n = c.size(),q=l.size();
for(int i=0;i<q;i++)
seg.upd(1,0,n-1,l[i],r[i],v[i]);
seg.traverse(1,0,n-1);
return ans;
}
Compilation message
candies.cpp: In member function 'void segtree::upd(int, int, int, int, int, int)':
candies.cpp:34:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | pd(i);upd(i*2,l,l+r>>1,ll,rr,v);
| ~^~
candies.cpp:35:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
35 | upd(i*2+1,l+r+2>>1,r,ll,rr,v);
| ~~~^~
candies.cpp: In member function 'void segtree::traverse(int, int, int)':
candies.cpp:39:31: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
39 | pd(i);traverse(i*2,l,l+r>>1);
| ~^~
candies.cpp:40:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
40 | traverse(i*2+1,l+r+2>>1,r);
| ~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
137 ms |
14464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6488 KB |
Output is correct |
2 |
Correct |
69 ms |
11092 KB |
Output is correct |
3 |
Correct |
37 ms |
10932 KB |
Output is correct |
4 |
Correct |
137 ms |
14536 KB |
Output is correct |
5 |
Correct |
143 ms |
20836 KB |
Output is correct |
6 |
Correct |
151 ms |
21188 KB |
Output is correct |
7 |
Correct |
140 ms |
20420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
6492 KB |
Output is correct |
2 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |