int C[maxn];
int lowbit(int x)
{
return x&(-x);
}
void updata(int pos, int tmp)
{
for(; pos<=100000; pos+=lowbit(pos))
C[pos] += tmp;
}
int query(int pos)
{
int a = 0;
for(; pos>0; pos-=lowbit(pos)) a+=C[pos];
return a;
}
void ans(int b, int k)
{
int l=b+1, r=100000, mid, tmp;
int sm = query(b);
while(l<r)
{
mid = (l+r)/2;
tmp = query(mid);
//cout<<" mid ++ "<<mid<<' '<<tmp<<endl;
if(tmp<k+sm) l = mid+1;
else r = mid;
}
//cout<<tmp<<' '<<x<<' '<<sm<<endl;
if(query(l)>=k+sm)
{
printf("%d\n", l); return;
}
puts("Not Find!");
}
int main()
{
int m;
int a, b, c;
while(~scanf("%d", &m))
{
memset(C, 0, sizeof(C));
while(m--)
{
scanf("%d%d", &a, &b);
if(a==0) updata(b, 1);
else if(a==1)
{
if( query(b)==query(b-1) ) puts("No Elment!");
else updata(b, -1);
}
else
{
scanf("%d", &c);
ans(b, c);
}
}
}
return 0;
}
HDU-2852-树状数组+第k小数
最新推荐文章于 2024-05-09 00:45:37 发布