天天看点

cd 915E(离散化+线段树)(新线段树模板)

写了一个新的线段树模板,相比上次的尝试这次的代码量有所减少有耶。。

emmmm先看看这题吧。。。汪聚聚动态开点pp了然而最终还是T了,毕竟复杂度接近1e7的话确实有点危险。。

然后正解其实是离散化。。。太弱了想不到qaq

离散化之后直接维护就可以。。然而没怎么写过离散化写起来困难重重蛙qaq

还是要多提高自己的姿势水平。。。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define eps 1e-8
#define inf (ll)10000000000
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define ls T[i<<1]
#define rs T[i<<1|1]
#define op T[i]
#define mid (x+y>>1)
#define NM 600005
#define nm 100005
#define pi 3.141592653
using namespace std;
int read(){
    int x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}

int n,m,a[NM],b[NM],c[NM],d[NM],tmp[NM];
int _x,_y,_t;
struct node{
    int tag,s,size;
    node*l,*r;
    void upd(){size=l->size+r->size;s=l->s+r->s;}
    node(int s,node *l=0,node *r=0):size(s),s(0),l(l),r(r),tag(-1){if(l)upd();}
    void push(){
        if(l&&~tag){
            l->tag=r->tag=tag;
            l->s=l->size*tag;r->s=r->size*tag;
            tag=-1;
        }
    }
    void mod(int x,int y){
        if(_y<x||y<_x)return;
        if(_x<=x&&y<=_y){this->s=_t*size;this->tag=_t;return;}
        push();
        l->mod(x,mid);r->mod(mid+1,y);
        upd();
    }
}*root;

node*build(int x,int y){return x==y?new node(c[x+1]-c[x]):new node(0,build(x,mid),build(mid+1,y));}


int main(){
#ifdef  db
    freopen("data.in","r",stdin);
#endif
    m=read();n=read();
    inc(i,1,n)c[i]=a[i]=read(),b[i]=read(),d[i]=read();
    inc(i,1,n)c[n+i]=b[i]+1;
    int tot=n;
    n<<=1;
    sort(c+1,c+n+1);
    n--;
    root=build(1,n);
#ifdef db
    inc(i,1,n)printf("%d  ",c[i]);putchar('\n');
    printf("%d\n",root->s);
#endif
    inc(i,1,tot){
        _x=lower_bound(c+1,c+1+n,a[i])-c;
        _y=upper_bound(c+1,c+1+n,b[i])-c-1;
#ifdef db
        printf("%d %d\n",_x,_y);
#endif
        _t=d[i]==1;
        root->mod(1,n);
        printf("%d\n",m-root->s);
    }
    return 0;
}      

E. Physical Education Lessons

time limit per test

memory limit per test

input

output

This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical education lessons. The end of the term is very soon, but, unfortunately, Alex still hasn't attended a single lesson!

Since Alex doesn't want to get expelled, he wants to know the number of working days left until the end of the term, so he can attend physical education lessons during these days. But in BSU calculating the number of working days is a complicated matter:

There are n days left before the end of the term (numbered from 1 to n), and initially all of them are working days. Then the university staff sequentially publishes q orders, one after another. Each order is characterised by three numbers l, r and k:

  • Ifk= 1, then all days fromltor
  • Ifk= 2, then all days fromltor

Help Alex to determine the number of working days left after each order!

Input

The first line contains one integer n, and the second line — one integer q (1 ≤ n ≤ 109, 1 ≤ q ≤ 3·105) — the number of days left before the end of the term, and the number of orders, respectively.

Then q lines follow, i-th line containing three integers li, ri and ki representing i-th order (1 ≤ li ≤ ri ≤ n, 1 ≤ ki ≤ 2).

Output

Print q integers. i-th of them must be equal to the number of working days left until the end of the term after the first i

Example

Input

4

6

1 2 1

3 4 1

2 3 2

1 3 2

2 4 1

1 4 2

Output

2

2

3

1

4