Submission #503245

#TimeUsernameProblemLanguageResultExecution timeMemory
503245rainboyOsumnjičeni (COCI21_osumnjiceni)C11
30 / 110
1087 ms18280 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...