#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int) x.size())
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x, y) cerr << #x << " is " << x << ", " << #y << " is " << y << endl;
#define show3(x, y, z) cerr << #x << " is " << x << ", " << #y << " is " << y << ", " << #z << " is " << z << endl;
typedef long long lint;
typedef pair<lint, lint> ii;
struct thing{
lint leftval, rightval, leftcnt, rightcnt, best, full;
};
inline thing single(int u){
return {u,u,1,1,1,1};
}
inline thing merge(thing L, thing R){
thing res;
if(L.full and R.full and L.rightval == R.leftval){
return {L.leftval, R.rightval, L.leftcnt+R.leftcnt, L.rightcnt+R.rightcnt, L.best+R.best, 1};
}
res.leftval = L.leftval, res.rightval = R.rightval;
res.leftcnt = L.leftcnt, res.rightcnt = R.rightcnt;
res.best = max(L.best, R.best);
res.full = 0;
if(L.rightval == R.leftval){
res.best = max(res.best, L.rightcnt + R.leftcnt);
if(L.full) res.leftcnt += R.leftcnt;
else if(R.full) res.rightcnt += L.rightcnt;
res.best = max(res.best, res.leftcnt);
res.best = max(res.best, res.rightcnt);
}
return res;
}
lint arr[300005];
struct node{
int s, e, m;
thing val;
lint add = 0;
node *l, *r;
node(int S, int E){
s = S, e = E, m = (s+e)/2;
if(s == e) val = single(arr[s]);
else{
l = new node(s,m);
r = new node(m+1,e);
val = merge(l->val, r->val);
}
}
void applyadd(lint A){
val.leftval += A;
val.rightval += A;
add += A;
}
void push(){
if(add != 0 and s != e){
l->applyadd(add);
r->applyadd(add);
add = 0;
}
}
thing query(int S, int E){
push();
if(s == S and E == e) return val;
else if(E <= m) return l->query(S,E);
else if(S >= m+1) return r->query(S,E);
else return merge(l->query(S,m), r->query(m+1,E));
}
void updateadd(int S, int E, lint A){
push();
if(s == S and E == e){
applyadd(A);
}
else{
if(E <= m) l->updateadd(S,E,A);
else if(S >= m+1) r->updateadd(S,E,A);
else l->updateadd(S,m,A), r->updateadd(m+1,E,A);
val = merge(l->val, r->val);
}
}
} *root;
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n, Q; cin >> n >> Q;
lint x; cin >> x;
for(int i = 2;i <= n;i++){
lint y; cin >> y;
arr[i-1] = y-x;
x = y;
}
if(n != 1) root = new node(1,n-1);
while(Q--){
lint t, l, r; cin >> t >> l >> r;
if(t == 3){
if(l == r) cout << "1\n";
else cout << root->query(l,r-1).best+1 << '\n';
}
else{
if(n == 1) continue;
lint a, b; cin >> a >> b;
if(t == 1){
if(l != r) root->updateadd(l,r-1,b);
if(l != 1) root->updateadd(l-1,l-1,a);
if(r != n) root->updateadd(r,r,-((r-l)*b+a));
}
}
//for(int i = 1;i <= n-1;i++) cout << root->query(i,i).leftval << " "; cout << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
196 ms |
59400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
347 ms |
60024 KB |
Output is correct |
2 |
Correct |
96 ms |
964 KB |
Output is correct |
3 |
Correct |
95 ms |
908 KB |
Output is correct |
4 |
Correct |
83 ms |
848 KB |
Output is correct |
5 |
Correct |
94 ms |
960 KB |
Output is correct |
6 |
Correct |
93 ms |
956 KB |
Output is correct |
7 |
Correct |
94 ms |
952 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
419 ms |
59716 KB |
Output is correct |
12 |
Correct |
381 ms |
60132 KB |
Output is correct |
13 |
Correct |
403 ms |
59716 KB |
Output is correct |
14 |
Correct |
397 ms |
59800 KB |
Output is correct |
15 |
Correct |
331 ms |
59908 KB |
Output is correct |
16 |
Correct |
421 ms |
60336 KB |
Output is correct |
17 |
Correct |
401 ms |
60356 KB |
Output is correct |
18 |
Correct |
409 ms |
60440 KB |
Output is correct |
19 |
Correct |
356 ms |
59668 KB |
Output is correct |
20 |
Correct |
345 ms |
59808 KB |
Output is correct |
21 |
Correct |
341 ms |
59596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
493 ms |
59212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
347 ms |
60024 KB |
Output is correct |
2 |
Correct |
96 ms |
964 KB |
Output is correct |
3 |
Correct |
95 ms |
908 KB |
Output is correct |
4 |
Correct |
83 ms |
848 KB |
Output is correct |
5 |
Correct |
94 ms |
960 KB |
Output is correct |
6 |
Correct |
93 ms |
956 KB |
Output is correct |
7 |
Correct |
94 ms |
952 KB |
Output is correct |
8 |
Correct |
1 ms |
204 KB |
Output is correct |
9 |
Correct |
1 ms |
204 KB |
Output is correct |
10 |
Correct |
1 ms |
204 KB |
Output is correct |
11 |
Correct |
419 ms |
59716 KB |
Output is correct |
12 |
Correct |
381 ms |
60132 KB |
Output is correct |
13 |
Correct |
403 ms |
59716 KB |
Output is correct |
14 |
Correct |
397 ms |
59800 KB |
Output is correct |
15 |
Correct |
331 ms |
59908 KB |
Output is correct |
16 |
Correct |
421 ms |
60336 KB |
Output is correct |
17 |
Correct |
401 ms |
60356 KB |
Output is correct |
18 |
Correct |
409 ms |
60440 KB |
Output is correct |
19 |
Correct |
356 ms |
59668 KB |
Output is correct |
20 |
Correct |
345 ms |
59808 KB |
Output is correct |
21 |
Correct |
341 ms |
59596 KB |
Output is correct |
22 |
Correct |
954 ms |
59368 KB |
Output is correct |
23 |
Correct |
144 ms |
596 KB |
Output is correct |
24 |
Correct |
141 ms |
556 KB |
Output is correct |
25 |
Correct |
141 ms |
604 KB |
Output is correct |
26 |
Correct |
148 ms |
600 KB |
Output is correct |
27 |
Correct |
145 ms |
580 KB |
Output is correct |
28 |
Correct |
146 ms |
652 KB |
Output is correct |
29 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
196 ms |
59400 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |