| 比赛 |
2026.9.5 |
评测结果 |
AAAAAAAAAAAAAAA |
| 题目名称 |
Pretty Pens |
最终得分 |
100 |
| 用户昵称 |
KKZH |
运行时间 |
4.656 s |
| 代码语言 |
C++ |
内存使用 |
25.44 MiB |
| 提交时间 |
2026-09-05 11:58:09 |
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N=2e5+10;
multiset <int> st[N],mx,mn;
int n,m,q,tot;
int c[N],sum[N],mmx[N],mxx[N];
void update(int col){
int ok2=1;
auto mxn=st[col].end();
mxn--;
auto mnn=mxn;
if(st[col].size()>1)
mnn--;
else ok2=0;
if(mmx[col]!=(*mxn)){
auto p1=mn.find(mmx[col]);
tot-=mmx[col];
mn.erase(p1);
tot+=(*mxn);
mn.insert(*mxn);
mmx[col]=(*mxn);
}
if(ok2==1){
if(mxx[col]!=(*mnn)){
if(mxx[col]!=-1){
auto p1=mx.find(mxx[col]);
mx.erase(p1);
}
mx.insert(*mnn);
mxx[col]=(*mnn);
}
}else{
if(mxx[col]!=-1){
auto p1=mx.find(mxx[col]);
mx.erase(p1);
}
mxx[col]=-1;
}
}
signed main(){
// freopen("s3.4-46.in","r",stdin);
freopen("Pens.in","r",stdin);
freopen("Pens.out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
cin>>n>>m>>q;
for(int i=1;i<=n;i++){
cin>>c[i]>>sum[i];
st[c[i]].insert(sum[i]);
}
for(int i=1;i<=m;i++){
// for(auto j:st[i]) cout<<j<<' ';
// cout<<'\n';
auto p=st[i].end();
p--;
mn.insert((*p));
tot+=*p;
mmx[i]=*p;
if(st[i].size()>1){
p--;
mxx[i]=*p;
mx.insert(*p);
}else mxx[i]=-1;
}
if(!mx.empty()){
auto p1=mn.begin();
auto p2=mx.end();
p2--;
cout<<max(tot-(*p1)+(*p2),tot)<<'\n';
}else cout<<tot<<'\n';
int x,y,z;
for(int i=1;i<=q;i++){
cin>>x>>y>>z;
if(x==1){
int col=c[y];
int p=sum[y];
c[y]=z;
auto it=st[col].find(p);
st[col].erase(it);
update(col);
st[z].insert(p);
update(z);
}else{
int col=c[y];
int p=sum[y];
sum[y]=z;
auto it=st[col].find(p);
st[col].erase(it);
st[col].insert(z);
update(col);
}
if(!mx.empty()){
auto p1=mn.begin();
auto p2=mx.end();
p2--;
cout<<max(tot-(*p1)+(*p2),tot)<<'\n';
}else cout<<tot<<'\n';
}
}