#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define pii pair #define mem(a,b) memset(a,b,sizeof(a)) #define lson l,mid,rt<<1 #define rson mid+1,r,rt<<1|1 #define PI acos(-1.0) typedef __int64 LL; typedef unsigned __int64 ULL; const int N=100010; const int INF=0x3f3f3f3f; const int MOD=95041567,STA=8000010; const LL LNF=1LL<<60; const double EPS=1e-8; const double OO=1e15; const int dx[4]={-1,0,1,0}; const int dy[4]={0,1,0,-1}; const int day[13]={0,31,28,31,30,31,30,31,31,30,31,30,31}; inline int sign(double x){return (x>EPS)-(x<-EPS);} template T gcd(T a,T b){return b?gcd(b,a%b):a;} template T lcm(T a,T b){return a/gcd(a,b)*b;} template inline T lcm(T a,T b,T d){return a/d*b;} template inline T Min(T a,T b){return a inline T Max(T a,T b){return a>b?a:b;} template inline T Min(T a,T b,T c){return min(min(a, b),c);} template inline T Max(T a,T b,T c){return max(max(a, b),c);} template inline T Min(T a,T b,T c,T d){return min(min(a, b),min(c,d));} template inline T Max(T a,T b,T c,T d){return max(max(a, b),max(c,d));} LL low[N<<2][2],f[N]; int l[N],la[N],q[N][2],type[N],eng[N]; int T,n; void update(int l,int r,int rt,int w,LL val,int flag) { if(l==r){ low[rt][flag]=val; return; } int mid=(l+r)>>1; if(w<=mid)update(lson,w,val,flag); else update(rson,w,val,flag); low[rt][flag]=Min(low[rt<<1][flag],low[rt<<1|1][flag]); } LL query(int l,int r,int rt,int L,int R,int flag) { if(L<=l && r<=R){ return low[rt][flag]; } int mid=(l+r)>>1; LL ret=LNF; if(L<=mid)ret=Min(ret,query(lson,L,R,flag)); if(R>mid)ret=Min(ret,query(rson,L,R,flag)); return ret; } int binary(int l,int r,int tar) { int mid; while(l>1; if(q[mid][0]