编程介的小学生 2019-05-14 21:31 采纳率: 20.5%
浏览 472

C语言摘苹果的编程问题,怎么利用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

  • 写回答

0条回答

    报告相同问题?

    悬赏问题

    • ¥15 opencv 无法读取视频
    • ¥15 用matlab 实现通信仿真
    • ¥15 按键修改电子时钟,C51单片机
    • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
    • ¥20 5037端口被adb自己占了
    • ¥15 python:excel数据写入多个对应word文档
    • ¥60 全一数分解素因子和素数循环节位数
    • ¥15 ffmpeg如何安装到虚拟环境
    • ¥188 寻找能做王者评分提取的
    • ¥15 matlab用simulink求解一个二阶微分方程,要求截图