| 比赛 |
2026.9.5 |
评测结果 |
AAAAAAAAAAATTTT |
| 题目名称 |
Pretty Pens |
最终得分 |
72 |
| 用户昵称 |
彭欣越 |
运行时间 |
13.876 s |
| 代码语言 |
C++ |
内存使用 |
16.59 MiB |
| 提交时间 |
2026-09-05 11:43:24 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200010,M=500010;
int n,m,Q,id[M],mk[M];
int c[M],p[M];
struct node {
ll x;
int id;
bool operator<(const node &o) const{
return x<o.x;
}
};
priority_queue<node>q[N],q1,q2;
int main () {
freopen("Pens.in","r",stdin);
freopen("Pens.out","w",stdout);
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin >> n >> m >> Q;
for (int i=1;i<=n;i++) {
cin >> c[i] >> p[i];
q[c[i]].push({p[i],i});
id[i]=i;
}
ll mx=0,mn=1e18,ans=0;
for (int i=1;i<=m;i++) {
ll t=q[i].top().x;
int id=q[i].top().id;
ans+=t;
mn=min(mn,t);
q[i].pop();
if (!q[i].empty()) mx=max(mx,q[i].top().x);
q[i].push({t,id});
}
ans+=max(0ll,mx-mn);
cout << ans <<"\n";
int cnt=n;
while (Q--) {
ans=mx=0;
mn=1e18;
ll op,x,y;
cin >> op >> x >> y;
if (op==1) {
if (q[c[id[x]]].top().id==id[x]) {
q[c[id[x]]].pop();
}else{
mk[id[x]]=1;
}
cnt++;
c[cnt]=y,p[cnt]=p[id[x]];
//cout << c[cnt] <<' '<< p[cnt] <<"\n";
id[x]=cnt;
q[y].push({p[cnt],cnt});
}else{
if (q[c[id[x]]].top().id==id[x]) {
q[c[id[x]]].pop();
}else{
//cout << id[x] <<"\n";
mk[id[x]]=1;
}
cnt++;
c[cnt]=c[id[x]],p[cnt]=y;
id[x]=cnt;
q[c[cnt]].push({y,cnt});
}
/*
if (q[y].top().id==cnt) {
id[y]=++tot;
q1.push({-p[cnt],tot});
q2.push()
}
*/
for (int i=1;i<=m;i++) {
while (!q[i].empty()&&mk[q[i].top().id]) q[i].pop();
ll t=q[i].top().x;
int id=q[i].top().id;
//cout << t <<' '<< id <<"\n";
ans+=t;
mn=min(mn,t);
q[i].pop();
while (!q[i].empty()&&mk[q[i].top().id]) q[i].pop();
//cout << q[i].top().id <<"\n";
if (!q[i].empty()) mx=max(mx,q[i].top().x);
q[i].push({t,id});
}
cout << ans+max(0ll,mx-mn) <<"\n";
}
return 0;
}