# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
751279 |
2023-05-31T10:44:44 Z |
amin |
Growing Trees (BOI11_grow) |
C++14 |
|
182 ms |
5060 KB |
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int seg[1000000];
int laz[1000000];
int a[1000003];
int z;
int b[1000003];
int ans=0;
int n;
void merg(int v,int v1,int v2)
{
seg[v]=max(seg[v1],seg[v2]);
}
void build(int v,int tl,int tr)
{
if(tl==tr)
{
seg[v]=a[tl];
return ;
}
int tm=(tl+tr)/2;
build(v*2,tl,tm);
build(v*2+1,tm+1,tr);
merg(v,v*2,v*2+1);
}
void push(int v)
{
laz[v*2]+=laz[v];
seg[v*2]+=laz[v];
seg[v*2+1]+=laz[v];
laz[v*2+1]+=laz[v];
laz[v]=0;
}
void update(int v,int tl,int tr,int l,int r)
{
if(l>r)
return ;
if(tl==l&&tr==r)
{
seg[v]++;
laz[v]++;
return ;
}
push(v);
int tm=(tl+tr)>>1;
update(v*2,tl,tm,l,min(r,tm));
update(v*2+1,tm+1,tr,max(tm+1,l),r);
merg(v,v*2,v*2+1);
}
int get(int v,int tl,int tr,int val)
{
//cout<<tl<<' '<<tr<<endl;
/* if(val<tl||val>tr)
return 1000000;*/
// cout<<tl<<' '<<tr<<endl;
if(tl==tr)
{
//cout<<seg[v]<<endl;
return tl;
}
push(v);
int tm=(tl+tr)/2;
if(seg[v*2]>=val)
{
return get(v*2,tl,tm,val);
}else
return get(v*2+1,tm+1,tr,val);
}
int get1(int v,int tl,int tr,int pos)
{
// cout<<tl<<' '<<tr<<' '<<pos<<endl;
if(pos<tl||pos>tr)
return n;
if(tl==tr)
return seg[v];
int tm=(tl+tr)>>1;
push(v);
return min(get1(v*2,tl,tm,pos),get1(v*2+1,tm+1,tr,pos));
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("balancing.in","r",stdin);
// freopen("balancing.out","w",stdout);
cin>>n;
int q;
cin>>q;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
a[n]=1000000000;
build(1,0,n);
while(q--)
{
char c;
cin>>c;
int co,mi;
cin>>mi>>co;
swap(mi,co);
if(c=='F')
{
// co--;
int pos=get(1,0,n,mi);
int en=pos+co-1;
en=min(en,n-1);
if(en==n-1)
{
update(1,0,n,pos,n-1);
continue;
}
int val=get1(1,0,n,en);
int st=get(1,0,n,val);
int e=get(1,0,n,val+1);
update(1,0,n,pos,st-1);
// cout<<pos<<' '<<st-1<<' '<<e-en+st-1<<' '<<e-1<<endl;
update(1,0,n,e-(en-st+1),e-1);
/*for(int y=0;y<n;y++)
{
cout<<get1(1,0,n,y)<<' ';
}
cout<<endl;*/
}else
{
swap(mi,co);
// cout<<get(1,0,n,co+1)<<get(1,0,n,mi);
// cout<<mi<<' '<<co+1<<endl;
cout<<get(1,0,n,co+1)-get(1,0,n,mi)<<endl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
3996 KB |
Output is correct |
2 |
Incorrect |
139 ms |
4472 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
340 KB |
Output is correct |
2 |
Correct |
5 ms |
348 KB |
Output is correct |
3 |
Correct |
6 ms |
340 KB |
Output is correct |
4 |
Correct |
4 ms |
340 KB |
Output is correct |
5 |
Incorrect |
115 ms |
1688 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
1668 KB |
Output is correct |
2 |
Incorrect |
138 ms |
1892 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
169 ms |
2080 KB |
Output is correct |
2 |
Correct |
155 ms |
1752 KB |
Output is correct |
3 |
Correct |
9 ms |
596 KB |
Output is correct |
4 |
Incorrect |
143 ms |
1792 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
99 ms |
2764 KB |
Output is correct |
2 |
Correct |
141 ms |
4204 KB |
Output is correct |
3 |
Correct |
37 ms |
1236 KB |
Output is correct |
4 |
Correct |
44 ms |
4044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
112 ms |
3756 KB |
Output is correct |
2 |
Correct |
140 ms |
4284 KB |
Output is correct |
3 |
Correct |
74 ms |
4244 KB |
Output is correct |
4 |
Correct |
34 ms |
1308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
105 ms |
3888 KB |
Output is correct |
2 |
Correct |
111 ms |
4108 KB |
Output is correct |
3 |
Correct |
68 ms |
4352 KB |
Output is correct |
4 |
Correct |
32 ms |
1276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
141 ms |
4464 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
138 ms |
4172 KB |
Output is correct |
2 |
Incorrect |
168 ms |
4428 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
182 ms |
5060 KB |
Output is correct |