存个板子
Codeforces Round #576 (Div. 2) D. Welfare State
#include<bits/stdc++.h>
using namespace std;
#define ls rt<<1
#define rs (rt<<1)+1
#define PI acos(-1)
#define eps 1e-8
#define ll long long
#define fuck(x) cout<<#x<<" "<<x<<endl;
typedef pair<int,int> pii;
const int inf=2e9;
const int maxn=2e5+10;
int d[4][2]={1,0,-1,0,0,1,0,-1};
//int lowbit(int x){return x&-x;}
//void add(int x,int v){while(x<=n)bit[x]+=v,x+=lowbit(x);}
//int sum(int x){int ans=0;while(x>=1) ans+=bit[x],x-=lowbit(x);return ans;}
inline ll read() {
ll s = 0,w = 1;
char ch = getchar();
while(!isdigit(ch)) {
if(ch == '-') w = -1;
ch = getchar();
}
while(isdigit(ch))
s = s * 10 + ch - '0',ch = getchar();
return s * w;
}
inline void write(ll x) {
if(x < 0)
putchar('-'), x = -x;
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
int minn[maxn<<2],sminn[maxn<<2],lazy[maxn<<2],a[maxn];
void pushup(int rt){
if(minn[ls]!=minn[rs]){
minn[rt]=min(minn[ls],minn[rs]);
sminn[rt]=min(max(minn[ls],minn[rs]),min(sminn[ls],sminn[rs]));
}
else
{
minn[rt]=minn[ls];
sminn[rt]=min(sminn[ls],sminn[rs]);
}
}
void pushdown(int rt){
if(lazy[rt]!=-1){
if(minn[ls]<lazy[rt]&&sminn[ls]>lazy[rt]){
minn[ls]=lazy[rt];
lazy[ls]=lazy[rt];
}
if(minn[rs]<lazy[rt]&&sminn[rs]>lazy[rt]){
minn[rs]=lazy[rt];
lazy[rs]=lazy[rt];
}
lazy[rt]=-1;
}
}
void build(int rt,int L,int R){
lazy[rt]=-1;
if(L==R){
minn[rt]=a[L];
sminn[rt]=inf;
return ;
}
int mid=(L+R)>>1;
build(ls,L,mid);
build(rs,mid+1,R);
pushup(rt);
}
void update1(int rt,int L,int R,int x){
if(minn[rt]>=x) return;
if(sminn[rt]>x){
minn[rt]=x;
lazy[rt]=x;
return ;
}
pushdown(rt);
int mid=(L+R)>>1;
update1(ls,L,mid,x);
update1(rs,mid+1,R,x);
pushup(rt);
}
void update2(int rt,int L,int R,int x,int y){
if(L==R){
minn[rt]=y;
return ;
}
pushdown(rt);
int mid=(L+R)>>1;
if(x<=mid)
update2(ls,L,mid,x,y);
else
update2(rs,mid+1,R,x,y);
pushup(rt);
}
int query(int rt,int L,int R,int x){
if(L==R)
return minn[rt];
int mid=(L+R)>>1;
pushdown(rt);
if(x<=mid)
return query(ls,L,mid,x);
else
return query(rs,mid+1,R,x);
}
int main(){
int n,q;
n=read();
for(int i=1;i<=n;i++)
a[i]=read();
build(1,1,n);
q=read();
while(q--){
int opt,x,y;
opt=read();
if(opt==1){
x=read();y=read();
update2(1,1,n,x,y);
}
else{
x=read();
update1(1,1,n,x);
}
}
for(int i=1;i<=n;i++){
write(query(1,1,n,i));
printf(" ");
}
puts("");
return 0;
}
hdu5306 Gorgeous Sequenc
#include<bits/stdc++.h>
using namespace std;
#define ls rt<<1
#define rs (rt<<1)+1
#define PI acos(-1)
#define eps 1e-8
#define ll long long
#define fuck(x) cout<<#x<<" "<<x<<endl;
typedef pair<int,int> pii;
const int inf=2e9;
const int maxn=1e6+10;
int d[4][2]={1,0,-1,0,0,1,0,-1};
//int lowbit(int x){return x&-x;}
//void add(int x,int v){while(x<=n)bit[x]+=v,x+=lowbit(x);}
//int sum(int x){int ans=0;while(x>=1) ans+=bit[x],x-=lowbit(x);return ans;}
inline ll read() {
ll s = 0,w = 1;
char ch = getchar();
while(!isdigit(ch)) {
if(ch == '-') w = -1;
ch = getchar();
}
while(isdigit(ch))
s = s * 10 + ch - '0',ch = getchar();
return s * w;
}
inline void write(ll x) {
if(x < 0)
putchar('-'), x = -x;
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
int a[maxn],lazy[maxn<<2],maxx[maxn<<2],smax[maxn<<2],mnum[maxn<<2];
ll sum[maxn<<2];
void pushup(int rt){
if(maxx[ls]!=maxx[rs]){
maxx[rt]=max(maxx[ls],maxx[rs]);
mnum[rt]=(maxx[rt]==maxx[ls])?mnum[ls]:mnum[rs];
smax[rt]=max(max(smax[ls],smax[rs]),min(maxx[ls],maxx[rs]));
}
else
{
maxx[rt]=maxx[ls];
mnum[rt]=mnum[ls]+mnum[rs];
smax[rt]=max(smax[ls],smax[rs]);
}
sum[rt]=sum[ls]+sum[rs];
}
void pushdown(int rt){
if(lazy[rt]!=-1){
if(maxx[ls]>lazy[rt]&&lazy[rt]>smax[ls]){
sum[ls]-=1LL*mnum[ls]*(maxx[ls]-lazy[rt]);
maxx[ls] = lazy[rt];
lazy[ls] = lazy[rt];
}
if(maxx[rs]>lazy[rt]&&lazy[rt]>smax[rs]){
sum[rs]-=1LL*mnum[rs]*(maxx[rs]-lazy[rt]);
maxx[rs]=lazy[rt];
lazy[rs]=lazy[rt];
}
lazy[rt]=-1;
}
}
void build(int rt,int L,int R){
lazy[rt]=-1;
if(L==R){
sum[rt]=maxx[rt]=a[L];
smax[rt]=-1;
mnum[rt]=1;
return ;
}
int mid=(L+R)>>1;
build(ls,L,mid);
build(rs,mid+1,R);
pushup(rt);
}
void update(int rt,int L,int R,int l,int r,int v){
if(l<=L&&r>=R){
if(v>=maxx[rt]) return ;
if(v>smax[rt]){
sum[rt]-=1LL*mnum[rt]*(maxx[rt]-v);
maxx[rt]=v;
lazy[rt]=v;
return ;
}
}
pushdown(rt);
int mid=(L+R)>>1;
if(r<=mid)
update(ls,L,mid,l,r,v);
else
if(l>mid)
update(rs,mid+1,R,l,r,v);
else{
update(ls,L,mid,l,r,v);
update(rs,mid+1,R,l,r,v);
}
pushup(rt);
}
int querym(int rt,int L,int R,int l,int r){
if(l<=L&&r>=R)
return maxx[rt];
pushdown(rt);
int mid=(L+R)>>1;
if(r<=mid)
return querym(ls,L,mid,l,r);
else
if(l>mid)
return querym(rs,mid+1,R,l,r);
else
return max(querym(ls,L,mid,l,r),querym(rs,mid+1,R,l,r));
}
ll querys(int rt,int L,int R,int l,int r){
if(l<=L&&r>=R)
return sum[rt];
pushdown(rt);
int mid=(L+R)>>1;
if(r<=mid)
return querys(ls,L,mid,l,r);
else
if(l>mid)
return querys(rs,mid+1,R,l,r);
else
return querys(ls,L,mid,l,r)+querys(rs,mid+1,R,l,r);
}
int main(){
int t,n,m;
t=read();
while(t--){
n=read();m=read();
for(int i=1;i<=n;i++)
a[i]=read();
build(1,1,n);
//fuck(sum[7]);
// fuck(maxx[7]);
while(m--){
int op,x,y,t;
op=read();
if(op==0){
x=read();y=read();t=read();
update(1,1,n,x,y,t);
}
else
if(op==1){
x=read();y=read();
write(querym(1,1,n,x,y));
puts("");
}
else{
x=read();y=read();
write(querys(1,1,n,x,y));
puts("");
}
// int index;
// index=read();
// fuck(sum[index]);
// fuck(maxx[index]);
}
}
return 0;
}