https://www.lydsy.com/JudgeOnline/problem.php?id=4695
新博客用来整理,所以乱七八糟的东西我就暂时继续往这边扔了。
闲得淡疼打了个segtreebeats
我数据结构真是太弱了。。。
//Achen#include#define For(i,a,b) for(int i=(a);i<=(b);i++)#define Rep(i,a,b) for(int i=(a);i>=(b);i--)#define Formylove return 0const int N=5e5+7;typedef long long LL; typedef double db;using namespace std;int o,n,m,a[N];template void read(T &x) { char ch=getchar(); x=0; T f=1; while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar(); if(ch=='-') f=-1,ch=getchar(); for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;}#define inf 1e9struct data { int mi,smi,cmi,mx,smx,cmx,cnt,lz; LL sum;}dt[N<<2];data operator +(const data&A,const data&B) { data rs; rs.lz=0; if(A.mi B.mx) { rs.mx=A.mx; rs.cmx=A.cmx; rs.smx=max(A.smx,B.mx); } else if(B.mx>A.mx) { rs.mx=B.mx; rs.cmx=B.cmx; rs.smx=max(B.smx,A.mx); } else { rs.mx=A.mx; rs.cmx=A.cmx+B.cmx; rs.smx=max(A.smx,B.smx); } return rs;}#define lc x<<1#define rc ((x<<1)|1)#define mid ((l+r)>>1)void build(int x,int l,int r) { if(l==r) { dt[x]=(data){a[l],inf,1,a[l],-inf,1,1,0,a[l]}; return; } build(lc,l,mid); build(rc,mid+1,r); dt[x]=dt[lc]+dt[rc];}void add(int x,int v) { dt[x].sum+=(LL)dt[x].cnt*v; dt[x].lz+=v; dt[x].mi+=v; dt[x].mx+=v; if(dt[x].smi!=inf) dt[x].smi+=v; if(dt[x].smx!=-inf) dt[x].smx+=v;}void get_min(int x,int v) { if(dt[x].mx<=v) return; dt[x].sum-=(LL)dt[x].cmx*(dt[x].mx-v); if(dt[x].mi==dt[x].mx) dt[x].mi=v; if(dt[x].smi==dt[x].mx) dt[x].smi=v; dt[x].mx=v; }void get_max(int x,int v) { if(dt[x].mi>=v) return; dt[x].sum+=(LL)dt[x].cmi*(v-dt[x].mi); if(dt[x].mi==dt[x].mx) dt[x].mx=v; if(dt[x].smx==dt[x].mi) dt[x].smx=v; dt[x].mi=v;}void down(int x,int l,int r) { if(dt[x].lz) add(lc,dt[x].lz),add(rc,dt[x].lz); dt[x].lz=0; get_min(lc,dt[x].mx); get_max(lc,dt[x].mi); get_min(rc,dt[x].mx); get_max(rc,dt[x].mi);}void change(int x,int l,int r,int ql,int qr,int v) { if(l>=ql&&r<=qr) { if(o==1) { add(x,v); return; } else if(o==2) { if(dt[x].mi>=v) return; else if(dt[x].smi>v) { get_max(x,v); return; } } else { if(dt[x].mx<=v) return; else if(dt[x].smx mid) change(rc,mid+1,r,ql,qr,v); dt[x]=dt[lc]+dt[rc];}LL Qrs;void qry(int x,int l,int r,int ql,int qr) { if(l>=ql&&r<=qr) { if(o==4) Qrs+=dt[x].sum; else if(o==5) Qrs=max(Qrs,(LL)dt[x].mx); else Qrs=min(Qrs,(LL)dt[x].mi); return ; } down(x,l,r); if(ql<=mid) qry(lc,l,mid,ql,qr); if(qr>mid) qry(rc,mid+1,r,ql,qr);}int main() { //freopen("4695.in","r",stdin); //freopen("4695.out","w",stdout); read(n); For(i,1,n) read(a[i]); build(1,1,n); read(m); For(i,1,m) { read(o); int l,r,v; read(l); read(r); if(o<=3) { read(v); change(1,1,n,l,r,v); } else { Qrs=(o==4?0:(o==5?-inf:inf)); qry(1,1,n,l,r); printf("%lld\n",Qrs); } } Formylove;}
//Achen#include#define For(i,a,b) for(int i=(a);i<=(b);i++)#define Rep(i,a,b) for(int i=(a);i>=(b);i--)#define Formylove return 0const int N=5005;typedef long long LL;typedef double db;using namespace std;int a[N][N];template void read(T &x) { char ch=getchar(); T f=1; x=0; while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar(); if(ch=='-') f=-1,ch=getchar(); for(;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0'; x*=f;}int main() { //freopen("1.in","w",stdout); srand(time(0)); int n=rand()%10+1,m=rand()%10+1; printf("%d\n",n); For(i,1,n) { int x=rand()%10+1; printf("%d ",x); } puts(""); printf("%d\n",m); For(i,1,m) { int o,l,r,v; l=rand()%n+1; r=rand()%n+1; if(l>r) swap(l,r); o=rand()%6+1; v=rand()%10+1; if(o<=3) printf("%d %d %d %d\n",o,l,r,v); else printf("%d %d %d\n",o,l,r); } Formylove;}