#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll n,m,i,a[100005],x,y,s[400005];
char type;
void update(ll node,ll l,ll r,ll L,ll R,ll val){
if(l>R || r<L) return;
if(l>=L && r<=R){
s[node]+=val;
return;
}
ll mid=(r+l)/2;
update(node*2,l,mid,L,R,val);
update(node*2+1,mid+1,r,L,R,val);
}
ll get(ll node,ll l,ll r,ll loc){
if(l==r) return s[node];
ll mid=(r+l)/2,z;
if(loc<=mid) z=get(node*2,l,mid,loc);
else z=get(node*2+1,mid+1,r,loc);
return s[node]+z;
}
ll find(ll x,ll y){
ll l,r,mid;
if(get(1,1,n,n)<x || get(1,1,n,1)>y) return 0;
l=1;
r=n;
while(r-l>1){
mid=(r+l+1)/2;
if(get(1,1,n,mid)>=x) r=mid;
else l=mid;
}
if(get(1,1,n,l)>=x) x=l;
else x=r;
l=1;
r=n;
while(r-l>1){
mid=(r+l+1)/2;
if(get(1,1,n,mid)>y) r=mid;
else l=mid;
}
if(get(1,1,n,r)<=y) y=r;
else y=l;
return y-x+1;
}
void change(ll c,ll h){
if(get(1,1,n,n)<h) return;
ll l,r,mid,strt,val1,val2,x,y;
l=1;
r=n;
while(r-l>1){
mid=(r+l+1)/2;
if(get(1,1,n,mid)>=h) r=mid;
else l=mid;
}
if(get(1,1,n,l)>=h) strt=l;
else strt=r;
if(strt+c>=n){
update(1,1,n,strt,n,1);
return;
}
val1=get(1,1,n,strt);
val2=get(1,1,n,strt+c-1);
l=1;
r=n;
while(r-l>1){
mid=(r+l+1)/2;
if(get(1,1,n,mid)>=val2) r=mid;
else l=mid;
}
if(get(1,1,n,l)>=val2) x=l;
else x=r;
l=1;
r=n;
while(r-l>1){
mid=(r+l+1)/2;
if(get(1,1,n,mid)>val2) r=mid;
else l=mid;
}
if(get(1,1,n,r)<=val2) y=r;
else y=l;
if(val1!=val2){
update(1,1,n,strt,x-1,1);
c=c-(x-strt);
update(1,1,n,y-c+1,y,1);
}
else update(1,1,n,y-c+1,y,1);
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n >> m;
for(i=1;i<=n;i++) cin >> a[i];
sort(a+1,a+n+1);
for(i=1;i<=n;i++) update(1,1,n,i,i,a[i]);
while(m--){
cin >> type >> x >> y;
if(type=='C'){
cout << find(x,y) << "\n";
}
else change(x,y);
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
125 ms |
4432 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
348 KB |
Output is correct |
2 |
Correct |
3 ms |
348 KB |
Output is correct |
3 |
Correct |
5 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
103 ms |
1608 KB |
Output is correct |
6 |
Incorrect |
123 ms |
1916 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
92 ms |
1900 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
79 ms |
2116 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
139 ms |
4228 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
218 ms |
4172 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
140 ms |
4356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
288 ms |
5100 KB |
Output is correct |
2 |
Correct |
248 ms |
4976 KB |
Output is correct |
3 |
Correct |
49 ms |
4188 KB |
Output is correct |
4 |
Correct |
109 ms |
4560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
194 ms |
4616 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
243 ms |
5740 KB |
Output is correct |