wocwocwoc我是真的想骂人了,分块不喜欢我,分块不喜欢我!!!!!
疯狂漏打数组,看看下面的sb记录:
绝望!!!!!!!!
代码(mmp):
//By Bibi
/// .-~~~~~~~~~-._ _.-~~~~~~~~~-.
/// __.' ~. .~ `.__
/// .'// \./ \\`.
/// .'// | \\`.
/// .'// .-~"""""""~~~~-._ | _,-~~~~"""""""~-. \\`.
/// .'//.-" `-. | .-' "-.\\`.
/// .'//______.============-.. \ | / ..-============.______\\`.
/// .'______________________________\|/______________________________`.
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define dep(i,a,b) for(int i=a;i>=b;--i)
#define ql sort(d+l[be[L]],d+r[be[L]]+1)
#define qr sort(d+l[be[R]],d+r[be[R]]+1)
using namespace std;
const int MAXN=100010;
int read()
{
int sum=0,flag=1;
char c;
for(;c<'0'||c>'9';c=getchar())if(c=='-') flag=-1;
for(;c>='0'&&c<='9';c=getchar())sum=(sum<<1)+(sum<<3)+c-'0';
return sum*flag;
}
int n;
int num,block,l[MAXN],r[MAXN],c,op,L,R;
int be[MAXN];
int p[MAXN];
int d[MAXN];
int a[MAXN];
void build()
{
block=sqrt(n);
num=n/block;
if(n%block) num++;
rep(i,1,n) be[i]=(i-1)/block+1;
rep(i,1,num)
{
l[i]=(i-1)*block+1;
r[i]=i*block;
}
r[num]=n;
rep(i,1,num) sort(d+l[i],d+r[i]+1);
}
void ask()
{
int ans=-1;
if(be[L]==be[R])
{
rep(i,L,R) if(a[i]+p[be[L]]<c) ans=max(ans,a[i]+p[be[L]]);
}
else
{
rep(i,L,r[be[L]]) if(a[i]+p[be[L]]<c) ans=max(ans,a[i]+p[be[L]]);
rep(i,l[be[R]],R) if(a[i]+p[be[R]]<c) ans=max(ans,a[i]+p[be[R]]);
rep(i,be[L]+1,be[R]-1)
{
int ll=l[i],rr=r[i],mid;
while(ll+1<rr)
{
mid=(ll+rr)>>1;
if(d[mid]+p[i]<c) ll=mid;
else
rr=mid;
}
if(d[rr]+p[i]<c) ans=max(ans,d[rr]+p[i]);
if(d[ll]+p[i]<c) ans=max(ans,d[ll]+p[i]);
}
}
printf("%d\n",ans);
}
void add()
{
if(be[L]==be[R])
{
rep(i,L,R) a[i]+=c;
rep(i,l[be[L]],r[be[L]]) d[i]=a[i];
ql;
}
else
{
rep(i,L,r[be[L]]) a[i]+=c;
rep(i,l[be[L]],r[be[L]]) d[i]=a[i];
ql;
rep(i,l[be[R]],R) a[i]+=c;
rep(i,l[be[R]],r[be[R]]) d[i]=a[i];
qr;
rep(i,be[L]+1,be[R]-1) p[i]+=c;
}
}
void init()
{
n=read();
rep(i,1,n) a[i]=read(),d[i]=a[i];
build();
rep(i,1,n)
{
op=read();
if(op)
{
L=read();R=read();c=read();
ask();
}
else
{
L=read();R=read();c=read();
add();
}
}
}
int main()
{
init();
return 0;
}