天天看点

codeforces 915 E 896 C 珂朵莉树(ODT)

/*
 * @Author: vain
 * @Date: 2020
 * @LastEditTime: 2020-09-23 19:00:14
 * @LastEditors: sueRimn
 * @Description: 学不会 dp 的 fw
 * @FilePath: \main\demo.cpp
 */
//#include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <ctime>
#include <cstring>
#include <cstdlib>
#include <math.h>
#include <bitset>
using namespace std;
typedef long long ll;
#define
//typedef unsigned long long uint;
const int N = 1e3 + 20;
const int maxn = 1e5 + 20;
int a[maxn];
// typedef pair<int, int> p;
// priority_queue<p, vector<p>, greater<p>> m;
//int sum[maxn];
int max(int a, int b) { return a > b ? a : b; }
int min(int a, int b) { return a < b ? a : b; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
void swap(int &x, int &y) { x ^= y, y ^= x, x ^= y; }
int lowbit(int x) { return (x) & (-x); }
struct node
{
    int l, r;
    mutable int w;
    node(int L = 0, int R = -1, int W = 0) : l(L), r(R), w(W){};
    bool operator<(const node &x) const { return l < x.l; }
};
#define
set<node> S;
int ans;
It split(int pos)
{
    It it = S.lower_bound(pos);
    if (it != S.end() && it->l == pos)
        return it;
    it--;
    int L = it->l, R = it->r, w = it->w;
    S.erase(it);
    S.insert(node(L, pos - 1, w));
    return S.insert(node(pos, R, w)).first;
}
void push(int l, int r, int w) 
{

    It itr = split(r + 1), itl = split(l);
    int sum, res;
    sum = res = 0;
    for (It it = itl; it != itr; it++)
    {
        if ((it->w) && (w))
            sum += it -> r - it->l + 1;
        if (!(it->w) && !(w))
            res += it -> r - it->l + 1;
    }
    S.erase(itl, itr);
    S.insert(node(l, r, w));
    if (w)
        ans += r - l + 1 - sum;
    else
        ans += res - (r - l + 1);
}

int main()
{
    // ios::sync_with_stdio(false);
    // cin.tie(0), cout.tie(0);
    int n, q;
    scanf("%d %d", &n, &q);
    S.insert(node(1, n, 1));
    ans = n;
    while (q--)
    {
        int k, l, r;
        scanf("%d %d %d", &l, &r, &k);
        push(l, r, k - 1);
        printf("%d\n", ans);
    }
}