#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define sp <<" "<<
#define endl "\n"
struct segtree {
int l, r;
segtree *left, *right;
};
void solve() {
ll n, q; cin >> n >> q;
ll sync = 0;
n += sync;
vector<ll> a(n), d1, d2;
for (ll i = sync; i < n; i++) cin >> a[i];
auto derive = [&](vector<ll> &a) -> vector<ll> {
vector<ll> res(n);
for (ll i = 1; i < n; i++) {
res[i] = a[i] - a[i-1];
}
return res;
};
auto print = [&](vector<ll> &a) -> void {
for (auto &x : a) {
cerr << x << " ";
} cerr << endl;
};
auto enact = [&]() -> void {
d1 = derive(a);
d2 = derive(d1);
};
auto debug = [&]() -> void {
print(a), print(d1), print(d2);
cerr << endl;
};
enact();
// debug();
ll type, l, r, s, c;
while (q--) {
cin >> type;
if (type == 1) {
cin >> l >> r >> s >> c; l--, r--;
l += sync, r += sync;
for (ll i = l; i <= r; i++) {
a[i] += s + (i - l) * c;
}
enact();
// debug();
} else
if (type == 2) {
cin >> l >> r >> s >> c; l--, r--;
l += sync, r += sync;
for (ll i = l; i <= r; i++) {
a[i] = s + (i - l) * c;
}
enact();
// debug();
} else
if (type == 3) {
cin >> l >> r; l--, r--;
l += sync, r += sync;
ll sz = (r - l + 1);
ll mx = 0, cnt = 0;
for (ll i = l+2; i <= min(n-1, r+1); i++) {
if (d2[i] == 0) {
cnt++;
mx = max(mx, cnt);
} else {
cnt = 0;
}
}
mx = max(mx, cnt);
cout << min(sz, mx + 2) << endl;
}
}
}
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(false);
int t = 1;
// cin >> t;
while (t--)
solve();
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |