思路;
恶心;
代码:
#include#include #include #include using namespace std;#define maxn 200005struct TreeNodeType { int l,r,dis,mid,flag; bool if_;};struct TreeNodeType tree[maxn<<2];struct QueryType { int l,r,id;};struct QueryType qu[maxn];int n,m,ai[maxn],sg[maxn],ans[maxn],Next[maxn],last[maxn];int num[maxn];inline void in(int &now){ char Cget=getchar();now=0; while(Cget>'9'||Cget<'0') Cget=getchar(); while(Cget>='0'&&Cget<='9') { now=now*10+Cget-'0'; Cget=getchar(); }}void tree_build(int now,int l,int r){ tree[now].l=l,tree[now].r=r; if(l==r) { tree[now].dis=sg[l];return; } tree[now].mid=l+r>>1; tree_build(now<<1,l,tree[now].mid); tree_build(now<<1|1,tree[now].mid+1,r); tree[now].dis=min(tree[now<<1].dis,tree[now<<1|1].dis);}void tree_down(int now){ tree[now<<1].dis=min(tree[now<<1].dis,tree[now].flag); tree[now<<1|1].dis=min(tree[now<<1|1].dis,tree[now].flag); if(tree[now<<1].if_) tree[now<<1].flag=min(tree[now<<1].flag,tree[now].flag); else tree[now<<1].flag=tree[now].flag,tree[now<<1].if_=true; if(tree[now<<1|1].if_) tree[now<<1|1].flag=min(tree[now<<1|1].flag,tree[now].flag); else tree[now<<1|1].flag=tree[now].flag,tree[now<<1|1].if_=true; tree[now].if_=false;return ;}void tree_change(int now,int l,int r,int x){ if(tree[now].l==l&&tree[now].r==r) { tree[now].dis=min(tree[now].dis,x); if(tree[now].if_) tree[now].flag=min(tree[now].flag,x); else tree[now].flag=x,tree[now].if_=true; return ; } if(tree[now].if_) tree_down(now); if(r<=tree[now].mid) tree_change(now<<1,l,r,x); else if(l>tree[now].mid) tree_change(now<<1|1,l,r,x); else tree_change(now<<1,l,tree[now].mid,x),tree_change(now<<1|1,tree[now].mid+1,r,x); tree[now].dis=min(tree[now<<1].dis,tree[now<<1|1].dis);}int tree_query(int now,int to){ if(tree[now].l==tree[now].r) return tree[now].dis; if(tree[now].if_) tree_down(now); if(to<=tree[now].mid) return tree_query(now<<1,to); else return tree_query(now<<1|1,to);}bool cmp(QueryType aa,QueryType bb){ return aa.l