Submission #493307

# Submission time Handle Problem Language Result Execution time Memory
493307 2021-12-10T21:22:42 Z rainboy Autobahn (COI21_autobahn) C
100 / 100
159 ms 17452 KB
#include <stdio.h>

#define N	100000

long long min(long long a, long long b) { return a < b ? a : b; }
long long max(long long a, long long b) { return a > b ? a : b; }

unsigned int X = 12345;

int rand_() {
	return (X *= 3) >> 1;
}

int *zz;

void sort(int *ii, int l, int r) {
	while (l < r) {
		int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;

		while (j < k)
			if (zz[ii[j]] == zz[i_])
				j++;
			else if (zz[ii[j]] < zz[i_]) {
				tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;
				i++, j++;
			} else {
				k--;
				tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;
			}
		sort(ii, l, i);
		l = k;
	}
}

void accumulate(int *xx, int *dd, int n) {
	static int xx_[N * 2], dd_[N * 2], ii[N * 2];
	int i;

	for (i = 0; i < n; i++)
		ii[i] = i;
	zz = xx, sort(ii, 0, n);
	for (i = 1; i < n; i++)
		dd[ii[i]] += dd[ii[i - 1]];
	for (i = 0; i < n; i++)
		xx_[i] = xx[ii[i]], dd_[i] = dd[ii[i]];
	for (i = 0; i < n; i++)
		xx[i] = xx_[i], dd[i] = dd_[i];
}

int main() {
	static int ll[N], rr[N], cc[N], xx1[N * 2], dd1[N * 2], xx2[N * 2], dd2[N * 2], xx3[N * 8], dd3[N * 8], ii[N * 8];
	int n, n1, n2, n3, k, len, i, i1, i2;
	long long ans, y, d;

	scanf("%d%d%d", &n, &k, &len);
	for (i = 0; i < n; i++)
		scanf("%d%d%d", &ll[i], &cc[i], &rr[i]);
	n1 = 0, n2 = 0;
	for (i = 0; i < n; i++) {
		xx1[n1] = ll[i], dd1[n1] = 1, n1++, xx1[n1] = rr[i] + 1, dd1[n1] = -1, n1++;
		if (ll[i] + cc[i] <= rr[i])
			xx2[n2] = ll[i] + cc[i], dd2[n2] = 1, n2++, xx2[n2] = rr[i] + 1, dd2[n2] = -1, n2++;
	}
	accumulate(xx1, dd1, n1);
	accumulate(xx2, dd2, n2);
	i1 = 0, i2 = 0, n3 = 0;
	while (i1 + 1 < n1 && i2 + 1 < n2) {
		int l = max(xx1[i1], xx2[i2]), r = min(xx1[i1 + 1], xx2[i2 + 1]);

		if (l < r && dd1[i1] >= k && dd2[i2] > 0) {
			xx3[n3] = l - len, dd3[n3] = dd2[i2], n3++, xx3[n3] = l, dd3[n3] = -dd2[i2], n3++;
			xx3[n3] = r - len, dd3[n3] = -dd2[i2], n3++, xx3[n3] = r, dd3[n3] = dd2[i2], n3++;
		}
		if (xx1[i1 + 1] < xx2[i2 + 1])
			i1++;
		else
			i2++;
	}
	for (i = 0; i < n3; i++)
		ii[i] = i;
	zz = xx3, sort(ii, 0, n3);
	ans = 0, y = 0, d = 0;
	for (i = 0; i + 1 < n3; i++) {
		d += dd3[ii[i]];
		y += (long long) (xx3[ii[i + 1]] - xx3[ii[i]]) * d;
		ans = max(ans, y);
	}
	printf("%lld\n", ans);
	return 0;
}

Compilation message

autobahn.c: In function 'main':
autobahn.c:55:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |  scanf("%d%d%d", &n, &k, &len);
      |  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
autobahn.c:57:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |   scanf("%d%d%d", &ll[i], &cc[i], &rr[i]);
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 448 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 0 ms 332 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 0 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 460 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 448 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 145 ms 17288 KB Output is correct
22 Correct 147 ms 17372 KB Output is correct
23 Correct 149 ms 17296 KB Output is correct
24 Correct 159 ms 17452 KB Output is correct
25 Correct 145 ms 17220 KB Output is correct
26 Correct 142 ms 17192 KB Output is correct
27 Correct 141 ms 17328 KB Output is correct
28 Correct 148 ms 17324 KB Output is correct
29 Correct 142 ms 17436 KB Output is correct