| 比赛 |
2026.9.5 |
评测结果 |
AAAAAAAAAAAAAAA |
| 题目名称 |
Pretty Pens |
最终得分 |
100 |
| 用户昵称 |
VTXE |
运行时间 |
4.635 s |
| 代码语言 |
C++ |
内存使用 |
25.09 MiB |
| 提交时间 |
2026-09-05 09:25:57 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll n,m,q;
ll c[210000],p[210000];
ll ans,cnt;
multiset <ll> ps[210000],p1,p2;
ll getm(ll o){
return *ps[o].rbegin();
}
ll gets(ll o){
if (ps[o].size()<2) return -1e18;
auto it=ps[o].end();
it--;it--;
return *it;
}
void add(ll o){
ll n1=getm(o),n2=gets(o);
p1.insert(n1);
cnt+=n1;
if (n2!=-1e18) p2.insert(n2);
}
void del(ll o){
ll n1,n2;
n1=getm(o);
n2=gets(o);
p1.erase(p1.find(n1));
cnt-=n1;
if (n2!=-1e18){
p2.erase(p2.find(n2));
}
}
void solve(){
ans=cnt;
if (!p2.empty()){
ll aa,bb;
aa=*p2.rbegin();
bb=*p1.begin();
if (aa>bb) ans+=aa-bb;
}
cout<<ans<<'\n';
}
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];
ps[c[i]].insert(p[i]);
}
for (int i=1;i<=m;i++) add(i);
solve();
ll op,i,x,y;
while (q--){
cin>>op>>i;
if (op==1){
cin>>x;
del(c[i]);
ps[c[i]].erase(ps[c[i]].find(p[i]));
add(c[i]);
c[i]=x;
del(c[i]);
ps[c[i]].insert(p[i]);
add(c[i]);
}else{
cin>>y;
del(c[i]);
ps[c[i]].erase(ps[c[i]].find(p[i]));
p[i]=y;
ps[c[i]].insert(p[i]);
add(c[i]);
}
solve();
}
return 0;
}