#include #include #include #include #include using namespace std; long long readInt(long long l,long long r,char endd){ long long x=0; int cnt=0; int fi=-1; bool is_neg=false; while(true){ char g=getchar(); if(g=='-'){ assert(fi==-1); is_neg=true; continue; } if('0'<=g && g<='9'){ x*=10; x+=g-'0'; if(cnt==0){ fi=g-'0'; } cnt++; assert(fi!=0 || cnt==1); assert(fi!=0 || is_neg==false); assert(!(cnt>19 || ( cnt==19 && fi>1) )); } else if(g==endd){ assert(cnt>0); if(is_neg){ x= -x; } assert(l<=x && x<=r); return x; } else { assert(false); } } } string readString(int l,int r,char endd){ string ret=""; int cnt=0; while(true){ char g=getchar(); assert(g!=-1); if(g==endd){ break; } cnt++; ret+=g; } assert(l<=cnt && cnt<=r); return ret; } long long readIntSp(long long l,long long r){ return readInt(l,r,' '); } long long readIntLn(long long l,long long r){ return readInt(l,r,'\n'); } string readStringLn(int l,int r){ return readString(l,r,'\n'); } string readStringSp(int l,int r){ return readString(l,r,' '); } int T; int n,q,sm_n=0,sm_q=0; int d[100100]; int pl[100100]; int pr[100100]; int grp[100100]; int L[100100]; int R[100100]; long double depth[100100]; int root(int x){ if(grp[x] == x)return x; return grp[x] = root(grp[x]); } int jump_left(int x){ x=root(x); if(root(pl[x]) == x)return x; return pl[x] = jump_left(pl[x]); } int jump_right(int x){ x=root(x); if(root(pr[x]) == x)return x; return pr[x] = jump_right(pr[x]); } void merge_left(int x){ x=root(x); int y=root(L[x]-1); pl[x] = jump_left(y); grp[y] = x; L[x] = min(L[x],L[y]); R[x] = max(R[x],R[y]); } void merge_right(int x){ x=root(x); int y=root(R[x] + 1); pr[x] = jump_right(y); grp[y] = x; L[x] = min(L[x],L[y]); R[x] = max(R[x],R[y]); } long double capacity(int x){ x=root(x); long double LD = 0, RD = 0; if(L[x] > 1){ LD = depth[root(L[x]-1)]; } if(R[x] < n){ RD = depth[root(R[x] + 1)]; } return (depth[x] - max(LD,RD)) * (R[x] - L[x] + 1); } void fill(int x,long double h){ depth[x] -= h / (R[x] - L[x] + 1); } void output(){ cout<<"========="<1 && d[i-1] > d[i]){ pl[i] = i-1; } else { pl[i] = i; } if(i d[i]){ pr[i] = i+1; } else { pr[i] = i; } } for(int i=1;i= 1e-12){ /*output(); if(stop){ output_debug(); }*/ x=root(x); if(root(jump_left(x)) == x && root(jump_right(x)) == x){ long double cap = capacity(x); if(cap>=h){ depth[x] -= h / (R[x] - L[x] + 1); h=0; break; } h -= cap; long double LD = 0, RD = 0; if(L[x] > 1){ LD = depth[root(L[x]-1)]; } if(R[x] < n){ RD = depth[root(R[x] + 1)]; } if(L[x] > 1 && R[x] 1 && LD >= RD){ depth[x] = LD; merge_left(x); } else if(R[x] < n && LD <= RD){ depth[x] = RD; merge_right(x); } else { depth[x] = 0; break; } } else if(root(jump_left(x)) != x && root(jump_right(x)) != x){ int l_nd = root(jump_left(x)); int r_nd = root(jump_right(x)); long double cap_l = capacity(l_nd); long double cap_r = capacity(r_nd); if(min(cap_l,cap_r) > h/2){ fill(l_nd,h/2); fill(r_nd,h/2); break; } else if(cap_l < cap_r){ fill(r_nd,cap_l); h-= cap_l * 2; long double LD = 0, RD = 0; if(L[l_nd] > 1){ LD = depth[root(L[l_nd]-1)]; } if(R[l_nd] < n){ RD = depth[root(R[l_nd] + 1)]; } if(L[l_nd] > 1 && R[l_nd] 1 && LD >= RD){ depth[l_nd] = LD; merge_left(l_nd); } else if(R[l_nd] < n && LD <= RD){ depth[l_nd] = RD; merge_right(l_nd); } else { depth[l_nd] = 0; } } else { h-= cap_r * 2; fill(l_nd,cap_r); long double LD = 0, RD = 0; if(L[r_nd] > 1){ LD = depth[root(L[r_nd]-1)]; } if(R[r_nd] < n){ RD = depth[root(R[r_nd] + 1)]; } if(L[r_nd] > 1 && R[r_nd] 1 && LD >= RD){ depth[r_nd] = LD; merge_left(r_nd); } else if(R[r_nd] < n && LD <= RD){ depth[r_nd] = RD; merge_right(r_nd); } else { depth[r_nd] = 0; } } } else if(root(jump_left(x)) != x){ int nd_l = root(jump_left(x)); long double cap = capacity(nd_l); if(cap >= h){ fill(nd_l,h); h=0; break; } else { h -= cap; long double LD = 0, RD = 0; if(L[nd_l] > 1){ LD = depth[root(L[nd_l]-1)]; } if(R[nd_l] < n){ RD = depth[root(R[nd_l] + 1)]; } if(L[nd_l] > 1 && R[nd_l] 1 && LD >= RD){ depth[nd_l] = LD; merge_left(nd_l); } else if(R[nd_l] < n && LD <= RD){ depth[nd_l] = RD; merge_right(nd_l); } else { depth[nd_l] = 0; } } } else { int nd_r = root(jump_right(x)); long double cap = capacity(nd_r); if(cap >= h){ fill(nd_r,h); h=0; break; } else { h -= cap; long double LD = 0, RD = 0; if(L[nd_r] > 1){ LD = depth[root(L[nd_r]-1)]; } if(R[nd_r] < n){ RD = depth[root(R[nd_r] + 1)]; } if(L[nd_r] > 1 && R[nd_r] 1 && LD >= RD){ depth[nd_r] = LD; merge_left(nd_r); } else if(R[nd_r] < n && LD <= RD){ depth[nd_r] = RD; merge_right(nd_r); } else { depth[nd_r] = 0; } } } } } else { int x=readIntLn(1,n); cout<