分析

非常平凡的一道题,没太大意义。这里放松,敲了一个 。有区间覆盖的,如果保证随机,其实 还是不错的。

代码

#include<bits/stdc++.h>
using namespace std;
struct Node{
    int l,r;
    mutable int c;
    bool operator <(const Node a) const {
        return l < a.l;
    }
    Node(int _l,int _r = 0,int _c = 0) {l=_l;r=_r;c=_c;}
};
set<Node> s;
#define It set<Node>::iterator 
int n,m;
int read(){int x;scanf("%d",&x);return x;}
It split(int pos) {
    It it = s.lower_bound((Node){pos,0,0});
    if(it != s.end() && it -> l == pos) return it;
    --it;int l = it->l,r = it->r,c = it -> c;
    s.erase(it);s.insert((Node){l,pos-1,c});
    return s.insert((Node){pos,r,c}).first;
}int sum;
void assgin(int l,int r,int c) {
    It itr = split(r + 1),itl = split(l);
    for(It it = itl;it != itr;++it) {
        sum -= (it->r-it->l+1) * it->c;
    }
    s.erase(itl,itr);
    s.insert((Node){l,r,c});
    sum += (r - l + 1) * c;
} 

int main() {
    n = read();m = read();
    s.insert((Node){1,n,1});sum = n;
    while(m--) {
        int l = read(),r = read(),k = read() - 1;
        assgin(l,r,k);
        printf("%d\n",sum);
    }
}