mirror of
https://gitcode.com/Zengtudor/alg2025.git
synced 2025-10-26 10:02:47 +00:00
feat: 添加P4087题解实现
实现P4087题目解决方案,包括输入处理、排序和统计逻辑。使用map维护奶牛产奶量排名变化,计算需要更新广告牌的次数。
This commit is contained in:
parent
779ef8b327
commit
65e1874d65
60
src/10/20/P4087.cpp
Normal file
60
src/10/20/P4087.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
#include <algorithm>
|
||||||
|
#include <cmath>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <iostream>
|
||||||
|
#include <istream>
|
||||||
|
#include <iterator>
|
||||||
|
#include <map>
|
||||||
|
using ll = int64_t;
|
||||||
|
|
||||||
|
const ll maxn = 10'0000 + 5, inf = 1e9 + 7;
|
||||||
|
struct C {
|
||||||
|
ll d, c, a;
|
||||||
|
inline bool operator<(const C &o) const {
|
||||||
|
return d < o.d;
|
||||||
|
}
|
||||||
|
} c[maxn];
|
||||||
|
ll n, g, ans;
|
||||||
|
std::map<ll, ll> cow_num, num_cowcount;
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::iostream::sync_with_stdio(false);
|
||||||
|
std::cin.tie(nullptr);
|
||||||
|
|
||||||
|
std::cin >> n >> g;
|
||||||
|
for (ll i = 1; i <= n; i++) {
|
||||||
|
std::cin >> c[i].d >> c[i].c >> c[i].a;
|
||||||
|
}
|
||||||
|
std::sort(c + 1, c + 1 + n);
|
||||||
|
|
||||||
|
num_cowcount[0] = inf;
|
||||||
|
|
||||||
|
for (ll i = 1; i <= n; i++) {
|
||||||
|
|
||||||
|
ll max_num_before = num_cowcount.rbegin()->first;
|
||||||
|
bool just_one_was_max = num_cowcount.rbegin()->second==1;
|
||||||
|
|
||||||
|
ll old_cownum = cow_num[c[i].c];
|
||||||
|
|
||||||
|
bool was_top = (old_cownum == max_num_before);
|
||||||
|
|
||||||
|
num_cowcount[old_cownum]--;
|
||||||
|
if (num_cowcount[old_cownum] == 0) {
|
||||||
|
num_cowcount.erase(old_cownum);
|
||||||
|
}
|
||||||
|
|
||||||
|
ll new_cownum = old_cownum + c[i].a;
|
||||||
|
cow_num[c[i].c] = new_cownum;
|
||||||
|
|
||||||
|
num_cowcount[new_cownum]++;
|
||||||
|
|
||||||
|
ll max_num_after = num_cowcount.rbegin()->first;
|
||||||
|
|
||||||
|
bool is_top = (new_cownum == max_num_after);
|
||||||
|
|
||||||
|
if ((max_num_before != max_num_after && !just_one_was_max) || (was_top != is_top)) {
|
||||||
|
ans++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
std::cout << ans << "\n";
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user