摘苹果的算法应用问题,怎么利用C语言程序设计的办法来解决的

Problem Description
There is an apple tree in front of Taotao's house. When autumn comes, n apples on the tree ripen, and Taotao will go to pick these apples.

When Taotao picks apples, Taotao scans these apples from the first one to the last one. If the current apple is the first apple, or it is strictly higher than the previously picked one, then Taotao will pick this apple; otherwise, he will not pick.

Given the heights of these apples h1,h2,⋯,hn, you are required to answer some independent queries. Each query is two integers p,q, which asks the number of apples Taotao would pick, if the height of the p-th apple were q (instead of hp). Can you answer all these queries?

Input
The first line of input is a single line of integer T (1≤T≤10), the number of test cases.

Each test case begins with a line of two integers n,m (1≤n,m≤105), denoting the number of apples and the number of queries. It is then followed by a single line of n integers h1,h2,⋯,hn (1≤hi≤109), denoting the heights of the apples. The next m lines give the queries. Each of these m lines contains two integers p (1≤p≤n) and q (1≤q≤109), as described in the problem statement.

Output
For each query, display the answer in a single line.

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

Sample Output
1
5
3

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!

相似问题

1
手机视频播放插件安卓,苹果兼容性问题
3
wx.previewImage 黑屏 苹果好用,安卓黑屏
5
iOS 项目第一次构建,邮件返回的问题如何解决?
2
有没有申请过台湾公司的苹果开发者账号?
1
用PHP写的程序,安卓手机点击下载查看附件时,显示下载的附件名乱码,网页和苹果手机不会
2
苹果6手机,系统IOS 10,如何不越狱修改MAC地址,寻大神!!
2
越狱后的苹果手机如何能被检测到没越狱,具体针对一个软件,能解决的RMB重金酬谢!!
2
数据库表和字段的关系如何设计比较好?
1
后端java 前端vue 前后分离 有ipk下载地址 怎么让苹果手机安装
1
新手求教:关于虫子吃苹果问题
2
html5 百度定图定位,在苹果手机好用,在安卓手机,浏览器内定位是精确的,微信内置浏览器定位不好用
1
建视频站 资源站API怎么获取
3
其他浏览器中的链接,强制使用safari打开
9
网页多张连续图片时,图片之间有白线
1
如何解决苹果 iso safari下div元素滑动时,不让同级div元素跟着滑动,并且还有橡皮筋效果的问题
2
苹果企业账号的描述文件过期后,APP闪退,请问各位大神有好的解决方案么?
1
项目中遇到了一个算法问题,求推荐个解决思路;
1
多个手机与多个硬件在不依靠网络 进行数据交互问题
1
在苹果5移动设备上使用jquery事件时无效
2
matlab 多元线性回归问题