这次不敢发题解了因为文字表达能力不行。 就把代码发这里吧,如果这次还算是暴力那我接着改awa
#include<bits/stdc++.h>
#define ll p*2
#define rr p*2+1
using namespace std;
const int N=2e6+10;
struct node{
int l,r;
long long s,ls,rs,ms;//s,ls,rs,ms
int x,t,c;//x,t,c
int lc,rc,mc;//lc,rc,mc
int tg;//tg
};
node tree[N<<2];
long long a[N];
int op,l,r;
long long tms,trs;
int k;
long long int read(){
int x=0,y=1;
char ch=getchar();
while(ch<'0'||ch>'9'){
if(ch=='-') y=-1;
ch=getchar();
}
while(ch>='0'&&ch<='9'){
x=(x<<1)+(x<<3)+ch-'0';
ch=getchar();
}
return x*y;
}
void init(int p,int a){
tree[p].s=tree[p].x=a;
tree[p].c=1;
if (a<=0) tree[p].ls=tree[p].rs=tree[p].ms=tree[p].lc=tree[p].rc=tree[p].mc=tree[p].t=0;
else {
tree[p].ls=tree[p].rs=tree[p].ms=a;tree[p].lc=tree[p].rc=tree[p].mc=1;tree[p].t=1e9;
}
return ;
}
void update(int p,int k){
tree[p].tg=k;
swap(k,tree[p].x);
k=tree[p].x-k;
tree[p].s+=1ll*k*tree[p].c;
tree[p].ls+=1ll*k*tree[p].lc;
tree[p].rs+=1ll*k*tree[p].rc;
tree[p].ms+=1ll*k*tree[p].mc;
}
void push_up(int p){
long long c1,c2,s1,s2;
tree[p].x=min(tree[ll].x,tree[rr].x);
tree[p].s=tree[ll].s+tree[rr].s;
bool fl=(tree[ll].x==tree[p].x);
bool fr=(tree[rr].x==tree[p].x);
// if(tree[ll].x==tree[rr].x){
// tree[p].c=tree[ll].c+tree[rr].c;
// tree[p].t=min(tree[ll].t,tree[rr].t);
// }
// if(tree[ll].x>tree[rr].x){
// tree[p].c=tree[rr].c;
// tree[p].t=min(tree[ll].x,tree[rr].t);
// }
// if(tree[ll].x<tree[rr].x){
// tree[p].c=tree[ll].c;
// tree[p].t=min(tree[ll].t,tree[rr].x);
// }
tree[p].c=fl*tree[ll].c+fr*tree[rr].c;
tree[p].t=min(min(tree[ll].t,tree[rr].t),min(fl? tree[ll].t : tree[ll].x-1,fr? tree[rr].t : tree[rr].x-1));
c1=fl*tree[ll].lc;c2=fr*tree[rr].lc+fl*tree[ll].c;
s1=tree[ll].ls;s2=tree[rr].ls+tree[ll].s;
if(s2>s1){
tree[p].ls=s2;
tree[p].lc=c2;
}
else{
tree[p].ls=s1;
tree[p].lc=c1;
if(c2>c1) tree[p].t=min(1ll*tree[p].t,1ll*(tree[p].x+(s1-s2)/(c2-c1)));
}
c1=fr*tree[rr].rc;c2=fl*tree[ll].rc+fr*tree[rr].c;
s1=tree[rr].rs;s2=tree[ll].rs+tree[rr].s;
if(s2>s1){
tree[p].rs=s2;
tree[p].rc=c2;
}
else{
tree[p].rs=s1;
tree[p].rc=c1;
if(c2>c1) tree[p].t=min(1ll*tree[p].t,1ll*(tree[p].x+(s1-s2)/(c2-c1)));
}
if(tree[ll].rs+tree[rr].ls>max(tree[ll].ms,tree[rr].ms)){
tree[p].ms=tree[ll].rs+tree[rr].ls;
tree[p].mc=fl*tree[ll].rc+fr*tree[rr].lc;
}
else if(tree[ll].ms>tree[rr].ms){
tree[p].ms=tree[ll].ms;
tree[p].mc=fl*tree[ll].mc;
}
else{
tree[p].ms=tree[rr].ms;
tree[p].mc=fr*tree[rr].mc;
}
}
void build(int p,int l,int r){
tree[p].l=l;
tree[p].r=r;
tree[p].tg=1e9;
if(l==r){
init(p,a[l]);
return;
}
int mid=(l+r)/2;
build(ll,l,mid);
build(rr,mid+1,r);
push_up(p);
}
void spread(int p){
if(tree[p].tg!=1e9){
if(tree[p].tg>tree[ll].x){
update(ll,tree[p].tg);
}
if(tree[p].tg>tree[rr].x){
update(rr,tree[p].tg);
}
tree[p].tg=1e9;
}
}
void change_min(int p){
if(tree[p].x>=k) return;
if(tree[p].l>=l&&tree[p].r<=r&&k<=tree[p].t){
update(p,k);
return;
}
if(tree[p].l==tree[p].r){
init(p,k);
return;
}
spread(p);
int mid=(tree[p].l+tree[p].r)/2;
if(l<=mid) change_min(ll);
if(mid+1<=r) change_min(rr);
push_up(p);
}
void qry(int u){
if (l<=tree[u].l&&tree[u].r<=r){
tms=max(max(tms,tree[u].ms),trs+tree[u].ls);
trs=max(trs+tree[u].s,tree[u].rs);
return ;
}
int mid=(tree[u].l+tree[u].r)>>1;
spread(u);
if (l<=mid) qry(u<<1);
if (mid+1<=r) qry(u<<1|1);
}
int n,q;
int main(){
n=read(),q=read();
for(int i=1;i<=n;i++){
a[i]=read();
}
build(1,1,n);
for(int i=1;i<=q;i++){
op=read(),l=read(),r=read();
if(op==0){
k=read();
change_min(1);
}
if(op==1){
tms=trs=0;
qry(1);
//if(tms<0) cout<<0<<"\n";
cout<<tms<<"\n";
}
}
return 0;
}