Scoreboard queries

In a tournament there are (N+1) players, N players have already played and their scores are denoted by an array A. Here, A1 is the score of the first player, A2 of the second, ..., AN of the Nth 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 the case of a 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.

Example:

Input:  n = 4, q = 1, arr = {2, 1, 1, 5}

Output:

5

Approach:

C++

#include <bits/stdc++.h>
using namespace std;

void scoreboardQueries(long nlong qvector<longv,
                       vector<vector<long>> &queries)
{
    unordered_map<longlongboard;
    for (long i = 1i <= n; ++i)
    {

        ++board[v[i]];
    }
    for (long i = 0i < qi++)
    {
        long l = queries[i][0];
        long r = queries[i][1];
        --board[v[l]];
        if (board[v[l]] == 0)
            board.erase(v[l]);
        v[l] = r;
        ++board[v[l]];
        cout << board.size() + 1 << "\n";
    }
}
int main()
{

    long n = 4q = 1;
    vector<longarr = {2115};
    vector<longv(n + 1);
    for (long i = 1i <= ni++)
        v[i] = arr[i - 1];
    vector<vector<long>> queries = {{23}};

    scoreboardQueries(nqvqueries);

    return 0;
}


No comments:

Post a Comment