F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Taotao Picks Apples

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 4731    Accepted Submission(s): 1337


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 $h_1, h_2, \cdots, h_n$, 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 $h_p$). Can you answer all these queries?
 

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

Each test case begins with a line of two integers $n, m$ $(1 \leq n, m \leq 10^5)$, denoting the number of apples and the number of queries. It is then followed by a single line of $n$ integers $h_1, h_2, \cdots, h_n$ $(1 \leq h_i \leq 10^9)$, denoting the heights of the apples. The next $m$ lines give the queries. Each of these $m$ lines contains two integers $p$ $(1 \leq p \leq n)$ and $q$ $(1 \leq q \leq 10^9)$, 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
 

Hint

For the first query, the heights of the apples were 5, 2, 3, 4, 4, so Taotao would only pick the first apple.

For the second query, the heights of the apples were 1, 2, 3, 4, 5, so Taotao would pick all these five apples.

For the third query, the heights of the apples were 1, 3, 3, 4, 4, so Taotao would pick the first, the second and the fourth apples.
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-11-22 09:47:16, Gzip enabled