# BZOJ2567 : 篱笆

1. 区间$i$可以接上区间$i-1$

2. 可以覆盖位置$0$

3. 可以覆盖位置$all$

#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=120010,M=262150,BUF=30000000;
const ll inf=1LL<<60;
int T,n,m,type,i,x,y;ll all,r,len,a[N],b[N],ans;bool flag;char Buf[BUF],*buf=Buf;
struct P{
ll v,w,ma,mi;
void set(ll b){v=w=0,ma=mi=b;}
P operator+(const P&b){
P c;
c.v=max(max(v,b.v),b.ma-mi);
c.w=max(max(w,b.w),ma-b.mi);
c.ma=max(ma,b.ma);
c.mi=min(mi,b.mi);
return c;
}
}v[M],val;
void build(int x,int a,int b){
if(a==b){v[x].set(::b[a]);return;}
int mid=(a+b)>>1;
build(x<<1,a,mid),build(x<<1|1,mid+1,b);
v[x]=v[x<<1]+v[x<<1|1];
}
void ask(int x,int a,int b,int c,int d){
if(c<=a&&b<=d){
if(!flag)val=v[x];else val=val+v[x];
flag=1;
return;
}
int mid=(a+b)>>1;
}
inline void query(int x,int y){
flag=0;
if(type==1){
ans=val.v;
ans=max(ans,(val.ma+len*x)*2);
ans=max(ans,(all-len-val.mi-len*y)*2);
}else ans=max(val.v,val.w-len*(y-x+1)+all);
printf("%lld.%lld0000\n",ans/2,ans%2*5);
}
int main(){
while(T--){