比赛 2026.9.5 评测结果 WWWWWWWWWWWWWWW
题目名称 Pretty Pens 最终得分 0
用户昵称 赵飞羽 运行时间 0.164 s
代码语言 C++ 内存使用 13.10 MiB
提交时间 2026-09-05 11:53:55
显示代码纯文本
#include <bits/stdc++.h>
#define int long long
using namespace std;

constexpr int N = 200010;
int n, m, q, res, c[N], p[N];
multiset <int> a[N], mx2, mx1;

signed main() {
	freopen("s3.3-30.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];
		a[c[i]].insert(p[i]);
	}
	for (int i = 1; i <= m; i++) {
		auto p1 = (--a[i].end());
		auto p2 = (--a[i].end());
		--p2;
		res += (*p1);
		mx1.insert(*p1);
		if (a[i].size() > 1) mx2.insert(*p2);
	}
	if (mx2.size()) cout << res + (*(--mx2.end()) > *(mx1.begin())) * (*(--mx2.end()) - *(mx1.begin())) << "\n";
	else cout << res << "\n";
	while (q--) {
		int op, x, y;
		cin >> op >> x >> y;
		if (op == 1) {
			auto p1 = a[c[x]].find(p[x]);
			auto p3 = (--a[c[x]].end());
			auto p4 = (--a[c[x]].end());
			--p4;
			int v1 = (*p1), v3 = (*p3), v4 = (*p4);
			res -= v3;
			p3 = mx1.find(v3);
			p4 = mx2.find(v4);
			if (mx1.size() && p3 != mx1.end()) mx1.erase(p3);
			if (mx2.size() && p4 != mx2.end()) mx2.erase(p4);
			p1 = a[c[x]].find(p[x]);
			a[c[x]].erase(p1);
			p3 = (--a[c[x]].end());
			p4 = (--a[c[x]].end());
			--p4;
			res += *p3;
			mx1.insert(*p3);
			if (a[c[x]].size() > 1) mx2.insert(*p4);
			p3 = (--a[y].end());
			p4 = (--a[y].end());
			--p4;
			v3 = (*p3), v4 = (*p4);
			res -= v3;
			p3 = mx1.find(v3);
			p4 = mx2.find(v4);
			if (mx1.size() && p3 != mx1.end()) mx1.erase(p3);
			if (mx2.size() && p4 != mx2.end()) mx2.erase(p4);
			a[y].insert(v1);
			p3 = (--a[y].end());
			p4 = (--a[y].end());
			--p4;
			mx1.insert(*p3);
			if (a[y].size() > 1) mx2.insert(*p4);
			res += *(--a[y].end());
			c[x] = y;
//			cout << "awa\n";
//			for (auto i: a[1]) cout << i << " ";
//			cout << "\n";
//			for (auto i: a[2]) cout << i << " ";
//			cout << "\n";
//			for (auto i: mx2) cout << i << " ";
//			cout << "\n";
//			for (auto i: mx1) cout << i << " ";
//			cout << "\nawa\n\n";
		} else {
			auto p1 = a[c[x]].find(p[x]);
			auto p3 = (--a[c[x]].end());
			auto p4 = (--a[c[x]].end());
			--p4;
			int v1 = (*p1), v3 = (*p3), v4 = (*p4);
			res -= v3;
			p3 = mx1.find(v3);
			p4 = mx2.find(v4);
			if (mx1.size() && p3 != mx1.end()) mx1.erase(p3);
			if (mx2.size() && p4 != mx2.end()) mx2.erase(p4);
			p1 = a[c[x]].find(p[x]);
			a[c[x]].erase(p1);
			a[c[x]].insert(y);
			p3 = (--a[c[x]].end());
			p4 = (--a[c[x]].end());
			--p4;
			mx1.insert(*p3);
			if (a[c[x]].size() > 1) mx2.insert(*p4);
			res += *(--a[c[x]].end());
			p[x] = y;
//			cout << "awa\n";
//			for (auto i: a[1]) cout << i << " ";
//			cout << "\n";
//			for (auto i: a[2]) cout << i << " ";
//			cout << "\n";
//			for (auto i: mx2) cout << i << " ";
//			cout << "\n";
//			for (auto i: mx1) cout << i << " ";
//			cout << "\nawa\n\n";
		}
//		if (mx2.size()) cout << op << "QWQ\n";
		if (mx2.size()) cout << res + (*(--mx2.end()) > *(mx1.begin())) * (*(--mx2.end()) - *(mx1.begin())) << "\n";
		else cout << res << "\n";
	}
	return 0;
}
/*
3 2 6
1 978090923
2 978090923
2 978090925
2 2 978090929
2 3 978090921
2 2 978090921
1 2 1
2 2 978090928
1 2 2

*/