题目链接1:
题目链接2:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define re register
#define pb push_back
#define fi first
#define se second
void read(int &a)
{
a=0;int d=1;char ch;
while(ch=getchar(),ch>'9'||ch<'0')
if(ch=='-')
d=-1;
a=ch^48;
while(ch=getchar(),ch>='0'&&ch<='9')
a=(a<<3)+(a<<1)+(ch^48);
a*=d;
}
struct note
{
int l,r;
mutable int v;
note(int L,int R=-1,int V=0){l=L,r=R,v=V;}
bool operator < (const note &x) const
{
return l<x.l;
}
};
set <note> s;
set <note> :: iterator split(int pos)
{
auto it=s.lower_bound(note(pos));
if(it!=s.end()&&it->l==pos) return it;
it--;
if(it->r<pos) return s.end();
int L=it->l,R=it->r,V=it->v;
s.erase(it);
s.insert(note(L,pos-1,V));
return s.insert(note(pos,R,V)).fi;
}
int ans;
void modify(int l,int r,int w)
{
auto it2=split(r+1),it1=split(l),it=it1;
for(;it1!=it2;it1++) ans-=it1->v?it1->r-it1->l+1:0;
s.erase(it,it2);
s.insert(note(l,r,w));
ans+=(r-l+1)*w;
}
int main()
{
int n,m;
read(n),read(m);
ans=n;
s.insert(note(1,n,1));
s.insert(note(n+1,n+1,0));
for(re int i=1,op,l,r;i<=m;i++)
{
read(l),read(r),read(op);
if(op==1) modify(l,r,0);
else modify(l,r,1);
printf("%d
",ans);
}
return 0;
}