#include <stdio.h>
#define int long long
#define lid (id << 1)
#define rid (id << 1 | 1)
#define Blue_Archive return 0
#define con putchar_unlocked(' ')
#define ent putchar_unlocked('\n')
const int N = 1e6 + 3;
const int INF = 0x3f3f3f3f;
const int mod = 19650827;
int n;
int m;
int a[N];
struct miku
{
int mx,cmx,cnt,sum,laz;
}tr[N << 2];
inline int read()
{
int k = 0,f = 1;
char c = getchar_unlocked();
while(c < '0' || c > '9')
{
if(c == '-') f = -1;
c = getchar_unlocked();
}
while(c >= '0' && c <= '9') k = (k << 3) + (k << 1) + c - '0',c = getchar_unlocked();
return k * f;
}
inline void write(int x)
{
if(x < 0) putchar_unlocked('-'),x = -x;
if(x > 9) write(x / 10);
putchar_unlocked(x % 10 + '0');
}
inline int max(int x,int y){return x > y ? x : y;}
inline int min(int x,int y){return x < y ? x : y;}
inline void pushup(int id)
{
tr[id].sum = tr[lid].sum + tr[rid].sum;
if(tr[lid].mx > tr[rid].mx)
{
tr[id].mx = tr[lid].mx,tr[id].cnt = tr[lid].cnt;
tr[id].cmx = max(tr[lid].cmx,tr[rid].mx);
}
else if(tr[lid].mx < tr[rid].mx)
{
tr[id].mx = tr[rid].mx,tr[id].cnt = tr[rid].cnt;
tr[id].cmx = max(tr[rid].cmx,tr[lid].mx);
}
else
{
tr[id].mx = tr[lid].mx,tr[id].cnt = tr[lid].cnt + tr[rid].cnt;
tr[id].cmx = max(tr[lid].cmx,tr[rid].cmx);
}
}
inline void update(int id,int val)
{
if(tr[id].mx <= val) return;
tr[id].sum -= (tr[id].mx - val) * tr[id].cnt;
tr[id].mx = val;
tr[id].laz = val;
}
inline void pushdown(int id) // 推平上界
{
if(!tr[id].laz) return;
update(lid,tr[id].laz);
update(rid,tr[id].laz);
tr[id].laz = 0;
}
inline void build(int id,int l,int r)
{
if(l == r)
{
tr[id].mx = tr[id].sum = a[l];
tr[id].cnt = 1;
tr[id].cmx = -INF;
tr[id].laz = 0;
return;
}
int mid = (l + r) >> 1;
build(lid,l,mid);
build(rid,mid + 1,r);
pushup(id);
}
inline int query_max(int id,int l,int r,int L,int R)
{
if(L <= l && r <= R) return tr[id].mx;
pushdown(id);
int mid = (l + r) >> 1,res = -INF;
if(L <= mid) res = max(res,query_max(lid,l,mid,L,R));
if(R > mid) res = max(res,query_max(rid,mid + 1,r,L,R));
return res;
}
inline int query_sum(int id,int l,int r,int L,int R)
{
if(L <= l && r <= R) return tr[id].sum;
pushdown(id);
int mid = (l + r) >> 1,res = 0;
if(L <= mid) res += query_sum(lid,l,mid,L,R);
if(R > mid) res += query_sum(rid,mid + 1,r,L,R);
return res;
}
inline void change(int id,int l,int r,int L,int R,int val)
{
if(val >= tr[id].mx) return;
if(L <= l && r <= R)
{
if(tr[id].cmx < val && val < tr[id].mx)
{
update(id,val);
return;
}
}
pushdown(id);
int mid = (l + r) >> 1;
if(L <= mid) change(lid,l,mid,L,R,val);
if(R > mid) change(rid,mid + 1,r,L,R,val);
pushup(id);
}
signed main()
{
// freopen("data.in","r",stdin);freopen("data.out","w",stdout);
n = read();
m = read();
for(int i = 1;i <= n;i ++) a[i] = read();
build(1,1,n);
for(int i = 1,op,l,r,x;i <= m;i ++)
{
op = read();
if(op == 1)
{
l = read();
r = read();
x = read();
change(1,1,n,l,r,x);
}
if(op == 2)
{
l = read();
r = read();
write(query_max(1,1,n,l,r));ent;
}
if(op == 3)
{
l = read();
r = read();
write(query_sum(1,1,n,l,r));ent;
}
}
Blue_Archive;
}to DZC
这是 2025年10月12日 存档的第 1 版,不是当前版本。查看当前版本