2009_10-5_Practice1 E

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

Special Container

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

Design a 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 numbers in container, it will be the (n+1)/2-th num when sort increased. Then pop the number.

Input

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

Then N 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.

You may assume all the numbers in the input file will be in the range of 32-bit integer.

Output

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

 

Sample Input

9

0 10

0 -10

0 5

1

1

0 2

1

1

1

3

0 2

0 1

1

 

Sample Output

5

-10

2

10

No Element!

 

1

 

 

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

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

 

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

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

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值