Gym 101234A Just question (NO answer!!!)
来源:互联网 发布:九次方大数据借壳上市 编辑:程序博客网 时间:2024/04/29 23:28
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
- Gym 101234A Just question (NO answer!!!)
- A Question And Answer Site
- some Form question & answer
- Question and answer
- GYM 100488 E.Just Change a Word(水~)
- The answer to the question
- Answer's Question about pointer
- The Project Management Question and Answer Book
- The Project Management Question and Answer Book
- WordPress 在线问答插件 DW Question & Answer
- QUESTION NO: 146
- QUESTION NO: 158
- QUESTION NO: 159
- QUESTION NO: 160
- QUESTION NO: 162
- QUESTION NO: 163
- QUESTION NO: 165
- QUESTION NO: 167
- css3 2d转换3d转换以及动画的知识点汇总
- 主席树模板题
- SharedSDK(三):sharedSdk集成分享及第三方登陆(下载文档Sdk)
- 博客迁移至http://blog.rookiehacker.org
- 从算法上解读自动驾驶是如何实现的?
- Gym 101234A Just question (NO answer!!!)
- 神的主权与人的自由 (李建安)
- N皇后
- CSS3阴影 box-shadow的使用和技巧总结
- 冒泡排序法笔记
- [C++] 数据结构之顺序栈
- C语言头文件避免重复包含
- OpenGL学习总结(八)
- MyBatis中模糊查询