/*
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC target("avx2,fma,bmi,bmi2,sse4.2,popcnt,lzcnt")
*/
#include <bits/stdc++.h>
#define taskname ""
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define int long long
#define i64 long long
#define pb push_back
#define ff first
#define ss second
#define isz(x) (int)x.size()
using namespace std;
const int mxN = 3e5 + 5;
const int mod = 1e9 + 7;
const i64 oo = 1e18;
struct SegmentTree {
struct node {
i64 val = 0;
int same = 0, len = 0;
pair<int, int> pfx, sfx;
i64 lz_mul = 1, lz_add = 0;
node() {}
node(int val) : val(val), same(1), len(1), pfx({val, 1}), sfx({val, 1}) {}
node operator + (const node &rhs) {
node res;
res.val = val + rhs.val;
res.len = len + rhs.len;
res.same = max(same, rhs.same);
if (sfx.ff == rhs.pfx.ff) res.same = max(res.same, sfx.ss + rhs.pfx.ss);
res.pfx = pfx, res.sfx = rhs.sfx;
if (pfx.ss == len and pfx.ff == rhs.pfx.ff) res.pfx = {pfx.ff, pfx.ss + rhs.pfx.ss};
if (rhs.sfx.ss == rhs.len and sfx.ff == rhs.sfx.ff) res.sfx = {rhs.sfx.ff, rhs.sfx.ss + sfx.ss};
// cout << *this << endl << rhs << endl << res << endl << endl;
return res;
}
friend ostream & operator << (ostream &out, node o) {
return out << o.pfx.ff << " " << o.pfx.ss << " " << o.sfx.ff << " " << o.sfx.ss << " " << o.same;
}
};
int n;
vector<node> data;
SegmentTree(int n, vector<int> &diff) : n(n), data(4 * n + 10) {
auto build = [&](auto build, int l, int r, int idx) -> void {
if (l == r) {
data[idx] = node(diff[l]);
return;
}
int mid = (l + r) >> 1;
build(build, l, mid, idx << 1);
build(build, mid + 1, r, idx << 1 | 1);
data[idx] = data[idx << 1] + data[idx << 1 | 1];
};
build(build, 1, n, 1);
};
void apply(int idx, i64 mul, i64 add) {
if (mul == 0) {
data[idx].val = add * data[idx].len;
data[idx].same = data[idx].len;
data[idx].pfx = data[idx].sfx = {add, data[idx].len};
data[idx].lz_mul = mul, data[idx].lz_add = add;
}
else {
data[idx].val += add * data[idx].len;
data[idx].pfx.ff += add, data[idx].sfx.ff += add;
data[idx].lz_add += add;
}
}
void down(int idx) {
apply(idx << 1, data[idx].lz_mul, data[idx].lz_add);
apply(idx << 1 | 1, data[idx].lz_mul, data[idx].lz_add);
data[idx].lz_add = 0, data[idx].lz_mul = 1;
}
void update(int l, int r, int idx, int u, int v, i64 mul, i64 add) {
if (u <= l && r <= v) {
apply(idx, mul, add);
return;
}
down(idx);
int mid = (l + r) >> 1;
if (u <= mid) update(l, mid, idx << 1, u, v, mul, add);
if (mid + 1 <= v) update(mid + 1, r, idx << 1 | 1, u, v, mul, add);
data[idx] = data[idx << 1] + data[idx << 1 | 1];
}
void update(int u, int v, i64 mul, i64 add) {
update(1, n, 1, u, v, mul, add);
}
node get(int l, int r, int idx, int u, int v) {
if (u <= l && r <= v) return data[idx];
down(idx);
int mid = (l + r) >> 1;
if (v <= mid) return get(l, mid, idx << 1, u, v);
if (mid + 1 <= u) return get(mid + 1, r, idx << 1 | 1, u, v);
return get(l, mid, idx << 1, u, v) + get(mid + 1, r, idx << 1 | 1, u, v);
}
node get(int u, int v) {
return get(1, n, 1, u, v);
}
};
int n, q;
int a[mxN];
vector<int> diff;
void solve() {
cin >> n >> q;
diff.resize(n + 1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
diff[i] = a[i] - a[i - 1];
}
SegmentTree st(n, diff);
// cout << st.data[1].same << endl;
while (q--) {
int tp;
cin >> tp;
if (tp == 1) {
int l, r, s, c;
cin >> l >> r >> s >> c;
st.update(l, l, 1, s);
if (l < r) st.update(l + 1, r, 1, c);
if (r + 1 <= n) st.update(r + 1, r + 1, 1, -(1ll * c * (r - l) + s));
}
else if (tp == 2) {
int l, r, s, c;
cin >> l >> r >> s >> c;
i64 cl = st.get(1, l).val;
i64 cr = st.get(1, r).val;
st.update(l, l, 1, s - cl);
if (r + 1 <= n) st.update(r + 1, r + 1, 1, s + (r - l) * c - cr);
if (l < r) st.update(l + 1, r, 0, c);
}
else {
int l, r;
cin >> l >> r;
if (l == r) cout << 1 << "\n";
else cout << st.get(l + 1, r).same + 1 << "\n";
}
}
// for (int i = 1; i <= n; ++i)
// cout << st.get(i, i).val << " \n"[i == n];
}
signed main() {
#ifndef CDuongg
if(fopen(taskname".inp", "r"))
assert(freopen(taskname".inp", "r", stdin)), assert(freopen(taskname".out", "w", stdout));
#else
freopen("bai3.inp", "r", stdin);
freopen("bai3.out", "w", stdout);
auto start = chrono::high_resolution_clock::now();
#endif
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1; //cin >> t;
while(t--) solve();
#ifdef CDuongg
auto end = chrono::high_resolution_clock::now();
cout << "\n"; for(int i = 1; i <= 100; ++i) cout << '=';
cout << "\nExecution time: " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
cout << "Check array size pls sir" << endl;
#endif
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
271 ms |
90316 KB |
Output is correct |
2 |
Correct |
95 ms |
596 KB |
Output is correct |
3 |
Correct |
97 ms |
596 KB |
Output is correct |
4 |
Correct |
97 ms |
536 KB |
Output is correct |
5 |
Correct |
106 ms |
1100 KB |
Output is correct |
6 |
Correct |
100 ms |
604 KB |
Output is correct |
7 |
Correct |
96 ms |
596 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
285 ms |
90464 KB |
Output is correct |
12 |
Correct |
267 ms |
90196 KB |
Output is correct |
13 |
Correct |
269 ms |
90452 KB |
Output is correct |
14 |
Correct |
297 ms |
90544 KB |
Output is correct |
15 |
Correct |
275 ms |
90448 KB |
Output is correct |
16 |
Correct |
272 ms |
90228 KB |
Output is correct |
17 |
Correct |
266 ms |
90088 KB |
Output is correct |
18 |
Correct |
286 ms |
90260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
604 KB |
Output is correct |
2 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
90492 KB |
Output is correct |
2 |
Correct |
66 ms |
904 KB |
Output is correct |
3 |
Correct |
63 ms |
848 KB |
Output is correct |
4 |
Correct |
58 ms |
848 KB |
Output is correct |
5 |
Correct |
69 ms |
1104 KB |
Output is correct |
6 |
Correct |
68 ms |
1028 KB |
Output is correct |
7 |
Correct |
69 ms |
960 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
236 ms |
90284 KB |
Output is correct |
12 |
Correct |
196 ms |
90704 KB |
Output is correct |
13 |
Correct |
242 ms |
90276 KB |
Output is correct |
14 |
Correct |
233 ms |
90292 KB |
Output is correct |
15 |
Correct |
202 ms |
90452 KB |
Output is correct |
16 |
Correct |
240 ms |
91220 KB |
Output is correct |
17 |
Correct |
244 ms |
90960 KB |
Output is correct |
18 |
Correct |
244 ms |
91132 KB |
Output is correct |
19 |
Correct |
211 ms |
90384 KB |
Output is correct |
20 |
Correct |
212 ms |
90196 KB |
Output is correct |
21 |
Correct |
221 ms |
90272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
407 ms |
89936 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
90492 KB |
Output is correct |
2 |
Correct |
66 ms |
904 KB |
Output is correct |
3 |
Correct |
63 ms |
848 KB |
Output is correct |
4 |
Correct |
58 ms |
848 KB |
Output is correct |
5 |
Correct |
69 ms |
1104 KB |
Output is correct |
6 |
Correct |
68 ms |
1028 KB |
Output is correct |
7 |
Correct |
69 ms |
960 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
236 ms |
90284 KB |
Output is correct |
12 |
Correct |
196 ms |
90704 KB |
Output is correct |
13 |
Correct |
242 ms |
90276 KB |
Output is correct |
14 |
Correct |
233 ms |
90292 KB |
Output is correct |
15 |
Correct |
202 ms |
90452 KB |
Output is correct |
16 |
Correct |
240 ms |
91220 KB |
Output is correct |
17 |
Correct |
244 ms |
90960 KB |
Output is correct |
18 |
Correct |
244 ms |
91132 KB |
Output is correct |
19 |
Correct |
211 ms |
90384 KB |
Output is correct |
20 |
Correct |
212 ms |
90196 KB |
Output is correct |
21 |
Correct |
221 ms |
90272 KB |
Output is correct |
22 |
Correct |
473 ms |
89900 KB |
Output is correct |
23 |
Correct |
96 ms |
544 KB |
Output is correct |
24 |
Correct |
102 ms |
660 KB |
Output is correct |
25 |
Correct |
106 ms |
604 KB |
Output is correct |
26 |
Correct |
101 ms |
648 KB |
Output is correct |
27 |
Correct |
98 ms |
544 KB |
Output is correct |
28 |
Correct |
98 ms |
520 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
494 ms |
89952 KB |
Output is correct |
33 |
Correct |
476 ms |
90460 KB |
Output is correct |
34 |
Correct |
469 ms |
90060 KB |
Output is correct |
35 |
Correct |
462 ms |
90288 KB |
Output is correct |
36 |
Correct |
391 ms |
90564 KB |
Output is correct |
37 |
Correct |
378 ms |
90248 KB |
Output is correct |
38 |
Correct |
396 ms |
90296 KB |
Output is correct |
39 |
Correct |
460 ms |
89952 KB |
Output is correct |
40 |
Correct |
489 ms |
90108 KB |
Output is correct |
41 |
Correct |
480 ms |
90344 KB |
Output is correct |
42 |
Correct |
480 ms |
89944 KB |
Output is correct |
43 |
Correct |
472 ms |
89952 KB |
Output is correct |
44 |
Correct |
452 ms |
89976 KB |
Output is correct |
45 |
Correct |
454 ms |
90200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
271 ms |
90316 KB |
Output is correct |
2 |
Correct |
95 ms |
596 KB |
Output is correct |
3 |
Correct |
97 ms |
596 KB |
Output is correct |
4 |
Correct |
97 ms |
536 KB |
Output is correct |
5 |
Correct |
106 ms |
1100 KB |
Output is correct |
6 |
Correct |
100 ms |
604 KB |
Output is correct |
7 |
Correct |
96 ms |
596 KB |
Output is correct |
8 |
Correct |
0 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
285 ms |
90464 KB |
Output is correct |
12 |
Correct |
267 ms |
90196 KB |
Output is correct |
13 |
Correct |
269 ms |
90452 KB |
Output is correct |
14 |
Correct |
297 ms |
90544 KB |
Output is correct |
15 |
Correct |
275 ms |
90448 KB |
Output is correct |
16 |
Correct |
272 ms |
90228 KB |
Output is correct |
17 |
Correct |
266 ms |
90088 KB |
Output is correct |
18 |
Correct |
286 ms |
90260 KB |
Output is correct |
19 |
Correct |
1 ms |
604 KB |
Output is correct |
20 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |