2009_10-5_Practice1 E

来源:互联网 发布:阐教 截教 知乎 编辑:程序博客网 时间:2024/04/29 08:54

<!--@page { margin: 2cm }P { margin-bottom: 0.21cm }-->

SpecialContainer

TimeLimit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K(Java/Others)

Designa container, which has two kinds of operation, push and pop.

Push:You should push the given number into the container.

Pop:Please find the middle number of the container. If these is n numbersin container, it will be the (n+1)/2-th num when sort increased. Thenpop the number.

Input

Theinput contains one or more data sets. At first line of each inputdata set is an integer N (1<= N <= 100000) indicate the numberof operations.

ThenN lines follows, each line contains a number (0 or 1). "0"means a push operation, it's followed by an integer E. "1"means a pop operation.

Youmay assume all the numbers in the input file will be in the range of32-bit integer.

Output

Foreach pop operation, you should print the integer popped. Please print"No Element!", if there is no number to pop. Please print ablank line after each data set.

 

SampleInput

9

010

0-10

05

1

1

02

1

1

1

3

02

01

1

 

SampleOutput

5

-10

2

10

NoElement!

 

1

 

 

1.用树状数组的方法,因为只有N次操作,但是不知道操作数范围,所以要先离散化一下,那么就要先记录;

2.有两种操作:push pop 在pop的时候怎样找到位置在(n+1)/2的数呢。。。肯定不能排序 位置在那个地方的数的特点是前面存在一定数量比他小的,因为是实时的操作,那么用树状数组记录某个

 

后记:我觉得这道题很强大。

首先刚开始看的时候我没有想到,后来听某牛说用树状数组可以解,就试着想了下

 

原创粉丝点击