求问为什么超时,该怎么修改
#include<bits/stdc++.h>
#define mid (l+r>>1)
using namespace std;
const int N=15001000;
struct Tree{
int s,lay=-1,lson,rson;
}t[N];
int n,q,root,cnt;
void PU(int u){
t[u].s=t[t[u].lson].s+t[t[u].rson].s;
}
void PD(int u,int l,int r){
if(t[u].lay>=0){
if(!t[u].lson){
t[u].lson=++cnt;
}
t[t[u].lson].s=t[u].lay*(mid-l+1);
t[t[u].lson].lay=t[u].lay;
if(!t[u].rson){
t[u].rson=++cnt;
}
t[t[u].rson].s=t[u].lay*(r-mid);
t[t[u].rson].lay=t[u].lay;
t[u].lay=-1;
}
}
void change(int L,int R,int &u,int l,int r,int k){
if(!u)u=++cnt;
if(L<=l&&r<=R){
t[u].s=k*(r-l+1);
t[u].lay=k;
return;
}
PD(u,l,r);
if(L<=mid){
change(L,R,t[u].lson,l,mid,k);
}
if(mid<R){
change(L,R,t[u].rson,mid+1,r,k);
}
PU(u);
}
int main(){
// freopen("weekday.in","r",stdin);
// freopen("weekday.out","w",stdout);
ios::sync_with_stdio(0);
cin >> n >> q;
change(1,n,root,1,n,0);
while(q--){
int l,r,k;
cin >> l >> r >> k;
change(l,r,root,1,n,2-k);
cout << n-t[1].s << '\n';
}
return 0;
}