diff --git a/src/10/20/P4087.cpp b/src/10/20/P4087.cpp new file mode 100644 index 0000000..0160678 --- /dev/null +++ b/src/10/20/P4087.cpp @@ -0,0 +1,60 @@ +#include +#include +#include +#include +#include +#include +#include +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 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"; +} \ No newline at end of file