Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T>
- using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- using pll = pair<ll, ll>;
- using vl = vector<ll>;
- using vi = vector<int>;
- int main(int argc, char **argv) {
- ll n, q;
- cin >> n >> q;
- vl cnt(n + 1, 1);
- using a2l = array<ll, 2>;
- map<a2l, ll> cs;
- for (ll i = 0; i <= n + 1; ++i)
- cs[{i, i + 1}] = i;
- for (ll i = 0, op, x, c; i < q; ++i) {
- cin >> op;
- switch (op) {
- case 1: {
- cin >> x >> c;
- auto it = std::prev(cs.upper_bound({x, LLONG_MAX}));
- auto [lb, ub] = it->first;
- ll old_color = it->second, old_cnt = ub - lb;
- cnt[old_color] -= old_cnt, cnt[c] += old_cnt;
- auto pre = std::prev(it), nxt = std::next(it);
- dbg(x, lb, ub, old_color, c);
- if (nxt->second == c) {
- assert(ub == (nxt->first)[0]);
- ub = (nxt->first)[1];
- cs.erase(nxt);
- }
- cs.erase(it);
- if (pre->second == c) {
- assert(lb == (pre->first)[1]);
- lb = (pre->first)[0];
- cs.erase(pre);
- }
- cs.insert({{lb, ub}, c});
- break;
- }
- case 2: {
- cin >> c;
- cout << cnt[c] << '\n';
- break;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement