#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5 + 10;
const long long inf = 1e16;
long long a[maxn];
int arr[maxn];
int n;
struct node {
long long sum, lazyadd, lazyass;
long long left, right;
int pre, suf, opt, sz;
} t[maxn * 4], zero;
void addNode(node &p, long long val) {
p.left += val;
p.right += val;
p.sum += val * p.sz;
if(p.lazyass == inf) {
p.lazyadd += val;
} else {
p.lazyass += val;
}
}
void assNode(node &p, long long val) {
p.left = val;
p.right = val;
p.sum = val * p.sz;
p.opt = p.pre = p.suf = p.sz;
p.lazyadd = 0;
p.lazyass = val;
}
void pushdown(int c) {
int l = c << 1;
int r = l + 1;
if(t[c].lazyass == inf) {
addNode(t[l], t[c].lazyadd);
addNode(t[r], t[c].lazyadd);
} else {
assNode(t[l], t[c].lazyass);
assNode(t[r], t[c].lazyass);
}
t[c].lazyass = inf;
t[c].lazyadd = 0;
}
void merge(node &ans, node p, node q) {
ans.sum = p.sum + q.sum;
ans.left = p.left;
ans.right = q.right;
ans.pre = p.pre;
ans.suf = q.suf;
ans.opt = max(p.opt, q.opt);
if(p.pre == p.sz && p.right == q.left) ans.pre += q.pre;
if(q.suf == q.sz && q.left == p.right) ans.suf += p.suf;
if(p.right == q.left) ans.opt = max(ans.opt, p.suf + q.pre);
}
void add(int x, int y, long long val, int c = 1, int b = 1, int e = n) {
if(x <= b && e <= y) {
addNode(t[c], val);
return ;
}
if(y < b || e < x) return ;
pushdown(c);
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
add(x, y, val, l, b, m);
add(x, y, val, r, m + 1, e);
merge(t[c], t[l], t[r]);
}
void assign(int x, int y, long long val, int c = 1, int b = 1, int e = n) {
if(x <= b && e <= y) {
assNode(t[c], val);
return ;
}
if(y < b || e < x) return ;
pushdown(c);
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
assign(x, y, val, l, b, m);
assign(x, y, val, r, m + 1, e);
merge(t[c], t[l], t[r]);
}
long long getValue(int idx, int c = 1, int b = 1, int e = n) {
if(b == e) return t[c].sum;
pushdown(c);
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
if(idx <= m) return getValue(idx, l, b, m);
else return getValue(idx, r, m + 1, e) + t[l].sum;
}
void build(int c = 1, int b = 1, int e = n) {
t[c].sz = e - b + 1;
t[c].lazyass = inf;
t[c].pre = t[c].suf = t[c].opt = t[c].sz;
if(b == e) {
return ;
}
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
build(l, b, m);
build(r, m + 1, e);
}
void patch(int l, int r, long long s, long long d) {
add(l, l, s);
add(l + 1, r, d);
if(r + 1 <= n) {
add(r + 1, r + 1, -(s + (r - l) * d));
}
}
void rewrite(int l, int r, long long s, long long d) {
long long last = getValue(r);
add(l, l, s - getValue(l));
assign(l + 1, r, d);
if(r + 1 <= n) {
add(r + 1, r + 1, last - (s + (r - l) * d));
}
}
node range(int x, int y, int c = 1, int b = 1, int e = n) {
if(x <= b && e <= y) {
return t[c];
}
if(y < b || e < x) return zero;
pushdown(c);
int m = (b + e) >> 1;
int l = c << 1;
int r = l + 1;
node ans;
merge(ans, range(x, y, l, b, m), range(x, y, r, m + 1, e));
return ans;
}
int query(int l, int r) {
if(l == r) return 1;
return range(l + 1, r).opt + 1;
}
int main() {
int m;
scanf("%d %d", &n, &m);
build();
zero.left = -inf; zero.right = inf;
for(int i = 1; i <= n; i++) {
scanf("%d", &arr[i]);
add(i, i, arr[i] - arr[i - 1]);
}
for(int i = 1; i <= m; i++) {
int c, l, r, s, d;
scanf("%d %d %d", &c, &l, &r);
if(c == 1) {
scanf("%d %d", &s, &d);
patch(l, r, s, d);
} else if (c == 2) {
scanf("%d %d", &s, &d);
rewrite(l, r, s, d);
} else {
printf("%d\n", query(l, r));
}
}
return 0;
}
Compilation message
Progression.cpp: In function 'int main()':
Progression.cpp:141:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~~
Progression.cpp:145:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &arr[i]);
~~~~~^~~~~~~~~~~~~~~
Progression.cpp:151:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &c, &l, &r);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Progression.cpp:153:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &s, &d);
~~~~~^~~~~~~~~~~~~~~~~
Progression.cpp:156:12: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &s, &d);
~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
721 ms |
59640 KB |
Output is correct |
2 |
Correct |
210 ms |
760 KB |
Output is correct |
3 |
Correct |
215 ms |
632 KB |
Output is correct |
4 |
Correct |
212 ms |
632 KB |
Output is correct |
5 |
Correct |
206 ms |
760 KB |
Output is correct |
6 |
Correct |
218 ms |
760 KB |
Output is correct |
7 |
Correct |
202 ms |
580 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
694 ms |
59640 KB |
Output is correct |
12 |
Correct |
697 ms |
59572 KB |
Output is correct |
13 |
Correct |
673 ms |
59892 KB |
Output is correct |
14 |
Correct |
695 ms |
60028 KB |
Output is correct |
15 |
Correct |
700 ms |
59896 KB |
Output is correct |
16 |
Correct |
684 ms |
59588 KB |
Output is correct |
17 |
Correct |
714 ms |
59640 KB |
Output is correct |
18 |
Correct |
698 ms |
59608 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
416 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
3 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
384 KB |
Output is correct |
13 |
Correct |
2 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
3 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
736 ms |
59980 KB |
Output is correct |
2 |
Correct |
162 ms |
1016 KB |
Output is correct |
3 |
Correct |
152 ms |
1144 KB |
Output is correct |
4 |
Correct |
131 ms |
888 KB |
Output is correct |
5 |
Correct |
158 ms |
988 KB |
Output is correct |
6 |
Correct |
159 ms |
1016 KB |
Output is correct |
7 |
Correct |
156 ms |
1016 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
721 ms |
59920 KB |
Output is correct |
12 |
Correct |
730 ms |
60280 KB |
Output is correct |
13 |
Correct |
766 ms |
59748 KB |
Output is correct |
14 |
Correct |
741 ms |
59752 KB |
Output is correct |
15 |
Correct |
721 ms |
60152 KB |
Output is correct |
16 |
Correct |
717 ms |
60412 KB |
Output is correct |
17 |
Correct |
830 ms |
60280 KB |
Output is correct |
18 |
Correct |
976 ms |
60536 KB |
Output is correct |
19 |
Correct |
717 ms |
59640 KB |
Output is correct |
20 |
Correct |
655 ms |
59896 KB |
Output is correct |
21 |
Correct |
692 ms |
59880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1071 ms |
59512 KB |
Output is correct |
2 |
Correct |
341 ms |
504 KB |
Output is correct |
3 |
Correct |
255 ms |
632 KB |
Output is correct |
4 |
Correct |
245 ms |
504 KB |
Output is correct |
5 |
Correct |
250 ms |
484 KB |
Output is correct |
6 |
Correct |
258 ms |
504 KB |
Output is correct |
7 |
Correct |
251 ms |
632 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
256 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1099 ms |
59256 KB |
Output is correct |
12 |
Correct |
1085 ms |
59384 KB |
Output is correct |
13 |
Correct |
1085 ms |
59384 KB |
Output is correct |
14 |
Correct |
1079 ms |
59264 KB |
Output is correct |
15 |
Correct |
1051 ms |
59280 KB |
Output is correct |
16 |
Correct |
1163 ms |
59256 KB |
Output is correct |
17 |
Correct |
1155 ms |
59256 KB |
Output is correct |
18 |
Correct |
1083 ms |
59384 KB |
Output is correct |
19 |
Correct |
1071 ms |
59372 KB |
Output is correct |
20 |
Correct |
1057 ms |
59640 KB |
Output is correct |
21 |
Correct |
1033 ms |
59180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
736 ms |
59980 KB |
Output is correct |
2 |
Correct |
162 ms |
1016 KB |
Output is correct |
3 |
Correct |
152 ms |
1144 KB |
Output is correct |
4 |
Correct |
131 ms |
888 KB |
Output is correct |
5 |
Correct |
158 ms |
988 KB |
Output is correct |
6 |
Correct |
159 ms |
1016 KB |
Output is correct |
7 |
Correct |
156 ms |
1016 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
721 ms |
59920 KB |
Output is correct |
12 |
Correct |
730 ms |
60280 KB |
Output is correct |
13 |
Correct |
766 ms |
59748 KB |
Output is correct |
14 |
Correct |
741 ms |
59752 KB |
Output is correct |
15 |
Correct |
721 ms |
60152 KB |
Output is correct |
16 |
Correct |
717 ms |
60412 KB |
Output is correct |
17 |
Correct |
830 ms |
60280 KB |
Output is correct |
18 |
Correct |
976 ms |
60536 KB |
Output is correct |
19 |
Correct |
717 ms |
59640 KB |
Output is correct |
20 |
Correct |
655 ms |
59896 KB |
Output is correct |
21 |
Correct |
692 ms |
59880 KB |
Output is correct |
22 |
Correct |
1224 ms |
59416 KB |
Output is correct |
23 |
Correct |
271 ms |
760 KB |
Output is correct |
24 |
Correct |
217 ms |
632 KB |
Output is correct |
25 |
Correct |
221 ms |
888 KB |
Output is correct |
26 |
Correct |
231 ms |
760 KB |
Output is correct |
27 |
Correct |
230 ms |
632 KB |
Output is correct |
28 |
Correct |
222 ms |
668 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
256 KB |
Output is correct |
31 |
Correct |
1 ms |
384 KB |
Output is correct |
32 |
Correct |
1434 ms |
59424 KB |
Output is correct |
33 |
Correct |
1133 ms |
59416 KB |
Output is correct |
34 |
Correct |
1250 ms |
59464 KB |
Output is correct |
35 |
Correct |
1289 ms |
59384 KB |
Output is correct |
36 |
Correct |
1246 ms |
59676 KB |
Output is correct |
37 |
Correct |
1041 ms |
59640 KB |
Output is correct |
38 |
Correct |
1071 ms |
59640 KB |
Output is correct |
39 |
Correct |
1282 ms |
59308 KB |
Output is correct |
40 |
Correct |
1192 ms |
59384 KB |
Output is correct |
41 |
Correct |
1215 ms |
59464 KB |
Output is correct |
42 |
Correct |
1203 ms |
59388 KB |
Output is correct |
43 |
Correct |
1169 ms |
59336 KB |
Output is correct |
44 |
Correct |
1143 ms |
59384 KB |
Output is correct |
45 |
Correct |
1103 ms |
59320 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
721 ms |
59640 KB |
Output is correct |
2 |
Correct |
210 ms |
760 KB |
Output is correct |
3 |
Correct |
215 ms |
632 KB |
Output is correct |
4 |
Correct |
212 ms |
632 KB |
Output is correct |
5 |
Correct |
206 ms |
760 KB |
Output is correct |
6 |
Correct |
218 ms |
760 KB |
Output is correct |
7 |
Correct |
202 ms |
580 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
256 KB |
Output is correct |
11 |
Correct |
694 ms |
59640 KB |
Output is correct |
12 |
Correct |
697 ms |
59572 KB |
Output is correct |
13 |
Correct |
673 ms |
59892 KB |
Output is correct |
14 |
Correct |
695 ms |
60028 KB |
Output is correct |
15 |
Correct |
700 ms |
59896 KB |
Output is correct |
16 |
Correct |
684 ms |
59588 KB |
Output is correct |
17 |
Correct |
714 ms |
59640 KB |
Output is correct |
18 |
Correct |
698 ms |
59608 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
416 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
384 KB |
Output is correct |
24 |
Correct |
1 ms |
256 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
3 ms |
384 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
3 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
3 ms |
384 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
4 ms |
384 KB |
Output is correct |
34 |
Correct |
3 ms |
384 KB |
Output is correct |
35 |
Correct |
3 ms |
384 KB |
Output is correct |
36 |
Correct |
3 ms |
384 KB |
Output is correct |
37 |
Correct |
1 ms |
384 KB |
Output is correct |
38 |
Correct |
2 ms |
384 KB |
Output is correct |
39 |
Correct |
2 ms |
256 KB |
Output is correct |
40 |
Correct |
736 ms |
59980 KB |
Output is correct |
41 |
Correct |
162 ms |
1016 KB |
Output is correct |
42 |
Correct |
152 ms |
1144 KB |
Output is correct |
43 |
Correct |
131 ms |
888 KB |
Output is correct |
44 |
Correct |
158 ms |
988 KB |
Output is correct |
45 |
Correct |
159 ms |
1016 KB |
Output is correct |
46 |
Correct |
156 ms |
1016 KB |
Output is correct |
47 |
Correct |
1 ms |
384 KB |
Output is correct |
48 |
Correct |
1 ms |
384 KB |
Output is correct |
49 |
Correct |
1 ms |
384 KB |
Output is correct |
50 |
Correct |
721 ms |
59920 KB |
Output is correct |
51 |
Correct |
730 ms |
60280 KB |
Output is correct |
52 |
Correct |
766 ms |
59748 KB |
Output is correct |
53 |
Correct |
741 ms |
59752 KB |
Output is correct |
54 |
Correct |
721 ms |
60152 KB |
Output is correct |
55 |
Correct |
717 ms |
60412 KB |
Output is correct |
56 |
Correct |
830 ms |
60280 KB |
Output is correct |
57 |
Correct |
976 ms |
60536 KB |
Output is correct |
58 |
Correct |
717 ms |
59640 KB |
Output is correct |
59 |
Correct |
655 ms |
59896 KB |
Output is correct |
60 |
Correct |
692 ms |
59880 KB |
Output is correct |
61 |
Correct |
1071 ms |
59512 KB |
Output is correct |
62 |
Correct |
341 ms |
504 KB |
Output is correct |
63 |
Correct |
255 ms |
632 KB |
Output is correct |
64 |
Correct |
245 ms |
504 KB |
Output is correct |
65 |
Correct |
250 ms |
484 KB |
Output is correct |
66 |
Correct |
258 ms |
504 KB |
Output is correct |
67 |
Correct |
251 ms |
632 KB |
Output is correct |
68 |
Correct |
1 ms |
384 KB |
Output is correct |
69 |
Correct |
1 ms |
256 KB |
Output is correct |
70 |
Correct |
1 ms |
384 KB |
Output is correct |
71 |
Correct |
1099 ms |
59256 KB |
Output is correct |
72 |
Correct |
1085 ms |
59384 KB |
Output is correct |
73 |
Correct |
1085 ms |
59384 KB |
Output is correct |
74 |
Correct |
1079 ms |
59264 KB |
Output is correct |
75 |
Correct |
1051 ms |
59280 KB |
Output is correct |
76 |
Correct |
1163 ms |
59256 KB |
Output is correct |
77 |
Correct |
1155 ms |
59256 KB |
Output is correct |
78 |
Correct |
1083 ms |
59384 KB |
Output is correct |
79 |
Correct |
1071 ms |
59372 KB |
Output is correct |
80 |
Correct |
1057 ms |
59640 KB |
Output is correct |
81 |
Correct |
1033 ms |
59180 KB |
Output is correct |
82 |
Correct |
1224 ms |
59416 KB |
Output is correct |
83 |
Correct |
271 ms |
760 KB |
Output is correct |
84 |
Correct |
217 ms |
632 KB |
Output is correct |
85 |
Correct |
221 ms |
888 KB |
Output is correct |
86 |
Correct |
231 ms |
760 KB |
Output is correct |
87 |
Correct |
230 ms |
632 KB |
Output is correct |
88 |
Correct |
222 ms |
668 KB |
Output is correct |
89 |
Correct |
2 ms |
384 KB |
Output is correct |
90 |
Correct |
1 ms |
256 KB |
Output is correct |
91 |
Correct |
1 ms |
384 KB |
Output is correct |
92 |
Correct |
1434 ms |
59424 KB |
Output is correct |
93 |
Correct |
1133 ms |
59416 KB |
Output is correct |
94 |
Correct |
1250 ms |
59464 KB |
Output is correct |
95 |
Correct |
1289 ms |
59384 KB |
Output is correct |
96 |
Correct |
1246 ms |
59676 KB |
Output is correct |
97 |
Correct |
1041 ms |
59640 KB |
Output is correct |
98 |
Correct |
1071 ms |
59640 KB |
Output is correct |
99 |
Correct |
1282 ms |
59308 KB |
Output is correct |
100 |
Correct |
1192 ms |
59384 KB |
Output is correct |
101 |
Correct |
1215 ms |
59464 KB |
Output is correct |
102 |
Correct |
1203 ms |
59388 KB |
Output is correct |
103 |
Correct |
1169 ms |
59336 KB |
Output is correct |
104 |
Correct |
1143 ms |
59384 KB |
Output is correct |
105 |
Correct |
1103 ms |
59320 KB |
Output is correct |
106 |
Correct |
1366 ms |
59608 KB |
Output is correct |
107 |
Correct |
284 ms |
760 KB |
Output is correct |
108 |
Correct |
272 ms |
508 KB |
Output is correct |
109 |
Correct |
281 ms |
504 KB |
Output is correct |
110 |
Correct |
1 ms |
384 KB |
Output is correct |
111 |
Correct |
2 ms |
384 KB |
Output is correct |
112 |
Correct |
1 ms |
384 KB |
Output is correct |
113 |
Correct |
1155 ms |
59372 KB |
Output is correct |
114 |
Correct |
1152 ms |
59472 KB |
Output is correct |
115 |
Correct |
1210 ms |
59512 KB |
Output is correct |
116 |
Correct |
1085 ms |
59416 KB |
Output is correct |
117 |
Correct |
1457 ms |
59768 KB |
Output is correct |
118 |
Correct |
1068 ms |
59512 KB |
Output is correct |
119 |
Correct |
1084 ms |
59384 KB |
Output is correct |
120 |
Correct |
731 ms |
60536 KB |
Output is correct |
121 |
Correct |
750 ms |
60664 KB |
Output is correct |
122 |
Correct |
776 ms |
60408 KB |
Output is correct |
123 |
Correct |
701 ms |
59708 KB |
Output is correct |
124 |
Correct |
701 ms |
59768 KB |
Output is correct |
125 |
Correct |
652 ms |
59640 KB |
Output is correct |
126 |
Correct |
1427 ms |
59512 KB |
Output is correct |
127 |
Correct |
1307 ms |
59568 KB |
Output is correct |
128 |
Correct |
1449 ms |
59596 KB |
Output is correct |
129 |
Correct |
1439 ms |
59512 KB |
Output is correct |
130 |
Correct |
1144 ms |
60280 KB |
Output is correct |
131 |
Correct |
1149 ms |
60280 KB |
Output is correct |
132 |
Correct |
1050 ms |
60408 KB |
Output is correct |
133 |
Correct |
1428 ms |
59640 KB |
Output is correct |
134 |
Correct |
1339 ms |
59912 KB |
Output is correct |
135 |
Correct |
1398 ms |
59512 KB |
Output is correct |
136 |
Correct |
276 ms |
632 KB |
Output is correct |
137 |
Correct |
274 ms |
504 KB |
Output is correct |
138 |
Correct |
277 ms |
632 KB |
Output is correct |