比赛 2026.9.5 评测结果 AAAAAAAAAAAAAAA
题目名称 Pretty Pens 最终得分 100
用户昵称 xuyuqing 运行时间 9.916 s
代码语言 C++ 内存使用 37.20 MiB
提交时间 2026-09-05 11:19:51
显示代码纯文本

#include <algorithm>
#include <cstdio>
#include <iostream>
#include <set>
#include <utility>
#include <vector>

using namespace std;

const int N = 214514;

int n;
int m;
int q;
int c[N];
long long p[N];
vector<pair<long long, int> > ps[N];

multiset<long long> nums[3];

pair<long long, int> max_one[N];
pair<long long, int> max_two[N];
multiset<pair<long long, int> > others[N];

long long max_one_sum;

void display_res () {
//    cout << max_one_sum << ' ' << *nums[1].begin() << ' ' << *nums[2].rbegin() << ' ' << max_one[1].first << ' ' << max_two[1].first << endl;
    if (!nums[2].empty() && *nums[1].begin() < *nums[2].rbegin()) {
        cout << max_one_sum - *nums[1].begin() + *nums[2].rbegin() << endl;
    }
    else {
        cout << max_one_sum << endl;
    }
}

int main () {
    
    freopen ("Pens.in", "r", stdin);
    freopen ("Pens.out", "w", stdout);
    
    scanf ("%d%d%d", &n, &m, &q);
    for (int i = 1; i <= n; i++) {
        scanf ("%d%lld", &(c[i]), &(p[i]));
        ps[c[i]].emplace_back(p[i], i);
    }
    
//    nums[0].insert(0);
//    nums[1].insert(1e9 + 10);
//    nums[2].insert(0);
    for (int i = 1; i <= m; i++) {
        sort (ps[i].begin(), ps[i].end());
        for (int j = 0; j < ps[i].size(); j++) {
            if (j == ps[i].size() - 1) {
                nums[1].insert(ps[i][j].first);
                max_one_sum += ps[i][j].first;
                max_one[i] = ps[i][j];
            }
            else if (j == ps[i].size() - 2) {
                nums[2].insert(ps[i][j].first);
                max_two[i] = ps[i][j];
            }
            else {
                nums[0].insert(ps[i][j].first);
                others[i].insert(ps[i][j]);
            }
        }
    }

    display_res ();
    
    int opt, id, x;
    for (int i = 1; i <= q; i++) {
        scanf ("%d%d%d", &opt, &id, &x);
        
        if (max_one[c[id]].second == id) {
            max_one_sum -= max_one[c[id]].first;
            nums[1].erase(nums[1].find(max_one[c[id]].first));
            max_one[c[id]] = max_two[c[id]];
            max_one_sum += max_one[c[id]].first;
            nums[1].insert(max_one[c[id]].first);
            
            if (!nums[2].empty() && max_two[c[id]].first) {
                nums[2].erase(nums[2].find(max_two[c[id]].first));
            }
            if (!others[c[id]].empty()) {
                max_two[c[id]] = *others[c[id]].rbegin();
            }
            else {
                max_two[c[id]] = make_pair (0, 0);
            }
            nums[2].insert(max_two[c[id]].first);
            
            if (!others[c[id]].empty()) {
                nums[0].erase(nums[0].find((*others[c[id]].rbegin()).first));
                others[c[id]].erase(others[c[id]].find(*others[c[id]].rbegin()));
            }
        }
        else if (max_two[c[id]].second == id) {
            if (!nums[2].empty() && max_two[c[id]].first) {
                nums[2].erase(nums[2].find(max_two[c[id]].first));
            }
            if (!others[c[id]].empty()) {
                max_two[c[id]] = *others[c[id]].rbegin();
            }
            else {
                max_two[c[id]] = make_pair (0, 0);
            }
            nums[2].insert(max_two[c[id]].first);
            
            if (!others[c[id]].empty()) {
                nums[0].erase(nums[0].find((*others[c[id]].rbegin()).first));
                others[c[id]].erase(others[c[id]].find(*others[c[id]].rbegin()));
            }
        }
        else {
            nums[0].erase(nums[0].find(p[id]));
            others[c[id]].erase(others[c[id]].find(make_pair (p[id], id)));
        }
        
        if (opt == 1) {
            c[id] = x;
        }
        else {
            p[id] = x;
        }
        
        if (p[id] > max_one[c[id]].first) {
//            nums[1].erase(p[id]);
            
            if (max_two[c[id]].first) {
                others[c[id]].insert(max_two[c[id]]);
                nums[0].insert(max_two[c[id]].first);
            }
            
            if (!nums[2].empty()) {
                nums[2].erase(nums[2].find(max_two[c[id]].first));
            }
            max_two[c[id]] = max_one[c[id]];
            nums[2].insert(max_two[c[id]].first);
            
            max_one_sum -= max_one[c[id]].first;
            nums[1].erase(nums[1].find(max_one[c[id]].first));
            max_one[c[id]] = make_pair (p[id], id);
            max_one_sum += max_one[c[id]].first;
            nums[1].insert(max_one[c[id]].first);
        }
        else if (p[id] > max_two[c[id]].first) {
//            nums[2].erase(p[id]);

            if (max_two[c[id]].first) {
                others[c[id]].insert(max_two[c[id]]);
                nums[0].insert(max_two[c[id]].first);
            }
            
            if (!nums[2].empty()) {
                nums[2].erase(nums[2].find(max_two[c[id]].first));
            }
            max_two[c[id]] = make_pair (p[id], id);
            nums[2].insert(max_two[c[id]].first);
        }
        else {
            others[c[id]].insert(make_pair (p[id], id));
            nums[0].insert(p[id]);
        }
        
        display_res ();
    }
        
    return 0;
}