1418 dynamic sequence statistics

Source: Internet
Author: User

 

Description

The binary sorting tree is used to design a data structure that supports fast sequential statistic operations. This data structure supports three operations: insert X inserts a number X into the dataset, delete x deletes a number X in the dataset, and order x outputs the number X in the current dataset. (Ensure that all elements in the dataset are not equal. The data in this question is Int)

Input

The initial data set of the first action. elements are separated by spaces. The number of M lines in the second action is M. The following M lines contain M commands. The Instruction format is described in the topic.

Output

Corresponding to each order x command, output the number X in the current dataset.

 

Simple search

#include <stdio.h>#include <string.h>char s[100000];int a[100000];main(){int number;int length,i,j;int p;int up;int temp;int count;char op;up=0;gets(s);length=strlen(s);i=0;p=0;for(i=0;i<length;i++){if(s[i]!=','){p=0;while(s[i] >= '0' && s[i] <= '9'&&i<length){p = p * 10 + s[i] - '0';i++;}a[up++]=p;}elsecontinue;}for(i=0;i<up;i++)for(j=i+1;j<up;j++){if(a[i]>a[j]){temp=a[i];a[i]=a[j];a[j]=temp;}}scanf("%d",&count);while(count--){getchar();scanf("%c",&op);if(op=='O'){for(i=0;i<5;i++)scanf("%c",&op);scanf("%d",&temp);printf("%d\n",a[temp-1]);}if(op=='I'){for(i=0;i<6;i++)                      scanf("%c",&op);scanf("%d",&temp);if(temp>a[up-1])a[up++]=temp;else{for(i=0;i<up;i++){if(a[i]>temp){  j=i;   break;}elsecontinue;}for(i=up;i>j;i--)a[i]=a[i-1];a[j]=temp;                   up++;}}if(op=='D'){for(i=0;i<6;i++)scanf("%c",&op);scanf("%d",&temp);for(i=0;i<up;i++)if(a[i]==temp)break;for(j=i;j<up-1;j++)a[j]=a[j+1];up--;}}}

 

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.