Submission #834309

# Submission time Handle Problem Language Result Execution time Memory
834309 2023-08-22T12:52:43 Z rainboy Progression (NOI20_progression) C
48 / 100
600 ms 60744 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 kk[N_ * 2];
long long aap[N_ * 2]; int kkp[N_ * 2];
long long aaq[N_ * 2]; int kkq[N_ * 2];
int kk_[N_ * 2];
int lz[N_];
int h_, n_;

void put(int i, long long x) {
	aap[i] += x, aaq[i] += x;
	if (i < n_)
		lz[i] += x;
}

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

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

		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;

	h_ = 0;
	while (1 << h_ < n - 1)
		h_++;
	n_ = 1 << h_;
	for (i = 0; i + 1 < n; i++) {
		kk[n_ + i] = 1;
		aap[n_ + i] = aaq[n_ + i] = aa[i + 1] - aa[i], kkp[n_ + i] = kkq[n_ + i] = 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, 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++, x);
		if ((r & 1) == 0)
			put(r--, x);
	}
	pull(l_), pull(r_);
}

int query(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;

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

Compilation message

Progression.c: In function 'main':
Progression.c:109:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  109 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
Progression.c:111:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  111 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
Progression.c:116:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  116 |   scanf("%d%d%d", &t, &l, &r), l--, r--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
Progression.c:118:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |    scanf("%d%d", &b, &a);
      |    ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 600 ms 60744 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 2 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 165 ms 30644 KB Output is correct
2 Correct 83 ms 2976 KB Output is correct
3 Correct 79 ms 3020 KB Output is correct
4 Correct 81 ms 2960 KB Output is correct
5 Correct 82 ms 3076 KB Output is correct
6 Correct 83 ms 3048 KB Output is correct
7 Correct 83 ms 3064 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 191 ms 33040 KB Output is correct
12 Correct 163 ms 34004 KB Output is correct
13 Correct 188 ms 32932 KB Output is correct
14 Correct 191 ms 33004 KB Output is correct
15 Correct 163 ms 33872 KB Output is correct
16 Correct 182 ms 34380 KB Output is correct
17 Correct 186 ms 34240 KB Output is correct
18 Correct 191 ms 34384 KB Output is correct
19 Correct 170 ms 33628 KB Output is correct
20 Correct 174 ms 33532 KB Output is correct
21 Correct 166 ms 33548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 59 ms 56728 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 165 ms 30644 KB Output is correct
2 Correct 83 ms 2976 KB Output is correct
3 Correct 79 ms 3020 KB Output is correct
4 Correct 81 ms 2960 KB Output is correct
5 Correct 82 ms 3076 KB Output is correct
6 Correct 83 ms 3048 KB Output is correct
7 Correct 83 ms 3064 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 296 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 191 ms 33040 KB Output is correct
12 Correct 163 ms 34004 KB Output is correct
13 Correct 188 ms 32932 KB Output is correct
14 Correct 191 ms 33004 KB Output is correct
15 Correct 163 ms 33872 KB Output is correct
16 Correct 182 ms 34380 KB Output is correct
17 Correct 186 ms 34240 KB Output is correct
18 Correct 191 ms 34384 KB Output is correct
19 Correct 170 ms 33628 KB Output is correct
20 Correct 174 ms 33532 KB Output is correct
21 Correct 166 ms 33548 KB Output is correct
22 Correct 589 ms 37792 KB Output is correct
23 Correct 121 ms 3484 KB Output is correct
24 Correct 116 ms 3504 KB Output is correct
25 Correct 116 ms 3500 KB Output is correct
26 Correct 117 ms 3544 KB Output is correct
27 Correct 119 ms 3492 KB Output is correct
28 Correct 119 ms 3496 KB Output is correct
29 Correct 1 ms 304 KB Output is correct
30 Correct 1 ms 212 KB Output is correct
31 Correct 1 ms 212 KB Output is correct
32 Correct 522 ms 34916 KB Output is correct
33 Correct 545 ms 37668 KB Output is correct
34 Correct 529 ms 34912 KB Output is correct
35 Correct 550 ms 34964 KB Output is correct
36 Correct 421 ms 34832 KB Output is correct
37 Correct 403 ms 34780 KB Output is correct
38 Correct 405 ms 34764 KB Output is correct
39 Correct 566 ms 37688 KB Output is correct
40 Correct 555 ms 37848 KB Output is correct
41 Correct 563 ms 37836 KB Output is correct
42 Correct 564 ms 37796 KB Output is correct
43 Correct 552 ms 37816 KB Output is correct
44 Correct 531 ms 37760 KB Output is correct
45 Correct 545 ms 37836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 600 ms 60744 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -