| 比赛 |
2026.9.5 |
评测结果 |
AAAAAAAAAAAAAAA |
| 题目名称 |
Pretty Pens |
最终得分 |
100 |
| 用户昵称 |
dream |
运行时间 |
4.300 s |
| 代码语言 |
C++ |
内存使用 |
23.51 MiB |
| 提交时间 |
2026-09-05 09:19:45 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=200005;
int n,m,q;
multiset<int> st[N],cd,an;
ll ans;
void del(int x){
auto pt=st[x].end();
pt--;
auto er=an.lower_bound(*(pt));
ans-=(*er);
an.erase(er);
if(st[x].size()>1){
pt--;
er=cd.lower_bound(*(pt));
cd.erase(er);
}
}
void delx(int x,int y){
auto er=st[x].lower_bound(y);
st[x].erase(er);
}
void add(int i){
auto ed=st[i].end();
ed--;
ans+=(*ed);
an.insert(*ed);
if(ed!=st[i].begin()){
ed--;
cd.insert(*ed);
}
}
ll qcd(){
if(cd.size()){
auto ed=cd.end();
ed--;
return (*ed);
}
return 0;
}
int c[N],p[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];
st[c[i]].insert(p[i]);
}
for(int i=1;i<=m;i++){
add(i);
}
ll exans=0;
exans=ans-(*(an.begin()))+qcd();
cout<<max(ans,exans)<<"\n";
for(int i=1;i<=q;i++){
int op,x,y;
cin>>op>>x>>y;
if(op==1){
if(c[x]==y){}
else{
del(c[x]);
del(y);
delx(c[x],p[x]);
add(c[x]);
c[x]=y;
st[c[x]].insert(p[x]);
add(c[x]);
}
}
else{
del(c[x]);
delx(c[x],p[x]);
p[x]=y;
st[c[x]].insert(p[x]);
add(c[x]);
}
exans=ans-(*(an.begin()))+qcd();
cout<<max(ans,exans)<<"\n";
}
return 0;
}