Loading

Educational Codeforces Round 36 (Rated for Div. 2) E Physical Education Lessons

Physical Education Lessons

珂朵莉树 模板

#include <iostream>
#include <cstdio>
#include <set>
using namespace std;
#define It set<ran>::iterator

struct ran
{
    int l, r;
    mutable int v;
    ran(){}
    ran(int _l, int _r, int _v)
    {
        l = _l;
        r = _r;
        v = _v;
    }
    bool operator < (const ran &x) const
    {
        return l < x.l;
    }
};

set<ran>st;
int ans = 0;
It split(int pos)
{
    It now = st.lower_bound(ran(pos, -1, 0));
    if(now != st.end() && now->l == pos) return now;
    now--;
    int l = now->l, r = now->r, v = now->v;
    st.erase(now);
    st.insert(ran(l, pos - 1, v));
    return st.insert(ran(pos, r, v)).first;
}

void merge(int l, int r, int v)
{
    It ir = split(r + 1), il = split(l);
    for(It it=il; it!=ir; it++)
        ans -= it->v * (it->r - it->l + 1);
    st.erase(il, ir);
    st.insert(ran(l, r, v));
    ans += (r - l + 1) * v;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    ans = n;
    st.insert(ran(1, n, 1));
    while(q--)
    {
        int l, r, v;
        cin >> l >> r >> v;
        v--;
        merge(l, r, v);
        cout << ans << "\n";
    }
    return 0;
}
posted @ 2022-11-23 12:59  dgsvygd  阅读(21)  评论(0编辑  收藏  举报