Gym 101234A Just question (NO answer!!!)

A. Hacker Cups and Balls
Problem ID: ademnoor

The dark side of Dreamoon, Ademnoor, wants to play an interesting game with you. Did you heard the game “cups and balls”? Here is the hacker version of it!
There are n cups and n balls, both are numbered 1, 2, … , n. Initially, The ai-th ball is placed in the i-th cup. Thus each cup will have exactly one ball inside. Admenoor will perform m magic operations on these balls and cups. The i-th operation will sort all the balls in the cups numbered between li and ri, inclusively. The sorting could be performed in either ascending order or descending order. After these m operations, you need to answer which ball is placed in the center cup. We guarantee that n would be an odd integer, so the center cup means the n+1 -th
cup.

For example, if n = 5, m = 2 and a = [5, 1, 4, 2, 3]. If the first operation is sort the balls in the cups numbered between 1 and 4 in ascending order, then a would become [1, 2, 4, 5, 3]. If the second operation is sort the balls in the cups numbered between 2 and 5 in descending order, then a would become [1, 5, 4, 3, 2]. In this example, the number of final ball in the center cup is 4.

Input

The first line of input contains two integers n, m. The following line contains n integers a1, a2, … , an. Each of the following m lines contains two integers li, ri. If li < ri, Admenoor will sort that balls in ascending order in this operation; Otherwise, the balls will be sorted in descending order in this operation.

• 1 ≤ n ≤ 99999
• n is an odd integer
• 0 ≤ m ≤ 105
• 1 ≤ ai ≤ n
• a[] is a permutation of 1, 2, … , n
• 1 ≤ li, ri ≤ n

Output

Output a single line with the number of the ball in the center cup.

Sample Input 1
3 2
1 3 2
1 3
3 1
Sample Output 1
2

Sample Input 2
5 2
5 1 4 2 3
1 4
5 2
Sample Output2
4

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值