Submission #503245

# Submission time Handle Problem Language Result Execution time Memory
503245 2022-01-07T14:55:36 Z rainboy Osumnjičeni (COCI21_osumnjiceni) C
30 / 110
1000 ms 18280 KB
#include <stdio.h>
#include <string.h>

#define N	200000
#define L	18	/* L = ceil(log2(N)) */

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

unsigned int X = 12345;

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

int xx[N * 2];

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 (xx[ii[j]] == xx[i_])
				j++;
			else if (xx[ii[j]] < xx[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;
	}
}

int main() {
	static int dd[N * 2], jj[L + 1][N];
	int n, q, i, j, l;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d%d", &xx[i << 1 | 0], &xx[i << 1 | 1]), xx[i << 1 | 1]++;
	scanf("%d", &q);
	for (i = 0; i < n; i++) {
		for (j = i + 1; j < n; j++)
			if (max(xx[i << 1 | 0], xx[j << 1 | 0]) < min(xx[i << 1 | 1], xx[j << 1 | 1]))
				break;
		jj[0][i] = j;
	}
	jj[0][n] = n;
	for (i = n - 1; i >= 0; i--)
		jj[0][i] = min(jj[0][i], jj[0][i + 1]);
	for (l = 1; l <= L; l++)
		for (i = 0; i <= n; i++)
			jj[l][i] = jj[l - 1][jj[l - 1][i]];
	while (q--) {
		int k, l;

		scanf("%d%d", &i, &j), i--, j--;
		memset(dd, 0, n * 2 * sizeof *dd);
		k = 0;
		for (l = L; l >= 0; l--)
			if (jj[l][i] <= j)
				i = jj[l][i], k += 1 << l;
		k++;
		printf("%d\n", k);
	}
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:41:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:43:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   scanf("%d%d", &xx[i << 1 | 0], &xx[i << 1 | 1]), xx[i << 1 | 1]++;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:44:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |  scanf("%d", &q);
      |  ^~~~~~~~~~~~~~~
Main.c:60:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   60 |   scanf("%d%d", &i, &j), i--, j--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 56 ms 17452 KB Output is correct
2 Correct 57 ms 17352 KB Output is correct
3 Correct 56 ms 17368 KB Output is correct
4 Correct 57 ms 17504 KB Output is correct
5 Correct 60 ms 18280 KB Output is correct
6 Correct 54 ms 16604 KB Output is correct
7 Correct 54 ms 16872 KB Output is correct
8 Correct 68 ms 17284 KB Output is correct
9 Correct 64 ms 17584 KB Output is correct
10 Correct 62 ms 16988 KB Output is correct
11 Execution timed out 1081 ms 1872 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 844 KB Output is correct
2 Correct 7 ms 844 KB Output is correct
3 Correct 8 ms 836 KB Output is correct
4 Correct 7 ms 844 KB Output is correct
5 Correct 8 ms 812 KB Output is correct
6 Correct 9 ms 844 KB Output is correct
7 Correct 9 ms 844 KB Output is correct
8 Correct 7 ms 844 KB Output is correct
9 Correct 12 ms 796 KB Output is correct
10 Correct 8 ms 716 KB Output is correct
11 Correct 27 ms 836 KB Output is correct
12 Correct 24 ms 844 KB Output is correct
13 Correct 24 ms 700 KB Output is correct
14 Correct 24 ms 716 KB Output is correct
15 Correct 26 ms 808 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 7 ms 844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 844 KB Output is correct
2 Correct 7 ms 844 KB Output is correct
3 Correct 8 ms 836 KB Output is correct
4 Correct 7 ms 844 KB Output is correct
5 Correct 8 ms 812 KB Output is correct
6 Correct 9 ms 844 KB Output is correct
7 Correct 9 ms 844 KB Output is correct
8 Correct 7 ms 844 KB Output is correct
9 Correct 12 ms 796 KB Output is correct
10 Correct 8 ms 716 KB Output is correct
11 Correct 27 ms 836 KB Output is correct
12 Correct 24 ms 844 KB Output is correct
13 Correct 24 ms 700 KB Output is correct
14 Correct 24 ms 716 KB Output is correct
15 Correct 26 ms 808 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 7 ms 844 KB Output is correct
18 Correct 255 ms 1804 KB Output is correct
19 Correct 236 ms 1620 KB Output is correct
20 Correct 246 ms 1860 KB Output is correct
21 Correct 242 ms 1576 KB Output is correct
22 Correct 220 ms 1616 KB Output is correct
23 Correct 263 ms 1688 KB Output is correct
24 Correct 261 ms 1652 KB Output is correct
25 Correct 241 ms 1636 KB Output is correct
26 Correct 248 ms 1784 KB Output is correct
27 Correct 225 ms 1588 KB Output is correct
28 Correct 243 ms 1124 KB Output is correct
29 Correct 236 ms 1260 KB Output is correct
30 Correct 241 ms 1220 KB Output is correct
31 Correct 246 ms 1340 KB Output is correct
32 Correct 246 ms 1452 KB Output is correct
33 Correct 1 ms 284 KB Output is correct
34 Correct 230 ms 1896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 18260 KB Output is correct
2 Correct 68 ms 17936 KB Output is correct
3 Correct 77 ms 16808 KB Output is correct
4 Correct 63 ms 16620 KB Output is correct
5 Correct 57 ms 17152 KB Output is correct
6 Correct 56 ms 16836 KB Output is correct
7 Correct 59 ms 16696 KB Output is correct
8 Correct 62 ms 16880 KB Output is correct
9 Correct 66 ms 16600 KB Output is correct
10 Correct 68 ms 18040 KB Output is correct
11 Execution timed out 1087 ms 1876 KB Time limit exceeded
12 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 56 ms 17452 KB Output is correct
2 Correct 57 ms 17352 KB Output is correct
3 Correct 56 ms 17368 KB Output is correct
4 Correct 57 ms 17504 KB Output is correct
5 Correct 60 ms 18280 KB Output is correct
6 Correct 54 ms 16604 KB Output is correct
7 Correct 54 ms 16872 KB Output is correct
8 Correct 68 ms 17284 KB Output is correct
9 Correct 64 ms 17584 KB Output is correct
10 Correct 62 ms 16988 KB Output is correct
11 Execution timed out 1081 ms 1872 KB Time limit exceeded
12 Halted 0 ms 0 KB -