Submission #503238

# Submission time Handle Problem Language Result Execution time Memory
503238 2022-01-07T14:46:39 Z rainboy Osumnjičeni (COCI21_osumnjiceni) C
0 / 110
267 ms 5588 KB
#include <stdio.h>
#include <string.h>

#define N	200000

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 ii[N * 2], dd[N * 2];
	int n, q, i, x, ans;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d%d", &xx[i << 1 | 0], &xx[i << 1 | 1]), xx[i << 1 | 1]++;
	for (i = 0; i < n * 2; i++)
		ii[i] = i;
	sort(ii, 0, n * 2);
	for (i = 0, x = 0; i < n * 2; i++)
		xx[ii[i]] = i + 1 == n * 2 || xx[ii[i + 1]] != xx[ii[i]] ? x++ : x;
	scanf("%d", &q);
	while (q--) {
		int l, r;

		scanf("%d%d", &l, &r), l--, r--;
		memset(dd, 0, n * 2 * sizeof *dd);
		for (i = l; i <= r; i++)
			dd[xx[i << 1 | 0]]++, dd[xx[i << 1 | 1]]--;
		for (i = 1; i < n * 2; i++)
			dd[i] += dd[i - 1];
		ans = 0;
		for (i = 0; i < n * 2; i++)
			ans = max(ans, dd[i]);
		printf("%d\n", ans);
	}
	return 0;
}

Compilation message

Main.c: In function 'main':
Main.c:39:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |  scanf("%d", &n);
      |  ^~~~~~~~~~~~~~~
Main.c:41:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   41 |   scanf("%d%d", &xx[i << 1 | 0], &xx[i << 1 | 1]), xx[i << 1 | 1]++;
      |   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.c:47:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   47 |  scanf("%d", &q);
      |  ^~~~~~~~~~~~~~~
Main.c:51:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |   scanf("%d%d", &l, &r), l--, r--;
      |   ^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 5020 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 183 ms 424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 183 ms 424 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 267 ms 5588 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 112 ms 5020 KB Output isn't correct
2 Halted 0 ms 0 KB -