比赛 2026.9.5 评测结果 AAAAAAAATAWAAAA
题目名称 Pretty Pens 最终得分 86
用户昵称 zcx 运行时间 5.664 s
代码语言 C++ 内存使用 21.91 MiB
提交时间 2026-09-05 11:53:24
显示代码纯文本
#include<bits/stdc++.h>
#define int long long
#define pr pair<int,int>
#define val first
#define id second
using namespace std;

const int N = 2e5 + 5;
const int INF = 1e9 ;

int n,m,Q,sum = 0;
int c[N],p[N],vis[N],tt[N][2];

priority_queue<pr> q[N],q2; 
priority_queue<pr,vector<pr>,greater<pr> > q1;

void get(int x){
    vis[tt[x][0]] = vis[tt[x][1]] = 0;
    pr p1,p2;
    while(c[q[x].top().id] != x || p[q[x].top().id] != q[x].top().val) q[x].pop();
    p1 = q[x].top();q[x].pop();sum += p1.val;
    while(q[x].size() && (c[q[x].top().id] != x || p[q[x].top().id] != q[x].top().val)) q[x].pop();
    if(q[x].size()) p2 = q[x].top();
    else p2 = make_pair(0,0);
    q[x].push(p1);
    
    q1.push(p1);
    if(p2.id) q2.push(p2);
    vis[p1.id] = 1;vis[p2.id] = 2;
    tt[x][0] = p1.id;tt[x][1] = p2.id;
}

signed main()
{
    freopen("Pens.in","r",stdin);
    freopen("Pens.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin>>n>>m>>Q;
    
    for(int i = 1;i <= n;i++){
        cin>>c[i]>>p[i];
        q[c[i]].push(make_pair(p[i],i));
    }
    
    for(int i = 1;i <= m;i++) get(i);
    
    if(n == m){
        cout<<sum<<'\n';
        while(Q--){
            int op,x,y;cin>>op>>x>>y;
            sum += y - p[x];
            p[x] = y;
            cout<<sum<<'\n';
        }
        return 0;
    }
    
    cout<<sum + max(q1.top().val,q2.top().val) - q1.top().val<<'\n';
    
    while(Q--){
        int op,x,y;cin>>op>>x>>y;
        if(op == 1){
            int co = c[x];
            sum -= q[co].top().val + q[y].top().val;c[x] = y;
            q[y].push(make_pair(p[x],x));
            get(co);get(y);
        }else{
            sum -= q[c[x]].top().val;p[x] = y;
            q[c[x]].push(make_pair(y,x));
            get(c[x]);
        }
        while(vis[q1.top().id] != 1 || q1.top().val != p[q1.top().id]) q1.pop();
        while(q2.size() && (vis[q2.top().id] != 2 || q2.top().val != p[q2.top().id])) q2.pop();
        
        cout<<sum + max(q1.top().val,q2.top().val) - q1.top().val<<'\n';
        
    }
    
     
    return 0;
}