hdu2852 KiKi ' s k-number tree-like array for K-large number

Source: Internet
Author: User

Getsum (b-1) <getsum (a) +k<=getsum (b) is required for the second largest number of K
B is the K-large number of a.
Also Gesum (b-1) <=getsum (b) can be used to find two points to do
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace Std;
const int maxn=100010;
int TREE[MAXN];
int lowbit (int i)
{
Return (i& (-i));
}
int getsum (int i)
{
int sum=0;
while (i>0)
{
Sum+=tree[i];
I-=lowbit (i);
}
return sum;
}
void update (int i,int dx)
{
while (I&LT;MAXN)
{
TREE[I]+=DX;
I+=lowbit (i);
}
}
void Find (int left,int right,int num)
{
while (Left<=right)
{
int middle= (left+right)/2;
int middle = left + (right-left)/2;
int tmp=getsum (middle);
if (tmp<num)
left=middle+1;
Else
right=middle-1;
}
if (LEFT&GT;=MAXN)
printf ("Not find!\n");
Else
printf ("%d\n", left);
}
int main ()
{
Freopen ("In.txt", "R", stdin);
Freopen ("OUT.txt", "w", stdout);
int m;
while (scanf ("%d", &m)!=eof)
{
int p,a,k;
memset (tree,0,sizeof (tree));
while (m--)
{
scanf ("%d", &p);
if (p==0)
{
scanf ("%d", &a);
Update (a,1);
}
else if (p==1)
{
scanf ("%d", &a);
if (! ( Getsum (a)-getsum (A-1))
{
printf ("No elment!\n");
Continue
}
Else
Update (A,-1);
}
Else
{
scanf ("%d%d", &a,&k);
int Tmp=getsum (a);
Find (A+1,MAXN-1,TMP+K);
}
}
}
}











































































































hdu2852 KiKi ' s k-number tree-like array for K-large number

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.