比赛 2026.9.5 评测结果 AAAAAAAAWAWTTTT
题目名称 Pretty Pens 最终得分 58
用户昵称 Ruyi 运行时间 13.714 s
代码语言 C++ 内存使用 15.86 MiB
提交时间 2026-09-05 08:37:25
显示代码纯文本
#include<bits/stdc++.h>
#define ll long long
#define N 200001
using namespace std;
ll n,m,c[N],p[N],q,op,x,y,minx,maxx,ans;
pair<ll,ll> pll;
priority_queue<pair<ll,ll>> pq[N];
ll read(){
	ll x=0,f=1;
	char c=' ';
	while(c>'9'||c<'0'){
		if(c=='-') f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=x*10+(c-'0');
		c=getchar();
	}
	return x*f;
}
void write(ll x){
	if(x<0){
		putchar('-');
		x=-x;
	}
	if(x>9) write(x/10);
	putchar(x%10+'0');
	return ; 
}
void solve(){
    maxx=ans=0;
    minx=1e18;
    for(int i=1;i<=m;i++){
        while(pq[i].size()&&(c[pq[i].top().second]!=i||p[pq[i].top().second]!=pq[i].top().first)) pq[i].pop();
        ans+=pq[i].top().first;
        minx=min(minx,pq[i].top().first);
        pll=pq[i].top();
        pq[i].pop();
        while(pq[i].size()&&(c[pq[i].top().second]!=i||p[pq[i].top().second]!=pq[i].top().first)) pq[i].pop();
        if(pq[i].size()) maxx=max(maxx,pq[i].top().first);
        pq[i].push(pll);
    }
    if(maxx>minx) ans+=maxx-minx;
    write(ans);
    putchar('\n');
    return ;
} 
int main(){
    freopen("Pens.in","r",stdin);
    freopen("Pens.out","w",stdout);
    n=read();
    m=read();
    q=read();
    for(int i=1;i<=n;i++){
        c[i]=read();
        p[i]=read();
        pq[c[i]].push({p[i],i});
    }
    solve();
    while(q--){
        op=read();
        x=read();
        y=read();
        if(op==1) c[x]=y;
        else p[x]=y;
        pq[c[x]].push({p[x],x});
        solve();
    }
    return 0;
}