Skip to content

Instantly share code, notes, and snippets.

@ewmson
Created October 23, 2017 20:18
Show Gist options
  • Save ewmson/2827c884b18dec2904bc5388bade4cbc to your computer and use it in GitHub Desktop.
Save ewmson/2827c884b18dec2904bc5388bade4cbc to your computer and use it in GitHub Desktop.
#include <bits/stdc++.h>
#include <set>
using namespace std;
typedef long long ll;
struct Team {
int num;
int probs;
ll penalty;
bool operator< (const Team& t) const {
if (probs < t.probs) {
return true;
} else if (probs == t.probs && penalty > t.penalty) {
return true;
} else if (probs == t.probs && penalty == t.penalty && num > t.num) {
return true;
}
return false;
}
};
set<Team> buckets[100001];
Team teams[100001];
int findPlace(int bucket) {
int count = 1;
for (Team t : buckets[bucket]) {
if (t.num == teams[1].num) {
return (buckets[bucket].size() - count) + 1;
}
count++;
}
exit(-1);
}
int main() {
int n, m;
scanf("%d%d", &n, &m);
int rank = 1;
for (int i = 1; i <= n; i++) {
teams[i].num = i;
buckets[0].insert(teams[i]);
}
for (int i = 0; i < m; i++) {
int a, b;
scanf("%d%d", &a, &b);
if (a != 1) {
bool less = false;
if (teams[a] < teams[1]) {
less = true;
}
buckets[teams[a].probs].erase(buckets[teams[a].probs].find(teams[a]));
teams[a].probs++;
teams[a].penalty += b;
if (less && teams[1] < teams[a]) {
rank++;
}
buckets[teams[a].probs].insert(teams[a]);
} else {
int curr = findPlace(teams[1].probs);
buckets[teams[1].probs].erase(buckets[teams[1].probs].find(teams[1]));
teams[1].probs++;
teams[1].penalty += b;
buckets[teams[1].probs].insert(teams[1]);
int next = findPlace(teams[1].probs);
rank -= (curr - 1) + (buckets[teams[1].probs].size() - next);
}
cout << rank << endl;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment