답안 #834698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
834698 2023-08-22T17:19:04 Z rainboy Progression (NOI20_progression) C
100 / 100
751 ms 43464 KB
#include <stdio.h>

#define N	300000
#define N_	(1 << 19)	/* N_ = pow2(ceil(log2(N))) */

int max(int a, int b) { return a > b ? a : b; }

int h_, n_;

char tt[N_ * 2]; long long aa[N_ * 2], bb[N_ * 2];

void put(int i, int t, long long a, long long b) {
	if (t == 1) {
		if (tt[i] == 0)
			tt[i] = 1;
		aa[i] += a, bb[i] += b;
	} else
		tt[i] = 2, aa[i] = a, bb[i] = b;
}

void pus(int i) {
	if (tt[i]) {
		put(i << 1 | 0, tt[i], aa[i], bb[i]), put(i << 1 | 1, tt[i], aa[i], bb[i]), tt[i] = aa[i] = bb[i] = 0;
	}
}

void push(int i) {
	int h;

	for (h = h_; h > 0; h--)
		pus(i >> h);
}

int kk[N_ * 2], pp[N_ * 2], qq[N_ * 2], mx[N_ * 2]; char lz_[N_];

void put_(int i) {
	pp[i] = qq[i] = mx[i] = kk[i];
	if (i < n_)
		lz_[i] = 1;
}

void pus_(int i) {
	if (lz_[i])
		put_(i << 1 | 0), put_(i << 1 | 1), lz_[i] = 0;
}

