Scoreboard queries
Practice
3.6 (39 votes)
Arrays
Data structures
Data manipulation
1 D
Problem
91% Success 14156 Attempts 30 Points 2.5s Time Limit 256MB Memory 1024 KB Max Code

In a tournament there are \((N+1)\) players, \(N\) players have already played and their scores are denoted by an array \(A\). Here, \(A_1\) is the score of the first player, \(A_2\) of the second, ..., \(A_N\) of the \(N^{th}\) player.

Now, the organizers decide the ranks according to the following rules:

The player \(x\) scored more than player \(y\), player \(x\) gets a better rank.

In case of tie, the player with lower indices gets a better rank.

Now, it is the turn of the \((N+1)^{th}\) player to play. Before playing, he wants to know the number of ranks that he can secure so that he can decide his strategy.

Now, the jury has some scoreboard updates. Therefore, your task is to tell the jury after every update the number of distinct possible ranks that he can get.

Input format

  • The first line contains the number of test cases \(T\).
  • The first line of each test case contains two integers \(N\) and \(Q\) denoting the number of players who have already played and the number of updates by jury.
  • The second line of each test case contains \(N\) space-separated integers of array \(A\).
  • Next \(Q\) lines of each test case contain two integers \(L\) and \(R\) denoting the score of the \(L^{th}\) player has changed to \(R\).

Output format

For each test case:

  • Print \(Q\) lines denoting the number of possible ranks which \((n+1)^{th}\) player can get after every update.

Constraints:

\(1 \leq T \leq 1000 \)

\(1 \leq N,Q \leq 100000\)

\(1 \leq A_i \leq 1e9 \forall i \in [1,N]\)

\(1 \leq L \leq N\)

\(1 \leq R \leq 1e9\)

The sum of \(N\) and \(Q\) in over all test cases does not exceed 100000.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
71 votes
Tags:
Data StructuresImplementationMedium
Points:30
126 votes
Tags:
Data StructuresImplementationMediumOne-dimensionalSets
Points:30
64 votes
Tags:
ArraysData StructuresMediumOne-dimensionalStacks