Untitled
unknown
plain_text
a month ago
2.8 kB
3
Indexable
Never
#include <bits/stdc++.h> using namespace std ; #define ll long long #define For(n) for(long long i = 0; i < n; i++) #define endl '\n' #define int long long struct node { int id; int score; }; struct cmp{ bool operator() (node n1,node n2)const{ if(n1.score<n2.score)return 1; else if(n1.score>n2.score)return 0; else return n1.id>n2.id; } }; void solve(){ map<int,int> mp; int n,q,x,y;;cin>>n>>q; set<node,cmp>prevscores; cin>>x>>y;mp[x]+=y; int ans=0,mxscore = y,winnerteam=x; for(int i=1;i<q;i++){ cin>>x>>y; mp[x]+= y; if(x==winnerteam && mp[x]<mxscore){// if winner team got fuckedup mxscore = mp[x];// update mxscore if(prevscores.empty())continue; node curr = *prevscores.crbegin(); if(mxscore<curr.score){ ans = i; mxscore = curr.score; winnerteam = curr.id; prevscores.erase(curr); } else if(mxscore==curr.score){ if(x>curr.id){ ans = i; winnerteam =curr.id; prevscores.erase(curr); } } } else if(mp[x]>mxscore){ if(winnerteam!=x){ ans = i; node neww; neww.id=winnerteam,neww.score=mxscore; prevscores.insert(neww); } winnerteam = x; mxscore = mp[x]; } else if(mp[x] == mxscore){ if(x<winnerteam){ ans = i; node neww;neww.id=winnerteam,neww.score=mxscore; prevscores.insert(neww); winnerteam = x; } else{ node neww,old; neww.id=x,neww.score=mp[x]; old.id =x;old.score = mp[x]-y; if(prevscores.find(old)!=prevscores.end()) prevscores.erase(old); prevscores.insert(neww); } } else{ node neww,old; neww.id=x,neww.score=mp[x]; old.id =x,old.score = mp[x]-y; if(prevscores.find(old)!=prevscores.end()) prevscores.erase(old); prevscores.insert(neww); } // cout << winnerteam<<' '<<mxscore<<' '<<prevscores.top().id<<' '<<prevscores.top().score<<endl; } if(ans)ans++; cout << ans << endl; } signed main () { ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); int t =1; cin>>t; while (t--){ solve(); } }
Leave a Comment