Skip to content
Programmingoneonone
Programmingoneonone
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

HackerEarth Scoreboard queries problem solution

YASH PAL, 31 July 2024
In this HackerEarth Scoreboard queries problem solution 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.
HackerEarth Scoreboard queries problem solution

HackerEarth Scoreboard queries problem solutions.

#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mod 1000000007
#define endl "n"
#define test ll txtc; cin>>txtc; while(txtc--)
typedef long long int ll;
typedef long double ld;
int main() {
FIO;
test
{
ll n,q,x,l,r; cin>>n>>q;
set<ll>s;
map<ll,ll>mp;
vector<ll>a(n);
for(int i=0;i<n;i++){
cin>>a[i];
s.insert(a[i]);
mp[a[i]]++;
}
while(q--){
cin>>l>>r;
l--;
mp[a[l]]--;
if(mp[a[l]]==0){
s.erase(s.find(a[l]));
}
mp[r]++;
s.insert(r);
a[l]=r;
cout<<(ll)s.size()+1ll<<endl;
}

}
return 0;
}

Second solution

t = int(input())
while t > 0:
t -= 1
n, q = map(int, input().split())
have = dict()
scores = list(map(int, input().split()))
for score in scores:
have[score] = have.get(score, 0) + 1
while q > 0:
q -= 1
i, nw = map(int, input().split())
i -= 1
have[scores[i]] -= 1
if have[scores[i]] == 0:
have.pop(scores[i])
scores[i] = nw
have[scores[i]] = have.get(scores[i], 0) + 1
print(len(have) + 1)
coding problems solutions

Post navigation

Previous post
Next post

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2026 Programmingoneonone | WordPress Theme by SuperbThemes