#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
using namespace std;
const int nmax = 500001;
struct node{
ll x, y;
ll pr, suf;
ll sum, lazy, lazy1;
bool good = false;
ll ans = 0;
node(){
x = y = 0;
pr = suf = 0;
sum = lazy1 = 0;
lazy = -9e18;
ans = 0;
}
}t[4 * nmax];
node merg(node a, node b){
node c;
c.sum = a.sum + b.sum;
c.pr = a.pr;
c.suf = b.suf;
c.x = a.x;
c.y = b.y;
if(a.good){
if(b.x == a.x) c.pr += b.pr;
}
if(b.good){
if(a.y == b.y) c.suf += a.suf;
}
if(a.good && b.good && a.x == b.x)
c.good = true;
c.ans = max(a.ans, b.ans);
if(a.y == b.x){
c.ans = max(c.ans, a.suf + b.pr);
}
return c;
}
//lazy minichebis lazy1 damatebis
void push1(int v, int l, int r){
if(t[v].lazy == -9e18)return;
t[v * 2].lazy = t[v].lazy;
t[v * 2].lazy1 = 0;
t[v * 2 + 1].lazy = t[v].lazy;
t[v * 2 + 1].lazy1 = 0;
int m = (l + r) /2;
t[v * 2].sum = (ll)(m - l + 1) * t[v].lazy;
t[v * 2 + 1].sum = (ll)(r - m) * t[v].lazy;
t[v * 2].good = true;
t[v * 2].pr = t[v * 2].suf = m - l + 1;
t[v * 2].x = t[v * 2].y = t[v].lazy;
t[v * 2 + 1].good = true;
t[v * 2 + 1].pr = t[v * 2 + 1].suf = r - m;
t[v * 2 + 1].x = t[v * 2 + 1].y = t[v].lazy;
t[v].lazy = -9e18;
t[v].lazy1 = 0;
}
void push2(int v, int l, int r){
if(t[v].lazy1 == 0) return;
ll m = (l + r) / 2;
if(t[v * 2].lazy != -9e18) t[v * 2].lazy += t[v].lazy1;
if(t[v * 2 + 1].lazy != -9e18) t[v * 2 + 1].lazy += t[v].lazy1;
t[v * 2].lazy1 += t[v].lazy1;
t[v * 2 + 1].lazy1 += t[v].lazy1;
t[v * 2].x += t[v].lazy1;
t[v * 2].y += t[v].lazy1;
t[v * 2 + 1].x += t[v].lazy1;
t[v * 2 + 1].y += t[v].lazy1;
t[v * 2].sum += t[v].lazy1 * (ll)(m - l + 1);
t[v * 2 + 1].sum += t[v].lazy1 * (ll)(r - m);
t[v].lazy1 = 0;
}
void updran1(int v, int l, int r, int st, int fin, ll val){//minicheba intervalze
if(l > fin || r < st)
return;
if(l >= st && r <= fin){
t[v].sum = val * (ll)(r - l + 1);
t[v].x = t[v].y = val;
t[v].pr = t[v].suf = r - l + 1;
t[v].lazy = val;
t[v].lazy1 = 0;
t[v].good = true;
t[v].ans = r - l + 1;
return;
}
push1(v, l, r);
push2(v, l, r);
int m = (l + r) / 2;
updran1(2 * v, l, m, st, fin, val);
updran1(2 * v + 1, m + 1, r, st, fin, val);
t[v] = merg(t[2 * v], t[2 * v + 1]);
}
void updran2(int v, int l, int r, int st, int fin, ll val){
if(l > fin || r < st)
return;
if(l >= st && r <= fin){
t[v].sum += val * (ll)(r - l + 1);
t[v].x += val;
t[v].y += val;
if(t[v].lazy != -9e18) t[v].lazy += val;
t[v].lazy1 += val;
return;
}
push1(v, l, r);
push2(v, l, r);
int m = (l + r) / 2;
updran2(2 * v, l, m, st, fin, val);
updran2(2 * v + 1, m + 1, r, st, fin, val);
t[v] = merg(t[2 * v], t[2 * v + 1]);
}
ll getsum(int v, int l, int r, int st, int fin){
if(l > fin || r < st)
return 0;
if(l >= st && r <= fin)
return t[v].sum;
push1(v, l, r);
push2(v, l, r);
int m = (l + r) / 2;
return getsum(2 * v, l, m,st, fin) + getsum(2 * v + 1, m + 1, r, st, fin);
}
node getans(int v, int l, int r, int tl, int tr){
if(l == tl && r == tr){
return t[v];
}
push1(v, l, r);
push2(v, l, r);
int m = (l + r) / 2;
if(tl > m)
return getans(2 * v + 1, m + 1, r, tl, tr);
if(tr <= m)
return getans(2 * v, l, m, tl, tr);
return merg(getans(2 * v, l, m, tl, m), getans(2 * v + 1, m + 1, r, m + 1, tr));
}
int32_t main(){
ios_base::sync_with_stdio(false); cin.tie(0);
int n, q; cin >> n >> q;
ll a[n + 1];
for(int i = 1; i<= n; ++i){
cin >> a[i];
}
for(int i = n; i >= 2; i--){
updran1(1, 1, n, i - 1, i - 1, a[i] - a[i - 1]);
}
while(q--){
int t; cin >> t;
if(t == 3){
int l, r; cin >> l >> r;
if(l == r) cout << 1 << "\n";
else
cout << getans(1, 1, n, l, r - 1).ans + 1 << "\n";
}
if(t == 1){
ll l, r, s, c; cin >> l >> r >> s >> c;
if(l > 1){
updran2(1, 1, n, l - 1, l - 1, s);
}
else a[1] += s;
ll val = s + c * (r - l);
if(r != n)updran2(1, 1, n, r, r, -val);
updran2(1,1, n, l, r - 1, c);
}
if(t == 2){
ll l, r, s, c; cin >> l >> r >> s >> c;
ll y = getsum(1, 1, n, 1, r) + a[1];
if(l > 1){
ll x = getsum(1, 1, n, 1, l - 2) + a[1];
updran1(1, 1, n, l - 1, l - 1, s - x);
}
if(l == 1){
a[1] = s;
}
updran1(1, 1, n, l, r - 1, c);
if(r < n){
ll x = y;
updran1(1, 1, n, r, r, x - s - c * (r - l));
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
539 ms |
151980 KB |
Output is correct |
2 |
Correct |
164 ms |
144432 KB |
Output is correct |
3 |
Correct |
171 ms |
144468 KB |
Output is correct |
4 |
Correct |
160 ms |
144412 KB |
Output is correct |
5 |
Correct |
162 ms |
144568 KB |
Output is correct |
6 |
Correct |
190 ms |
144468 KB |
Output is correct |
7 |
Correct |
158 ms |
144324 KB |
Output is correct |
8 |
Correct |
53 ms |
141192 KB |
Output is correct |
9 |
Correct |
54 ms |
141132 KB |
Output is correct |
10 |
Correct |
56 ms |
141112 KB |
Output is correct |
11 |
Correct |
498 ms |
151856 KB |
Output is correct |
12 |
Correct |
512 ms |
151780 KB |
Output is correct |
13 |
Correct |
488 ms |
152168 KB |
Output is correct |
14 |
Correct |
497 ms |
152116 KB |
Output is correct |
15 |
Correct |
497 ms |
152116 KB |
Output is correct |
16 |
Correct |
507 ms |
151704 KB |
Output is correct |
17 |
Correct |
493 ms |
151724 KB |
Output is correct |
18 |
Correct |
483 ms |
151792 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
141212 KB |
Output is correct |
2 |
Incorrect |
56 ms |
141116 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
467 ms |
150684 KB |
Output is correct |
2 |
Correct |
133 ms |
143880 KB |
Output is correct |
3 |
Correct |
132 ms |
143980 KB |
Output is correct |
4 |
Correct |
134 ms |
143880 KB |
Output is correct |
5 |
Correct |
145 ms |
143956 KB |
Output is correct |
6 |
Correct |
165 ms |
143944 KB |
Output is correct |
7 |
Correct |
141 ms |
144080 KB |
Output is correct |
8 |
Correct |
56 ms |
141120 KB |
Output is correct |
9 |
Correct |
57 ms |
141100 KB |
Output is correct |
10 |
Correct |
57 ms |
141172 KB |
Output is correct |
11 |
Correct |
497 ms |
149304 KB |
Output is correct |
12 |
Correct |
493 ms |
150716 KB |
Output is correct |
13 |
Correct |
491 ms |
149172 KB |
Output is correct |
14 |
Correct |
464 ms |
149292 KB |
Output is correct |
15 |
Correct |
461 ms |
150568 KB |
Output is correct |
16 |
Correct |
466 ms |
151232 KB |
Output is correct |
17 |
Correct |
509 ms |
151096 KB |
Output is correct |
18 |
Correct |
466 ms |
151212 KB |
Output is correct |
19 |
Correct |
416 ms |
150460 KB |
Output is correct |
20 |
Correct |
441 ms |
150568 KB |
Output is correct |
21 |
Correct |
507 ms |
150468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
959 ms |
150980 KB |
Output is correct |
2 |
Correct |
226 ms |
144432 KB |
Output is correct |
3 |
Correct |
227 ms |
144568 KB |
Output is correct |
4 |
Correct |
234 ms |
144536 KB |
Output is correct |
5 |
Correct |
254 ms |
144516 KB |
Output is correct |
6 |
Correct |
226 ms |
144552 KB |
Output is correct |
7 |
Correct |
230 ms |
144468 KB |
Output is correct |
8 |
Correct |
55 ms |
141184 KB |
Output is correct |
9 |
Correct |
57 ms |
141216 KB |
Output is correct |
10 |
Correct |
56 ms |
141116 KB |
Output is correct |
11 |
Correct |
876 ms |
150068 KB |
Output is correct |
12 |
Correct |
922 ms |
153296 KB |
Output is correct |
13 |
Correct |
897 ms |
150172 KB |
Output is correct |
14 |
Correct |
901 ms |
150140 KB |
Output is correct |
15 |
Correct |
904 ms |
153300 KB |
Output is correct |
16 |
Correct |
1010 ms |
153492 KB |
Output is correct |
17 |
Correct |
966 ms |
153432 KB |
Output is correct |
18 |
Correct |
971 ms |
153588 KB |
Output is correct |
19 |
Correct |
1004 ms |
153288 KB |
Output is correct |
20 |
Correct |
947 ms |
153444 KB |
Output is correct |
21 |
Correct |
882 ms |
153480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
467 ms |
150684 KB |
Output is correct |
2 |
Correct |
133 ms |
143880 KB |
Output is correct |
3 |
Correct |
132 ms |
143980 KB |
Output is correct |
4 |
Correct |
134 ms |
143880 KB |
Output is correct |
5 |
Correct |
145 ms |
143956 KB |
Output is correct |
6 |
Correct |
165 ms |
143944 KB |
Output is correct |
7 |
Correct |
141 ms |
144080 KB |
Output is correct |
8 |
Correct |
56 ms |
141120 KB |
Output is correct |
9 |
Correct |
57 ms |
141100 KB |
Output is correct |
10 |
Correct |
57 ms |
141172 KB |
Output is correct |
11 |
Correct |
497 ms |
149304 KB |
Output is correct |
12 |
Correct |
493 ms |
150716 KB |
Output is correct |
13 |
Correct |
491 ms |
149172 KB |
Output is correct |
14 |
Correct |
464 ms |
149292 KB |
Output is correct |
15 |
Correct |
461 ms |
150568 KB |
Output is correct |
16 |
Correct |
466 ms |
151232 KB |
Output is correct |
17 |
Correct |
509 ms |
151096 KB |
Output is correct |
18 |
Correct |
466 ms |
151212 KB |
Output is correct |
19 |
Correct |
416 ms |
150460 KB |
Output is correct |
20 |
Correct |
441 ms |
150568 KB |
Output is correct |
21 |
Correct |
507 ms |
150468 KB |
Output is correct |
22 |
Correct |
991 ms |
151076 KB |
Output is correct |
23 |
Correct |
212 ms |
144376 KB |
Output is correct |
24 |
Correct |
215 ms |
144532 KB |
Output is correct |
25 |
Correct |
217 ms |
144332 KB |
Output is correct |
26 |
Correct |
220 ms |
144392 KB |
Output is correct |
27 |
Correct |
225 ms |
144416 KB |
Output is correct |
28 |
Correct |
228 ms |
144428 KB |
Output is correct |
29 |
Correct |
59 ms |
141156 KB |
Output is correct |
30 |
Correct |
62 ms |
141184 KB |
Output is correct |
31 |
Correct |
60 ms |
141220 KB |
Output is correct |
32 |
Correct |
987 ms |
150068 KB |
Output is correct |
33 |
Correct |
1025 ms |
150924 KB |
Output is correct |
34 |
Correct |
1012 ms |
150092 KB |
Output is correct |
35 |
Correct |
1053 ms |
150100 KB |
Output is correct |
36 |
Correct |
827 ms |
150024 KB |
Output is correct |
37 |
Correct |
847 ms |
150040 KB |
Output is correct |
38 |
Correct |
836 ms |
150012 KB |
Output is correct |
39 |
Correct |
1012 ms |
150860 KB |
Output is correct |
40 |
Correct |
1085 ms |
150564 KB |
Output is correct |
41 |
Correct |
987 ms |
150544 KB |
Output is correct |
42 |
Correct |
1024 ms |
150516 KB |
Output is correct |
43 |
Correct |
1018 ms |
150312 KB |
Output is correct |
44 |
Correct |
984 ms |
150332 KB |
Output is correct |
45 |
Correct |
995 ms |
150136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
539 ms |
151980 KB |
Output is correct |
2 |
Correct |
164 ms |
144432 KB |
Output is correct |
3 |
Correct |
171 ms |
144468 KB |
Output is correct |
4 |
Correct |
160 ms |
144412 KB |
Output is correct |
5 |
Correct |
162 ms |
144568 KB |
Output is correct |
6 |
Correct |
190 ms |
144468 KB |
Output is correct |
7 |
Correct |
158 ms |
144324 KB |
Output is correct |
8 |
Correct |
53 ms |
141192 KB |
Output is correct |
9 |
Correct |
54 ms |
141132 KB |
Output is correct |
10 |
Correct |
56 ms |
141112 KB |
Output is correct |
11 |
Correct |
498 ms |
151856 KB |
Output is correct |
12 |
Correct |
512 ms |
151780 KB |
Output is correct |
13 |
Correct |
488 ms |
152168 KB |
Output is correct |
14 |
Correct |
497 ms |
152116 KB |
Output is correct |
15 |
Correct |
497 ms |
152116 KB |
Output is correct |
16 |
Correct |
507 ms |
151704 KB |
Output is correct |
17 |
Correct |
493 ms |
151724 KB |
Output is correct |
18 |
Correct |
483 ms |
151792 KB |
Output is correct |
19 |
Correct |
55 ms |
141212 KB |
Output is correct |
20 |
Incorrect |
56 ms |
141116 KB |
Output isn't correct |
21 |
Halted |
0 ms |
0 KB |
- |