xiaobing @ 2024-09-03 15:51:08
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
#define ll long long
#define lll __int128
#define ull unsigned long long
#define veci vector<int>
#define vecl vector<long long>
const int N = 1e6 + 10, inf = 0x7FFFFFFF;
const ll INF = 0x7FFFFFFFFFFFFFFF;
template<typename T>inline void readT(T& x) {
bool f = 1; x = 0; char ch = getchar();
while (ch < '0' || ch>'9') { if (ch == '-') f = !f; ch = getchar(); }
while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
x = (f ? x : -x); return;
}
template<typename T>
inline void writeT(T x) {
if (x < 0) putchar('-'), x = -x;
if (x > 9) writeT(x / 10);
putchar(x % 10 + '0'); return;
}
struct tree {
vecl t, vis1, vis2, e, ls, rs;//1赋值,2加法
ll tot = 0, len, begin = 0;
ll build(ll& x, ll l, ll r) {
if (!x)x = ++tot;
// cout<<x<<" "<<l<<" "<<r<<'\n';
if (l == r)
return t[x] = e[l - 1];
ll mid = (l + r) >> 1;
return t[x] = max(build(ls[x], l, mid), build(rs[x], mid + 1, r));
}
tree(vecl a) {
len = a.size();
e = a;
vecl num(2 * len);
t = vis1 = vis2 = ls = rs = num;
for (auto& n : vis1)
n = INF;
build(begin, 1, len);
}
void push_down(ll x) {
if (vis1[x] != INF) {
vis1[x] += vis2[x];
t[x] = vis1[x];
vis1[ls[x]] = vis1[x];
vis1[rs[x]] = vis1[x];
vis2[ls[x]] = 0;
vis2[rs[x]] = 0;
vis2[x] = 0;
vis1[x] = INF;
}
else {
t[x] += vis2[x];
vis2[ls[x]] += vis2[x];
vis2[rs[x]] += vis2[x];
vis2[x] = 0;
}
return;
}
ll updata1(ll x, ll l, ll r, ll L, ll R, ll k) {
push_down(x);
if (L <= l && r <= R) {
vis1[x] = k;
push_down(x);
return t[x];
}
ll mid = (l + r) >> 1, rt = -INF;
if (mid >= L)rt = max(rt, updata1(ls[x], l, mid, L, R, k));
else push_down(ls[x]), rt = max(rt, t[ls[x]]);
if (mid < R)rt = max(rt, updata1(rs[x], mid + 1, r, L, R, k));
else push_down(rs[x]), rt = max(rt, t[rs[x]]);
return t[x] = rt;
}
ll updata2(ll x, ll l, ll r, ll L, ll R, ll k) {
push_down(x);
if (L <= l && r <= R) {
vis2[x] = k;
push_down(x);
return t[x];
}
ll mid = (l + r) >> 1, rt = -INF;
if (mid >= L)rt = max(rt, updata2(ls[x], l, mid, L, R, k));
else push_down(ls[x]), rt = max(rt, t[ls[x]]);
if (mid < R)rt = max(rt, updata2(rs[x], mid + 1, r, L, R, k));
else push_down(rs[x]), rt = max(rt, t[rs[x]]);
return t[x] = rt;
}
ll query(ll x, ll l, ll r, ll L, ll R) {
push_down(x);
if (L <= l && r <= R)
return t[x];
ll mid = (l + r) >> 1, rt = -INF;
if (mid >= L)rt = max(rt, query(ls[x], l, mid, L, R));
if (mid < R)rt = max(rt, query(rs[x], mid + 1, r, L, R));
return rt;
}
};
int main() {
int n, q;
readT(n); readT(q);
vecl a(n);
for (int i = 0; i < n; i++)
readT(a[i]);
tree tr(a);
while (q--) {
// for(auto e:tr.t)
// cout<<e<<" ";
// cout<<'\n';
int op;
cin >> op;
if (op == 1) {
int l, r, x;
cin >> l >> r >> x;
tr.updata1(1, 1, n, l, r, x);
}
if (op == 2) {
int l, r, x;
cin >> l >> r >> x;
tr.updata2(1, 1, n, l, r, x);
}
if (op == 3) {
int l, r;
cin >> l >> r;
writeT(tr.query(1, 1, n, l, r));
putchar('\n');
}
}
return 0;
}
by XuYueming @ 2024-09-03 16:10:43
@xiaobing 《加了快读快写》
cin >> l >> r >> x;
by xiaobing @ 2024-09-03 16:22:09
@XuYueming 额,没看见,不过改了还是TLE