Submission #834149

# Submission time Handle Problem Language Result Execution time Memory
834149 2023-08-22T11:15:51 Z rainboy Progression (NOI20_progression) C
35 / 100
182 ms 57532 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 n_;

void pul(int 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 build(int *aa, int n) {
	int i;

	n_ = 1;
	while (n_ < n - 1)
		n_ <<= 1;
	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);
}

int query(int l, int r) {
	long long aq, ap;
	int kq, kp, k_;

	aq = 0, kq = 0, ap = 0, kp = 0, k_ = 0;
	for (l += n_, r += n_; 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;

		scanf("%d%d%d", &t, &l, &r), l--, r--;
		printf("%d\n", l == r ? 1 : query(l, r - 1) + 1);
	}
	return 0;
}

Compilation message

Progression.c: In function 'main':
Progression.c:68:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   68 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
Progression.c:70:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   70 |   scanf("%d", &aa[i]);
      |   ^~~~~~~~~~~~~~~~~~~
Progression.c:75:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |   scanf("%d%d%d", &t, &l, &r), l--, r--;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 60 ms 55116 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 596 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 152 ms 28224 KB Output is correct
2 Correct 79 ms 2908 KB Output is correct
3 Correct 77 ms 3004 KB Output is correct
4 Correct 82 ms 2912 KB Output is correct
5 Correct 77 ms 3172 KB Output is correct
6 Correct 78 ms 3152 KB Output is correct
7 Correct 78 ms 3092 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 182 ms 32904 KB Output is correct
12 Correct 159 ms 34324 KB Output is correct
13 Correct 176 ms 32972 KB Output is correct
14 Correct 181 ms 33004 KB Output is correct
15 Correct 148 ms 34280 KB Output is correct
16 Correct 167 ms 34892 KB Output is correct
17 Correct 181 ms 35064 KB Output is correct
18 Correct 174 ms 34892 KB Output is correct
19 Correct 160 ms 34300 KB Output is correct
20 Correct 156 ms 34192 KB Output is correct
21 Correct 157 ms 34252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 56 ms 55120 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 152 ms 28224 KB Output is correct
2 Correct 79 ms 2908 KB Output is correct
3 Correct 77 ms 3004 KB Output is correct
4 Correct 82 ms 2912 KB Output is correct
5 Correct 77 ms 3172 KB Output is correct
6 Correct 78 ms 3152 KB Output is correct
7 Correct 78 ms 3092 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 182 ms 32904 KB Output is correct
12 Correct 159 ms 34324 KB Output is correct
13 Correct 176 ms 32972 KB Output is correct
14 Correct 181 ms 33004 KB Output is correct
15 Correct 148 ms 34280 KB Output is correct
16 Correct 167 ms 34892 KB Output is correct
17 Correct 181 ms 35064 KB Output is correct
18 Correct 174 ms 34892 KB Output is correct
19 Correct 160 ms 34300 KB Output is correct
20 Correct 156 ms 34192 KB Output is correct
21 Correct 157 ms 34252 KB Output is correct
22 Runtime error 57 ms 57532 KB Execution killed with signal 11
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 60 ms 55116 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -