比赛 2026.9.5 评测结果 AAAEEAAAAEAAAAA
题目名称 Pretty Pens 最终得分 81
用户昵称 终焉折枝 运行时间 4.745 s
代码语言 C++ 内存使用 23.83 MiB
提交时间 2026-09-05 10:46:10
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;

using ll = long long;
using f64 = double;
using f128 = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi  = vector<int>;
using vll = vector<ll>;

#define pb emplace_back
#define mk make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)((x).size())
#define ciallo(x) cerr << (x) << '\n';

template <typename T, typename U>
inline bool chmin(T& a, const U& b){return (b < a ? a = b, true : false);}
template <typename T, typename U>
inline bool chmax(T& a, const U& b){return (a < b ? a = b, true : false);}

const int N = 2 * 1e5 + 5;
int n, m, q;
multiset<int> st[N];
int c[N], p[N];
multiset<int> mx1, mx2;
int m1x[N], m2x[N];
ll ans = 0;

inline void solve(){
    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 ++){
        int szst = sz(st[i]);
        if(szst == 0){
            m1x[i] = 0;
            m2x[i] = 0;
        }
        else if(szst == 1){
            m1x[i] = *(--st[i].end());
            mx1.insert(*--st[i].end());
            m2x[i] = 0;
        }
        else{
            auto itst = st[i].end();
            m1x[i] = *(-- itst);
            mx1.insert(*itst);
            m2x[i] = *(-- itst);
            mx2.insert(*itst);
        }
        ans += m1x[i];
    }
    auto itt1 = mx1.begin();
    auto itt2 = mx2.end();
    itt2 --;
//    cout << *itt1 << ' ' << *itt2 << '\n';
    if(*itt2 > *itt1) cout << ans - *itt1 + *itt2 << '\n';
    else cout << ans << '\n';
    while(q --){
        int op, pos, x;
        cin >> op >> pos >> x;
        if(op == 1){
            // 删除原来的最大值和次大值 
            ans -= m1x[c[pos]];
            ans -= m1x[x];
            if(m1x[c[pos]]) mx1.erase(mx1.find(m1x[c[pos]]));
            if(m2x[c[pos]]) mx2.erase(mx2.find(m2x[c[pos]]));
            if(m1x[x]) mx1.erase(mx1.find(m1x[x]));
            if(m2x[x]) mx2.erase(mx2.find(m2x[x])); 
            // 重插入
            st[c[pos]].erase(st[c[pos]].find(p[pos]));
            st[x].insert(p[pos]);
            // 重新记录 c[pos] 的最大值和次大值,并插入 大 次大 
            int szpos = sz(st[c[pos]]);
            if(szpos == 0){
                m1x[c[pos]] = 0;
                m2x[c[pos]] = 0;
            }
            else if(szpos == 1){
                m1x[c[pos]] = *(--st[c[pos]].end());
                mx1.insert(*(--st[c[pos]].end()));
                m2x[c[pos]] = 0;
            }
            else{
                auto itpos = st[c[pos]].end();
                m1x[c[pos]] = *(-- itpos);
                mx1.insert(*itpos);
                m2x[c[pos]] = *(-- itpos);
                mx2.insert(*itpos);
            }
            ans += m1x[c[pos]];
            // 重新记录 x 的最大值和次大值,并插入 大 次大 
            int szx = sz(st[x]);
            if(szx == 0){
                m1x[x] = 0;
                m2x[x] = 0;
            }
            else if(szx == 1){
                m1x[x] = *(--st[x].end());
                mx1.insert(*(--st[x].end()));
                m2x[x] = 0;
            }
            else{
                auto itx = st[x].end();
                m1x[x] = *(--itx);
                mx1.insert(*itx);
                m2x[x] = *(--itx);
                mx2.insert(*itx);
            }
            ans += m1x[x];
            c[pos] = x;
        }
        else{
            // p[pos] = val;
            int col = c[pos];
            // 删除 col 中的最大值和次大值
            ans -= m1x[col];
            if(m1x[col]) mx1.erase(mx1.find(m1x[col]));
            if(m2x[col]) mx2.erase(mx2.find(m2x[col]));
            // 删除原来 pos 的 p[pos] 值,并插入新的 val
            st[col].erase(st[col].find(p[pos]));
            st[col].insert(x);
            // 更新 col 的最大值和次大值
            int szcol = sz(st[col]);
            if(szcol == 0){
                m1x[col] = 0;
                m2x[col] = 0;
            }
            else if(szcol == 1){
                m1x[col] = *(--st[col].end());
                mx1.insert(*(--st[col].end()));
                m2x[col] = 0;
            }
            else{
                auto itcol = st[col].end();
                m1x[col] = *(--itcol);
                mx1.insert(*itcol);
                m2x[col] = *(--itcol);
                mx2.insert(*itcol);
            }
            // 更新 p[pos] 
            ans += m1x[col];
            p[pos] = x; 
        }
        auto it1 = mx1.begin();
        auto it2 = mx2.end();
        it2 --;
        if(*it2 > *it1) cout << ans - *it1 + *it2 << '\n';
        else cout << ans << '\n';
    }
}

int main(){
    freopen("Pens.in", "r", stdin);
    freopen("Pens.out", "w", stdout);
    cin.tie(0) -> ios::sync_with_stdio(0);
    int T = 1;
//    cin >> T;
    while(T --) solve();
//    #ifdef LOCAL
//        cout << "Time: " << 1.0 * clock() / CLOCKS_PER_SEC << " s\n ";
//    #endif
    return 0;
}