题解:P15081 [ICPC 2024 Chengdu R] Grand Prix of Ballance
小模拟。拿一个 now 记录现在的关卡,然后看每个命令是否有效就行了。
#include<bits/stdc++.h>
using namespace std;
pair<long long,int> a[100005]; //编号为 j 的人拿了 i 分
int b[100005]; //第 i 场比赛有几人完成了
map<pair<int,int>,int> mp; //第 i 个人在第 j 个关卡是否已有命令
bool cmp(pair<long long,int> x,pair<long long,int> y){
return x.first>y.first||x.first==y.first&&x.second<y.second;
}
int main(){
int T;
cin >> T;
while(T--){
int n,m,q;
int now=-1; //关卡
memset(a,0,sizeof a);
memset(b,0,sizeof b);
mp.clear();
cin >> n >> m >> q;
for(int i=1;i<=m;i++){
a[i].second=i;
}
while(q--){
int op,id,x;
cin >> op;
if(op==1){
cin >> x;
now=x;
}
else if(op==2){
cin >> id >> x;
if(x!=now||mp[{id,x}]) continue;
b[x]++;
a[id].first+=m-b[x]+1;
mp[{id,x}]=1; //记录
}
else{
cin >> id >> x;
if(x!=now) continue;
mp[{id,x}]=1; //记录
}
}
sort(a+1,a+m+1,cmp); //排序v
for(int i=1;i<=m;i++){
cout << a[i].second << " " << a[i].first << endl;
}
}
return 0;
}