Submission #503243

#TimeUsernameProblemLanguageResultExecution timeMemory
503243rainboyOsumnjičeni (COCI21_osumnjiceni)C11
10 / 110
1089 ms5792 KiB
#include <stdio.h>
#include <string.h>

#define N	200000

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[N];
	int n, q, i, j;

	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[i] = j;
	}
	for (i = n - 2; i >= 0; i--)
		jj[i] = min(jj[i], jj[i + 1]);
	while (q--) {
		int k;

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

Compilation message (stderr)

Main.c: In function 'main':
Main.c:40:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:42:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |   scanf("%d%d", &xx[i << 1 | 0], &xx[i << 1 | 1]), xx[i << 1 | 1]++;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:43:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |  scanf("%d", &q);
      |  ^~~~~~~~~~~~~~~
Main.c:55:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   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...