| 比赛 |
2026.9.5 |
评测结果 |
AAAAATWTTWWTTTT |
| 题目名称 |
Pretty Pens |
最终得分 |
30 |
| 用户昵称 |
汐汐很希希 |
运行时间 |
23.820 s |
| 代码语言 |
C++ |
内存使用 |
12.97 MiB |
| 提交时间 |
2026-09-05 09:33:10 |
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=2e5+10;
int n,m,q,c[N],p[N];
priority_queue<int> pq[N];
ll sum=0,mmax=-999;
void work()
{
priority_queue<int, vector<int>, greater<int> > pq1;
for(int i=1;i<=m;i++){
int t=pq[i].top();
sum+=t,pq1.push(t);
pq[i].pop();
if(!pq[i].empty()) mmax=max(mmax,pq[i].top()*1LL);
pq[i].push(t);
}
if(mmax<=pq1.top()) cout<<sum<<endl;
else cout<<sum+mmax-pq1.top()<<endl;
}
int main()
{
freopen("Pens.in","r",stdin);
freopen("Pens.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0);
cin>>n>>m>>q;
for(int i=1;i<=n;i++) cin>>c[i]>>p[i],pq[c[i]].push(p[i]);
work();
while(q--){
int op,i,x;
cin>>op>>i>>x;
int tc=c[i],tp=p[i],t[N],cnt=0;
if(op==1){
c[i]=x;
while(pq[tc].top()!=tp){
t[++cnt]=pq[tc].top();
pq[tc].pop();
}
pq[tc].pop();
for(int i=1;i<=cnt;i++) pq[tc].push(t[i]);
pq[c[i]].push(p[i]);
}else if(op==2){
p[i]=x;
while(pq[tc].top()!=tp){
t[++cnt]=pq[tc].top();
pq[tc].pop();
}
pq[tc].pop();
for(int i=1;i<=cnt;i++) pq[tc].push(t[i]);
pq[c[i]].push(p[i]);
}
work();
}
return 0;
}