#include <stdio.h>
#define N 300000
#define N_ (1 << 19) /* N_ = pow2(ceil(Log2(N + 2))) */
int max(int a, int b) { return a > b ? a : b; }
int kk[N_ * 2];
long long ss[N_ * 2];
long long aap[N_ * 2]; int kkp[N_ * 2];
long long aaq[N_ * 2]; int kkq[N_ * 2];
int kk_[N_ * 2];
char tz[N_]; long long lz[N_];
int h_, n_;
void put(int i, int t, long long x) {
if (t == 1) {
ss[i] += x * kk[i], aap[i] += x, aaq[i] += x;
if (i < n_) {
if (tz[i] == 0)
tz[i] = 1;
lz[i] += x;
}
} else {
ss[i] = x * kk[i];
aap[i] = x, kkp[i] = kk[i];
aaq[i] = x, kkq[i] = kk[i];
kk_[i] = kk[i];
if (i < n_)
tz[i] = 2, lz[i] = x;
}
}
void pus(int i) {
if (tz[i])
put(i << 1 | 0, tz[i], lz[i]), put(i << 1 | 1, tz[i], lz[i]), tz[i] = lz[i] = 0;
}
void pul(int i) {
if (!tz[i]) {
int l = i << 1, r = l | 1;
ss[i] = ss[l] + ss[r];
aap[i] = aap[l], kkp[i] = kkp[l] < kk[l] || aap[l] != aap[r] ? kkp[l] : kk[l] + kkp[r];
aaq[i] = aaq[r], kkq[i] = kkq[r] < kk[r] || aaq[l] != aaq[r] ? kkq[r] : kkq[l] + kk[r];
kk_[i] = max(kk_[l], kk_[r]);
if (aaq[l] == aap[r])
kk_[i] = max(kk_[i], kkq[l] + kkp[r]);
}
}
void push(int i) {
int h;
for (h = h_; h > 0; h--)
pus(i >> h);
}
void pull(int i) {
while (i > 1)
pul(i >>= 1);
}
void build(int *aa, int n) {
int i, a;
h_ = 0;
while (1 << h_ <= n + 1)
h_++;
n_ = 1 << h_;
for (i = 0; i <= n; i++) {
a = (i == n ? 0 : aa[i]) - (i == 0 ? 0 : aa[i - 1]);
kk[n_ + i] = 1;
ss[n_ + i] = a;
aap[n_ + i] = a, kkp[n_ + i] = 1;
aaq[n_ + i] = a, kkq[n_ + i] = 1;
kk_[n_ + i] = 1;
}
for (i = n_ - 1; i > 0; i--)
kk[i] = kk[i << 1 | 0] + kk[i << 1 | 1], pul(i);
}
void update(int l, int r, int t, long long x) {
int l_ = l += n_, r_ = r += n_;
push(l_), push(r_);
for ( ; l <= r; l >>= 1, r >>= 1) {
if ((l & 1) == 1)
put(l++, t, x);
if ((r & 1) == 0)
put(r--, t, x);
}
pull(l_), pull(r_);
}
long long query_s(int r) {
int l;
long long s;
push(r += n_);
s = 0;
for (l = 0 + n_; l <= r; l >>= 1, r >>= 1)
if ((r & 1) == 0)
s += ss[r--];
return s;
}
int query_k_(int l, int r) {
long long aq, ap;
int kq, kp, k_;
push(l += n_), push(r += n_);
aq = 0, kq = 0, ap = 0, kp = 0, k_ = 0;
for ( ; l <= r; l >>= 1, r >>= 1) {
if ((l & 1) == 1) {
k_ = max(k_, kk_[l]);
if (aq == aap[l])
k_ = max(k_, kq + kkp[l]);
kq = kkq[l] < kk[l] || aq != aaq[l] ? kkq[l] : kq + kkq[l], aq = aaq[l];
l++;
}
if ((r & 1) == 0) {
k_ = max(kk_[r], k_);
if (aaq[r] == ap)
k_ = max(k_, kkq[r] + kp);
kp = kkp[r] < kk[r] || aap[r] != ap ? kkp[r] : kkp[r] + kp, ap = aap[r];
r--;
}
}
if (aq == ap)
k_ = max(k_, kq + kp);
return k_;
}
int main() {
static int aa[N];
int n, q, i;
scanf("%d%d", &n, &q);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
build(aa, n);
while (q--) {
int t, l, r, a, b;
long long dl, dr;
scanf("%d%d%d", &t, &l, &r), l--, r--;
if (t == 1) {
scanf("%d%d", &b, &a);
update(l, l, 1, b);
if (l < r)
update(l + 1, r, 1, a);
update(r + 1, r + 1, 1, -((long long) a * (r - l) + b));
} else if (t == 2) {
scanf("%d%d", &b, &a);
dl = b - (l == 0 ? 0 : query_s(l - 1));
dr = (r + 1 == n ? 0 : query_s(r + 1)) - ((long long) a * (r - l) + b);
update(l, l, 2, dl);
if (l < r)
update(l + 1, r, 2, a);
update(r + 1, r + 1, 2, dr);
} else
printf("%d\n", l == r ? 1 : query_k_(l + 1, r) + 1);
}
return 0;
}
Compilation message
Progression.c: In function 'main':
Progression.c:139:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
139 | scanf("%d%d", &n, &q);
| ^~~~~~~~~~~~~~~~~~~~~
Progression.c:141:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
141 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
Progression.c:147:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
147 | scanf("%d%d%d", &t, &l, &r), l--, r--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.c:149:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
149 | scanf("%d%d", &b, &a);
| ^~~~~~~~~~~~~~~~~~~~~
Progression.c:155:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
155 | scanf("%d%d", &b, &a);
| ^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2897 ms |
42448 KB |
Output is correct |
2 |
Correct |
151 ms |
3512 KB |
Output is correct |
3 |
Correct |
147 ms |
3548 KB |
Output is correct |
4 |
Correct |
157 ms |
3468 KB |
Output is correct |
5 |
Correct |
167 ms |
3596 KB |
Output is correct |
6 |
Correct |
139 ms |
3640 KB |
Output is correct |
7 |
Correct |
174 ms |
3524 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Execution timed out |
3057 ms |
42476 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
368 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
428 KB |
Output is correct |
9 |
Correct |
2 ms |
392 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
1 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
428 KB |
Output is correct |
14 |
Correct |
1 ms |
432 KB |
Output is correct |
15 |
Correct |
2 ms |
468 KB |
Output is correct |
16 |
Correct |
2 ms |
472 KB |
Output is correct |
17 |
Correct |
4 ms |
480 KB |
Output is correct |
18 |
Correct |
2 ms |
468 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
296 KB |
Output is correct |
21 |
Correct |
2 ms |
304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
197 ms |
40736 KB |
Output is correct |
2 |
Correct |
100 ms |
2940 KB |
Output is correct |
3 |
Correct |
92 ms |
2924 KB |
Output is correct |
4 |
Correct |
79 ms |
3016 KB |
Output is correct |
5 |
Correct |
86 ms |
3156 KB |
Output is correct |
6 |
Correct |
94 ms |
3184 KB |
Output is correct |
7 |
Correct |
88 ms |
3100 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
292 KB |
Output is correct |
11 |
Correct |
257 ms |
39544 KB |
Output is correct |
12 |
Correct |
241 ms |
40828 KB |
Output is correct |
13 |
Correct |
283 ms |
39464 KB |
Output is correct |
14 |
Correct |
251 ms |
39456 KB |
Output is correct |
15 |
Correct |
202 ms |
40740 KB |
Output is correct |
16 |
Correct |
253 ms |
41352 KB |
Output is correct |
17 |
Correct |
248 ms |
41328 KB |
Output is correct |
18 |
Correct |
241 ms |
41360 KB |
Output is correct |
19 |
Correct |
216 ms |
40700 KB |
Output is correct |
20 |
Correct |
225 ms |
40664 KB |
Output is correct |
21 |
Correct |
246 ms |
40772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
583 ms |
43604 KB |
Output is correct |
2 |
Correct |
128 ms |
3596 KB |
Output is correct |
3 |
Correct |
151 ms |
3696 KB |
Output is correct |
4 |
Correct |
132 ms |
3676 KB |
Output is correct |
5 |
Correct |
124 ms |
3700 KB |
Output is correct |
6 |
Correct |
159 ms |
3696 KB |
Output is correct |
7 |
Correct |
139 ms |
3680 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
558 ms |
40312 KB |
Output is correct |
12 |
Correct |
569 ms |
43668 KB |
Output is correct |
13 |
Correct |
525 ms |
40304 KB |
Output is correct |
14 |
Correct |
613 ms |
40312 KB |
Output is correct |
15 |
Correct |
536 ms |
43540 KB |
Output is correct |
16 |
Correct |
579 ms |
43656 KB |
Output is correct |
17 |
Correct |
555 ms |
43640 KB |
Output is correct |
18 |
Correct |
554 ms |
43704 KB |
Output is correct |
19 |
Correct |
488 ms |
43516 KB |
Output is correct |
20 |
Correct |
499 ms |
43508 KB |
Output is correct |
21 |
Correct |
531 ms |
43536 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
197 ms |
40736 KB |
Output is correct |
2 |
Correct |
100 ms |
2940 KB |
Output is correct |
3 |
Correct |
92 ms |
2924 KB |
Output is correct |
4 |
Correct |
79 ms |
3016 KB |
Output is correct |
5 |
Correct |
86 ms |
3156 KB |
Output is correct |
6 |
Correct |
94 ms |
3184 KB |
Output is correct |
7 |
Correct |
88 ms |
3100 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
292 KB |
Output is correct |
11 |
Correct |
257 ms |
39544 KB |
Output is correct |
12 |
Correct |
241 ms |
40828 KB |
Output is correct |
13 |
Correct |
283 ms |
39464 KB |
Output is correct |
14 |
Correct |
251 ms |
39456 KB |
Output is correct |
15 |
Correct |
202 ms |
40740 KB |
Output is correct |
16 |
Correct |
253 ms |
41352 KB |
Output is correct |
17 |
Correct |
248 ms |
41328 KB |
Output is correct |
18 |
Correct |
241 ms |
41360 KB |
Output is correct |
19 |
Correct |
216 ms |
40700 KB |
Output is correct |
20 |
Correct |
225 ms |
40664 KB |
Output is correct |
21 |
Correct |
246 ms |
40772 KB |
Output is correct |
22 |
Correct |
960 ms |
45688 KB |
Output is correct |
23 |
Correct |
128 ms |
3532 KB |
Output is correct |
24 |
Correct |
144 ms |
3572 KB |
Output is correct |
25 |
Correct |
133 ms |
3540 KB |
Output is correct |
26 |
Correct |
174 ms |
3536 KB |
Output is correct |
27 |
Correct |
136 ms |
3536 KB |
Output is correct |
28 |
Correct |
128 ms |
3576 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
300 KB |
Output is correct |
32 |
Correct |
909 ms |
42836 KB |
Output is correct |
33 |
Correct |
922 ms |
45584 KB |
Output is correct |
34 |
Correct |
911 ms |
42948 KB |
Output is correct |
35 |
Correct |
1004 ms |
42952 KB |
Output is correct |
36 |
Correct |
613 ms |
42832 KB |
Output is correct |
37 |
Correct |
618 ms |
42816 KB |
Output is correct |
38 |
Correct |
694 ms |
42808 KB |
Output is correct |
39 |
Correct |
835 ms |
45724 KB |
Output is correct |
40 |
Correct |
919 ms |
45860 KB |
Output is correct |
41 |
Correct |
923 ms |
45852 KB |
Output is correct |
42 |
Correct |
957 ms |
45828 KB |
Output is correct |
43 |
Correct |
858 ms |
45644 KB |
Output is correct |
44 |
Correct |
895 ms |
45776 KB |
Output is correct |
45 |
Correct |
1064 ms |
45704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2897 ms |
42448 KB |
Output is correct |
2 |
Correct |
151 ms |
3512 KB |
Output is correct |
3 |
Correct |
147 ms |
3548 KB |
Output is correct |
4 |
Correct |
157 ms |
3468 KB |
Output is correct |
5 |
Correct |
167 ms |
3596 KB |
Output is correct |
6 |
Correct |
139 ms |
3640 KB |
Output is correct |
7 |
Correct |
174 ms |
3524 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Execution timed out |
3057 ms |
42476 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |