In a tournament there are players, players have already played and their scores are denoted by an array . Here, is the score of the first player, of the second, ..., of the player.
Now, the organizers decide the ranks according to the following rules:
The player scored more than player , player 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 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 n, long q, vector<long> v,vector<vector<long>> &queries){unordered_map<long, long> board;for (long i = 1; i <= n; ++i){++board[v[i]];}for (long i = 0; i < q; i++){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 = 4, q = 1;vector<long> arr = {2, 1, 1, 5};vector<long> v(n + 1);for (long i = 1; i <= n; i++)v[i] = arr[i - 1];vector<vector<long>> queries = {{2, 3}};scoreboardQueries(n, q, v, queries);return 0;}
No comments:
Post a Comment