| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 709597 | ToroTN | Growing Trees (BOI11_grow) | C++14 | 118 ms | 3284 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
int n,t,a[100005],x,y,fen[100005],st,md,ed,l,r;
char op[5];
void update(int u,int val)
{
while(u<=n)
{
fen[u]+=val;
u+=(u&(-u));
}
}
int query(int u)
{
int cnt=0;
while(u>0)
{
cnt+=fen[u];
u-=(u&(-u));
}
return cnt;
}
int main()
{
scanf("%d%d",&n,&t);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
sort(a+1,a+n+1);
for(int i=1;i<=n;i++)update(i,a[i]-a[i-1]);
/*for(int i=1;i<=n;i++)
{
printf("%d ",a[i]);
}
printf("\n");*/
while(t--)
{
scanf("%s",op);
if(op[0]=='C')
{
scanf("%d%d",&x,&y);
}else
{
scanf("%d%d",&y,&x);
}
if(op[0]=='C')
{
st=1,ed=n;
while(ed>=st)
{
md=(st+ed)/2;
if(query(md)<x)
{
st=md+1;
}else
{
ed=md-1;
}
}
l=st;
if(l>n)
{
printf("0\n");
continue;
}
st=1,ed=n;
while(ed>=st)
{
md=(st+ed)/2;
if(query(md)>y)
{
ed=md-1;
}else
{
st=md+1;
}
}
r=ed;
printf("%d\n",r-l+1);
}else
{
st=1,ed=n;
while(ed>=st)
{
md=(st+ed)/2;
if(query(md)<x)
{
st=md+1;
}else
{
ed=md-1;
}
}
l=st;
//printf("%d ",l);
r=l+y-1;
//printf("%d\n",r);
if(r>=n)
{
update(l,1);
}else
{
int numr=query(r);
st=1,ed=n;
while(ed>=st)
{
md=(st+ed)/2;
if(query(md)>=numr)
{
ed=md-1;
}else
{
st=md+1;
}
}
int pos_l=ed;
/*printf("%d\n",r);
printf("%d %d %d\n",st,md,ed);
break;*/
if(l<=pos_l)
{
update(l,1);
update(pos_l+1,-1);
}
int remain=y-(pos_l-l+1);
int lst;
st=1,ed=n;
while(ed>=st)
{
md=(st+ed)/2;
if(query(md)>numr)
{
ed=md-1;
}else
{
st=md+1;
}
}
lst=ed;
update(lst-remain+1,1);
update(lst+1,-1);
/*for(int i=1;i<=n;i++)
{
printf("%d ",query(i));
}
printf("\n");*/
}
}
}
}Compilation message (stderr)
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