void pul_(int i) {
	if (!lz_[i]) {
		int l = i << 1, r = l | 1;

		pp[i] = pp[l] < kk[l] ? pp[l] : kk[l] + pp[r];
		qq[i] = qq[r] < kk[r] ? qq[r] : qq[l] + kk[r];
		mx[i] = max(max(mx[l], mx[r]), qq[l] + pp[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(long long *xx, int n) {
	int i;

	h_ = 0;
	while (1 << h_ < n)
		h_++;
	n_ = 1 << h_;
	for (i = 0; i < n_; i++) {
		tt[n_ + i] = 2, aa[n_ + i] = 0, bb[n_ + i] = i < n ? xx[i] : 0;
		kk[n_ + i] = 1;
		pp[n_ + i] = qq[n_ + i] = mx[n_ + i] = i + 2 < n && xx[i + 2] - xx[i + 1] * 2 + xx[i] == 0 ? 1 : 0;
	}
	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 a, long long b) {
	push(l += n_), push(r += n_);
	for ( ; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1)
			put(l++, t, a, b);
		if ((r & 1) == 0)
			put(r--, t, a, b);
	}
}

long long query(int i) {
	push(n_ + i);
	return aa[n_ + i] * i + bb[n_ + i];
}

void upd_(int i, int x) {
	i += n_;
	push_(i);
	pp[i] = qq[i] = mx[i] = x;
	pull_(i);
}

void update_(int l, int r) {
	int l_ = l += n_, r_ = r += n_;

	push_(l_), push_(r_);
	for ( ; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1)
			put_(l++);
		if ((r & 1) == 0)
			put_(r--);
	}
	pull_(l_), pull_(r_);
}

int query_(int l, int r) {
	int q, p, x;

	push_(l += n_), push_(r += n_);
	q = p = x = 0;
	for ( ; l <= r; l >>= 1, r >>= 1) {
		if ((l & 1) == 1) {
			x = max(max(x, mx[l]), q + pp[l]);
			q = qq[l] < kk[l] ? qq[l] : q + kk[l];
			l++;
		}
		if ((r & 1) == 0) { 
			x = max(max(mx[r], x), qq[r] + p);
			p = pp[r] < kk[r] ? pp[r] : kk[r] + p;
			r--;
		}
	}
	x = max(x, q + p);
	return x;
}

int main() {
	static long long xx[N];
	int n, q, i;

	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++)
		scanf("%lld", &xx[i]);
	build(xx, n);
	while (q--) {
		int t, l, r, a, b;

		scanf("%d%d%d", &t, &l, &r), l--, r--;
		if (t == 1) {
			scanf("%d%d", &b, &a);
			update(l, r, 1, a, b - (long long) l * a);
			for (i = max(l - 2, 0); i <= l + 1 && i < n; i++)
				xx[i] = query(i);
			for (i = max(r - 1, 0); i <= r + 2 && i < n; i++)
				xx[i] = query(i);
			for (i = max(l - 2, 0); i < l && i + 2 < n; i++)
				upd_(i, xx[i + 2] - xx[i + 1] * 2 + xx[i] == 0 ? 1 : 0);
			for (i = max(r - 1, 0); i <= r && i + 2 < n; i++)
				upd_(i, xx[i + 2] - xx[i + 1] * 2 + xx[i] == 0 ? 1 : 0);
		} else if (t == 2) {
			scanf("%d%d", &b, &a);
			update(l, r, 2, a, b - (long long) l * a);
			if (r - l >= 2)
				update_(l, r - 2);
			for (i = max(l - 2, 0); i <= l + 1 && i < n; i++)
				xx[i] = query(i);
			for (i = max(r - 1, 0); i <= r + 2 && i < n; i++)
				xx[i] = query(i);
			for (i = max(l - 2, 0); i < l && i + 2 < n; i++)
				upd_(i, xx[i + 2] - xx[i + 1] * 2 + xx[i] == 0 ? 1 : 0);
			for (i = max(r - 1, 0); i <= r && i + 2 < n; i++)
				upd_(i, xx[i + 2] - xx[i + 1] * 2 + xx[i] == 0 ? 1 : 0);
		} else
			printf("%d\n", r - l < 2 ? r - l + 1 : query_(l, r - 2) + 2);
	}
	return 0;
}

Compilation message

Progression.c: In function 'main':
Progression.c:145:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  145 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
Progression.c:147:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  147 |   scanf("%lld", &xx[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~
Progression.c:152:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  152 |   scanf("%d%d%d", &t, &l, &r), l--, r--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.c:154:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  154 |    scanf("%d%d", &b, &a);
      |    ^~~~~~~~~~~~~~~~~~~~~
Progression.c:165:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  165 |    scanf("%d%d", &b, &a);
      |    ^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 471 ms 36576 KB Output is correct
2 Correct 106 ms 3496 KB Output is correct
3 Correct 106 ms 3532 KB Output is correct
4 Correct 107 ms 3564 KB Output is correct
5 Correct 108 ms 3536 KB Output is correct
6 Correct 109 ms 3604 KB Output is correct
7 Correct 109 ms 3484 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 455 ms 36568 KB Output is correct
12 Correct 446 ms 36600 KB Output is correct
13 Correct 452 ms 36776 KB Output is correct
14 Correct 418 ms 36940 KB Output is correct
15 Correct 454 ms 36836 KB Output is correct
16 Correct 471 ms 36584 KB Output is correct
17 Correct 461 ms 36556 KB Output is correct
18 Correct 458 ms 36536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 340 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 288 KB Output is correct
4 Correct 1 ms 340 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 480 KB Output is correct
8 Correct 2 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 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 2 ms 456 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 300 KB Output is correct
21 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 34732 KB Output is correct
2 Correct 83 ms 3072 KB Output is correct
3 Correct 78 ms 3012 KB Output is correct
4 Correct 74 ms 2972 KB Output is correct
5 Correct 79 ms 3152 KB Output is correct
6 Correct 79 ms 3108 KB Output is correct
7 Correct 82 ms 3132 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 142 ms 33468 KB Output is correct
12 Correct 140 ms 34792 KB Output is correct
13 Correct 159 ms 33484 KB Output is correct
14 Correct 149 ms 33380 KB Output is correct
15 Correct 144 ms 34696 KB Output is correct
16 Correct 151 ms 35440 KB Output is correct
17 Correct 162 ms 35324 KB Output is correct
18 Correct 160 ms 35440 KB Output is correct
19 Correct 148 ms 34760 KB Output is correct
20 Correct 143 ms 34768 KB Output is correct
21 Correct 140 ms 34712 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 373 ms 37548 KB Output is correct
2 Correct 130 ms 3740 KB Output is correct
3 Correct 129 ms 3572 KB Output is correct
4 Correct 125 ms 3560 KB Output is correct
5 Correct 131 ms 3692 KB Output is correct
6 Correct 131 ms 3600 KB Output is correct
7 Correct 130 ms 3688 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 Correct 366 ms 34304 KB Output is correct
12 Correct 381 ms 37596 KB Output is correct
13 Correct 380 ms 34376 KB Output is correct
14 Correct 354 ms 34356 KB Output is correct
15 Correct 381 ms 37496 KB Output is correct
16 Correct 381 ms 37616 KB Output is correct
17 Correct 393 ms 37660 KB Output is correct
18 Correct 381 ms 37752 KB Output is correct
19 Correct 379 ms 37576 KB Output is correct
20 Correct 371 ms 37492 KB Output is correct
21 Correct 383 ms 37568 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 141 ms 34732 KB Output is correct
2 Correct 83 ms 3072 KB Output is correct
3 Correct 78 ms 3012 KB Output is correct
4 Correct 74 ms 2972 KB Output is correct
5 Correct 79 ms 3152 KB Output is correct
6 Correct 79 ms 3108 KB Output is correct
7 Correct 82 ms 3132 KB Output is correct
8 Correct 1 ms 292 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 142 ms 33468 KB Output is correct
12 Correct 140 ms 34792 KB Output is correct
13 Correct 159 ms 33484 KB Output is correct
14 Correct 149 ms 33380 KB Output is correct
15 Correct 144 ms 34696 KB Output is correct
16 Correct 151 ms 35440 KB Output is correct
17 Correct 162 ms 35324 KB Output is correct
18 Correct 160 ms 35440 KB Output is correct
19 Correct 148 ms 34760 KB Output is correct
20 Correct 143 ms 34768 KB Output is correct
21 Correct 140 ms 34712 KB Output is correct
22 Correct 477 ms 42132 KB Output is correct
23 Correct 125 ms 3524 KB Output is correct
24 Correct 129 ms 3512 KB Output is correct
25 Correct 126 ms 3496 KB Output is correct
26 Correct 124 ms 3592 KB Output is correct
27 Correct 125 ms 3588 KB Output is correct
28 Correct 126 ms 3496 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 499 ms 39340 KB Output is correct
33 Correct 481 ms 41996 KB Output is correct
34 Correct 519 ms 39336 KB Output is correct
35 Correct 517 ms 39348 KB Output is correct
36 Correct 365 ms 39144 KB Output is correct
37 Correct 344 ms 39124 KB Output is correct
38 Correct 348 ms 39192 KB Output is correct
39 Correct 519 ms 42032 KB Output is correct
40 Correct 504 ms 42208 KB Output is correct
41 Correct 534 ms 42176 KB Output is correct
42 Correct 517 ms 42128 KB Output is correct
43 Correct 505 ms 42008 KB Output is correct
44 Correct 515 ms 41996 KB Output is correct
45 Correct 495 ms 42024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 471 ms 36576 KB Output is correct
2 Correct 106 ms 3496 KB Output is correct
3 Correct 106 ms 3532 KB Output is correct
4 Correct 107 ms 3564 KB Output is correct
5 Correct 108 ms 3536 KB Output is correct
6 Correct 109 ms 3604 KB Output is correct
7 Correct 109 ms 3484 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 300 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 455 ms 36568 KB Output is correct
12 Correct 446 ms 36600 KB Output is correct
13 Correct 452 ms 36776 KB Output is correct
14 Correct 418 ms 36940 KB Output is correct
15 Correct 454 ms 36836 KB Output is correct
16 Correct 471 ms 36584 KB Output is correct
17 Correct 461 ms 36556 KB Output is correct
18 Correct 458 ms 36536 KB Output is correct
19 Correct 2 ms 340 KB Output is correct
20 Correct 1 ms 296 KB Output is correct
21 Correct 1 ms 288 KB Output is correct
22 Correct 1 ms 340 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 1 ms 340 KB Output is correct
25 Correct 1 ms 480 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 2 ms 456 KB Output is correct
34 Correct 2 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 2 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 300 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 141 ms 34732 KB Output is correct
41 Correct 83 ms 3072 KB Output is correct
42 Correct 78 ms 3012 KB Output is correct
43 Correct 74 ms 2972 KB Output is correct
44 Correct 79 ms 3152 KB Output is correct
45 Correct 79 ms 3108 KB Output is correct
46 Correct 82 ms 3132 KB Output is correct
47 Correct 1 ms 292 KB Output is correct
48 Correct 1 ms 340 KB Output is correct
49 Correct 1 ms 340 KB Output is correct
50 Correct 142 ms 33468 KB Output is correct
51 Correct 140 ms 34792 KB Output is correct
52 Correct 159 ms 33484 KB Output is correct
53 Correct 149 ms 33380 KB Output is correct
54 Correct 144 ms 34696 KB Output is correct
55 Correct 151 ms 35440 KB Output is correct
56 Correct 162 ms 35324 KB Output is correct
57 Correct 160 ms 35440 KB Output is correct
58 Correct 148 ms 34760 KB Output is correct
59 Correct 143 ms 34768 KB Output is correct
60 Correct 140 ms 34712 KB Output is correct
61 Correct 373 ms 37548 KB Output is correct
62 Correct 130 ms 3740 KB Output is correct
63 Correct 129 ms 3572 KB Output is correct
64 Correct 125 ms 3560 KB Output is correct
65 Correct 131 ms 3692 KB Output is correct
66 Correct 131 ms 3600 KB Output is correct
67 Correct 130 ms 3688 KB Output is correct
68 Correct 1 ms 340 KB Output is correct
69 Correct 1 ms 340 KB Output is correct
70 Correct 1 ms 340 KB Output is correct
71 Correct 366 ms 34304 KB Output is correct
72 Correct 381 ms 37596 KB Output is correct
73 Correct 380 ms 34376 KB Output is correct
74 Correct 354 ms 34356 KB Output is correct
75 Correct 381 ms 37496 KB Output is correct
76 Correct 381 ms 37616 KB Output is correct
77 Correct 393 ms 37660 KB Output is correct
78 Correct 381 ms 37752 KB Output is correct
79 Correct 379 ms 37576 KB Output is correct
80 Correct 371 ms 37492 KB Output is correct
81 Correct 383 ms 37568 KB Output is correct
82 Correct 477 ms 42132 KB Output is correct
83 Correct 125 ms 3524 KB Output is correct
84 Correct 129 ms 3512 KB Output is correct
85 Correct 126 ms 3496 KB Output is correct
86 Correct 124 ms 3592 KB Output is correct
87 Correct 125 ms 3588 KB Output is correct
88 Correct 126 ms 3496 KB Output is correct
89 Correct 1 ms 340 KB Output is correct
90 Correct 1 ms 308 KB Output is correct
91 Correct 1 ms 340 KB Output is correct
92 Correct 499 ms 39340 KB Output is correct
93 Correct 481 ms 41996 KB Output is correct
94 Correct 519 ms 39336 KB Output is correct
95 Correct 517 ms 39348 KB Output is correct
96 Correct 365 ms 39144 KB Output is correct
97 Correct 344 ms 39124 KB Output is correct
98 Correct 348 ms 39192 KB Output is correct
99 Correct 519 ms 42032 KB Output is correct
100 Correct 504 ms 42208 KB Output is correct
101 Correct 534 ms 42176 KB Output is correct
102 Correct 517 ms 42128 KB Output is correct
103 Correct 505 ms 42008 KB Output is correct
104 Correct 515 ms 41996 KB Output is correct
105 Correct 495 ms 42024 KB Output is correct
106 Correct 726 ms 43392 KB Output is correct
107 Correct 162 ms 3748 KB Output is correct
108 Correct 157 ms 3692 KB Output is correct
109 Correct 156 ms 3700 KB Output is correct
110 Correct 1 ms 340 KB Output is correct
111 Correct 1 ms 300 KB Output is correct
112 Correct 1 ms 340 KB Output is correct
113 Correct 510 ms 42184 KB Output is correct
114 Correct 510 ms 42424 KB Output is correct
115 Correct 500 ms 42060 KB Output is correct
116 Correct 503 ms 42040 KB Output is correct
117 Correct 724 ms 43312 KB Output is correct
118 Correct 493 ms 42012 KB Output is correct
119 Correct 485 ms 42100 KB Output is correct
120 Correct 149 ms 35664 KB Output is correct
121 Correct 158 ms 35728 KB Output is correct
122 Correct 157 ms 35532 KB Output is correct
123 Correct 144 ms 34748 KB Output is correct
124 Correct 147 ms 34776 KB Output is correct
125 Correct 140 ms 34756 KB Output is correct
126 Correct 688 ms 40036 KB Output is correct
127 Correct 743 ms 40016 KB Output is correct
128 Correct 715 ms 43340 KB Output is correct
129 Correct 721 ms 40088 KB Output is correct
130 Correct 412 ms 40128 KB Output is correct
131 Correct 408 ms 40112 KB Output is correct
132 Correct 450 ms 40124 KB Output is correct
133 Correct 751 ms 43464 KB Output is correct
134 Correct 717 ms 43356 KB Output is correct
135 Correct 730 ms 43456 KB Output is correct
136 Correct 158 ms 3684 KB Output is correct
137 Correct 155 ms 3692 KB Output is correct
138 Correct 165 ms 3844 KB Output is correct