| 比赛 |
2026.9.5 |
评测结果 |
AAAEEAAAWEEWWAW |
| 题目名称 |
Pretty Pens |
最终得分 |
46 |
| 用户昵称 |
董彰奇 |
运行时间 |
5.177 s |
| 代码语言 |
C++ |
内存使用 |
31.59 MiB |
| 提交时间 |
2026-09-05 12:59:03 |
显示代码纯文本
#include"bits/stdc++.h"
using namespace std;
int n, m, q, maxn[200010];
struct node
{
int c, p;
} x[200010];
priority_queue<int>q_[200010];
struct pode
{
int c, p;
bool operator<(const pode& b)const
{
return b.p < p;
}
};
map<pode, int> ty, tt, tq;
struct qode
{
int c, p;
bool operator<(const qode& b)const
{
return b.p > p;
}
};
priority_queue<pode>t;
priority_queue<qode>y;
int 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 >> x[i].c >> x[i].p;
if (maxn[x[i].c] == 0)
{
maxn[x[i].c] = x[i].p;
t.push({ x[i].c, x[i].p });
continue;
}
if (x[i].p > maxn[x[i].c] && maxn[x[i].c])
{
q_[x[i].c].push(maxn[x[i].c]);
tt[{x[i].c, maxn[x[i].c]}]++;
y.push({ x[i].c, maxn[x[i].c] });
maxn[x[i].c] = x[i].p;
t.push({ x[i].c, x[i].p });
}
else
{
q_[x[i].c].push(x[i].p);
y.push({ x[i].c, x[i].p });
}
}
long long ans = 0;
for (int i = 1; i <= m; i++)ans += maxn[i];
while (tt[{t.top().c, t.top().p}])
{
tt[{t.top().c, t.top().p}]--;
t.pop();
}
if (y.top().p > t.top().p)
{
cout << ans - t.top().p + y.top().p << '\n';
}
else
{
cout << ans << '\n';
}
for (int i = 1; i <= q; i++)
{
int cho;
cin >> cho;
if (cho == 2)
{
int c, xx;
cin >> c >> xx;
while (q_[x[c].c].size() && tq[{x[c].c, q_[x[c].c].top()}])
{
tq[{x[c].c, q_[x[c].c].top()}]--;
q_[x[c].c].pop();
}
if (x[c].p == maxn[x[c].c])
{
ans -= maxn[x[c].c];
tt[{x[c].c, x[c].p}]++;
if (xx >= q_[x[c].c].top())
{
t.push({ x[c].c, xx });
maxn[x[c].c] = xx;
}
else
{
t.push({ x[c].c, q_[x[c].c].top() });
maxn[x[c].c] = q_[x[c].c].top();
ty[{x[c].c, q_[x[c].c].top()}]++;
t.push({ x[c].c, q_[x[c].c].top() });
q_[x[c].c].pop();
q_[x[c].c].push(xx);
y.push({ x[c].c, xx });
}
ans += maxn[x[c].c];
}
else
{
tq[{x[c].c, x[c].p}]++;
ty[{x[c].c, x[c].p}]++;
if (xx > maxn[x[c].c]) {
tt[{x[c].c, maxn[x[c].c]}]++;
t.push({ x[c].c,xx});
q_[x[c].c].push(maxn[x[c].c]);
y.push({ x[c].c,maxn[x[c].c] });
ans += (xx - maxn[x[c].c]);
maxn[x[c].c] = xx;
}
else {
y.push({ x[c].c, xx });
q_[x[c].c].push(xx);
}
}
x[c].p = xx;
}
else
{
int c, yy;
cin >> c >> yy;
while (q_[yy].size() && tq[{yy, q_[yy].top()}])
{
tq[{yy, q_[yy].top()}]--;
q_[yy].pop();
}
while (q_[x[c].c].size() && tq[{x[c].c, q_[x[c].c].top()}])
{
tq[{c, q_[x[c].c].top()}]--;
q_[x[c].c].pop();
}
if (x[c].p == maxn[x[c].c])
{
ans -= maxn[x[c].c];
ans += q_[x[c].c].top();
maxn[x[c].c] = q_[x[c].c].top();
t.push({ x[c].c, q_[x[c].c].top() });
q_[x[c].c].pop();
tt[{x[c].c, x[c].p}]++;
if (x[c].p > maxn[yy])
{
ans += (x[c].p - maxn[yy]);
tt[{yy, maxn[yy]}]++;
t.push({ yy, x[c].p });
q_[yy].push(maxn[yy]);
y.push({ yy, maxn[yy] });
maxn[yy] = x[c].p;
}
else
{
y.push({ yy, x[c].p });
q_[yy].push(x[c].p);
}
}
else
{
tq[{x[c].c, x[c].p}]++;
ty[{x[c].c, x[c].p}]++;
if (x[c].p > maxn[yy])
{
ans += (x[c].p - maxn[yy]);
tt[{yy, maxn[yy]}]++;
t.push({ yy, x[c].p });
q_[yy].push(maxn[yy]);
maxn[yy] = x[c].p;
}
else
{
q_[yy].push(x[c].p);
y.push({ yy, x[c].p });
}
}
x[c].c = yy;
}
while (tt[{t.top().c, t.top().p}])
{
tt[{t.top().c, t.top().p}]--;
t.pop();
}
while (ty[{y.top().c, y.top().p}])
{
ty[{y.top().c, y.top().p}]--;
y.pop();
}
if (y.top().p >= t.top().p)
{
cout << ans - t.top().p + y.top().p << '\n';
}
else
{
cout << ans << '\n';
}
}
return 0;
}