#include typedef long long ll; ll gi(){ ll x=0,f=1; char ch=getchar(); while(!isdigit(ch))f^=ch=='-',ch=getchar(); while(isdigit(ch))x=x*10+ch-'0',ch=getchar(); return f?x:-x; } std::mt19937 rnd(time(NULL)); #define rand rnd #define pr std::pair #define all(x) (x).begin(),(x).end() #define fi first #define se second templatevoid cxk(T&a,T b){a=a>b?a:b;} templatevoid cnk(T&a,T b){a=a>=1; } return ret; } templatevoid inc(Ta&a,Tb b){a=a+b>=mod?a+b-mod:a+b;} templatevoid dec(Ta&a,Tb b){a=a>=b?a-b:a+mod-b;} #endif int n,m,p[2000010],ql[2000010],qr[2000010],ans[2000010]; std::vectorQ[2000010];std::setS; int col_end[2000010],next[2000010],len[2000010]; int max[5000010]; #define mid ((l+r)>>1) void build(int x,int l,int r){ if(l==r){max[x]=len[l];return;} build(x<<1,l,mid); build(x<<1|1,mid+1,r); max[x]=std::max(max[x<<1],max[x<<1|1]); } void update(int x,int l,int r,int p){ if(l==r){max[x]=0;return;} if(p<=mid)update(x<<1,l,mid,p); else update(x<<1|1,mid+1,r,p); max[x]=std::max(max[x<<1],max[x<<1|1]); } int query(int x,int l,int r,int L,int R){ if(L<=l&&r<=R)return max[x]; if(L<=mid) if(mid