Submission #872794

# Submission time Handle Problem Language Result Execution time Memory
872794 2023-11-13T19:51:02 Z rainboy Pilot (NOI19_pilot) C
100 / 100
925 ms 44692 KB
#include <stdio.h>

#define N	1000000

unsigned int X = 12345;

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

int yy[N];

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 (yy[ii[j]] == yy[i_])
				j++;
			else if (yy[ii[j]] < yy[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], pp[N], qq[N];
	static long long ans[N + 1];
	int n, q, h, i;

	scanf("%d%d", &n, &q);
	for (i = 0; i < n; i++)
		scanf("%d", &yy[i]);
	for (i = 0; i < n; i++)
		ii[i] = i;
	sort(ii, 0, n);
	for (i = 0; i < n; i++)
		pp[i] = i - 1, qq[i] = i + 1;
	for (h = 0; h < n; h++) {
		i = ii[h];
		ans[h + 1] = ans[h] + (long long) (i - pp[i]) * (qq[i] - i);
		if (pp[i] != -1)
			qq[pp[i]] = qq[i];
		if (qq[i] != n)
			pp[qq[i]] = pp[i];
	}
	while (q--) {
		int y, lower, upper;

		scanf("%d", &y);
		lower = -1, upper = n;
		while (upper - lower > 1) {
			h = (lower + upper) / 2;
			if (yy[ii[h]] <= y)
				lower = h;
			else
				upper = h;
		}
		printf("%lld\n", ans[upper]);
	}
	return 0;
}

Compilation message

pilot.c: In function 'main':
pilot.c:37:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |  scanf("%d%d", &n, &q);
      |  ^~~~~~~~~~~~~~~~~~~~~
pilot.c:39:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   scanf("%d", &yy[i]);
      |   ^~~~~~~~~~~~~~~~~~~
pilot.c:56:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |   scanf("%d", &y);
      |   ^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6532 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6532 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6532 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 10076 KB Output is correct
2 Correct 21 ms 10444 KB Output is correct
3 Correct 19 ms 10072 KB Output is correct
4 Correct 19 ms 10104 KB Output is correct
5 Correct 18 ms 10096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 45 ms 11600 KB Output is correct
2 Correct 49 ms 11764 KB Output is correct
3 Correct 45 ms 11604 KB Output is correct
4 Correct 46 ms 11856 KB Output is correct
5 Correct 45 ms 11600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 49 ms 11860 KB Output is correct
2 Correct 53 ms 11856 KB Output is correct
3 Correct 50 ms 11860 KB Output is correct
4 Correct 51 ms 11860 KB Output is correct
5 Correct 54 ms 11860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 19 ms 10076 KB Output is correct
12 Correct 21 ms 10444 KB Output is correct
13 Correct 19 ms 10072 KB Output is correct
14 Correct 19 ms 10104 KB Output is correct
15 Correct 18 ms 10096 KB Output is correct
16 Correct 19 ms 10072 KB Output is correct
17 Correct 20 ms 10428 KB Output is correct
18 Correct 21 ms 10332 KB Output is correct
19 Correct 18 ms 10016 KB Output is correct
20 Correct 21 ms 10324 KB Output is correct
21 Correct 18 ms 10072 KB Output is correct
22 Correct 20 ms 10120 KB Output is correct
23 Correct 23 ms 10264 KB Output is correct
24 Correct 19 ms 10096 KB Output is correct
25 Correct 19 ms 10060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6532 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 19 ms 10076 KB Output is correct
27 Correct 21 ms 10444 KB Output is correct
28 Correct 19 ms 10072 KB Output is correct
29 Correct 19 ms 10104 KB Output is correct
30 Correct 18 ms 10096 KB Output is correct
31 Correct 45 ms 11600 KB Output is correct
32 Correct 49 ms 11764 KB Output is correct
33 Correct 45 ms 11604 KB Output is correct
34 Correct 46 ms 11856 KB Output is correct
35 Correct 45 ms 11600 KB Output is correct
36 Correct 49 ms 11860 KB Output is correct
37 Correct 53 ms 11856 KB Output is correct
38 Correct 50 ms 11860 KB Output is correct
39 Correct 51 ms 11860 KB Output is correct
40 Correct 54 ms 11860 KB Output is correct
41 Correct 19 ms 10072 KB Output is correct
42 Correct 20 ms 10428 KB Output is correct
43 Correct 21 ms 10332 KB Output is correct
44 Correct 18 ms 10016 KB Output is correct
45 Correct 21 ms 10324 KB Output is correct
46 Correct 18 ms 10072 KB Output is correct
47 Correct 20 ms 10120 KB Output is correct
48 Correct 23 ms 10264 KB Output is correct
49 Correct 19 ms 10096 KB Output is correct
50 Correct 19 ms 10060 KB Output is correct
51 Correct 54 ms 11708 KB Output is correct
52 Correct 63 ms 11428 KB Output is correct
53 Correct 54 ms 11664 KB Output is correct
54 Correct 59 ms 11600 KB Output is correct
55 Correct 60 ms 11644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6488 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6532 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6488 KB Output is correct
19 Correct 2 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 2 ms 6492 KB Output is correct
22 Correct 2 ms 6748 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 2 ms 6492 KB Output is correct
26 Correct 19 ms 10076 KB Output is correct
27 Correct 21 ms 10444 KB Output is correct
28 Correct 19 ms 10072 KB Output is correct
29 Correct 19 ms 10104 KB Output is correct
30 Correct 18 ms 10096 KB Output is correct
31 Correct 45 ms 11600 KB Output is correct
32 Correct 49 ms 11764 KB Output is correct
33 Correct 45 ms 11604 KB Output is correct
34 Correct 46 ms 11856 KB Output is correct
35 Correct 45 ms 11600 KB Output is correct
36 Correct 49 ms 11860 KB Output is correct
37 Correct 53 ms 11856 KB Output is correct
38 Correct 50 ms 11860 KB Output is correct
39 Correct 51 ms 11860 KB Output is correct
40 Correct 54 ms 11860 KB Output is correct
41 Correct 19 ms 10072 KB Output is correct
42 Correct 20 ms 10428 KB Output is correct
43 Correct 21 ms 10332 KB Output is correct
44 Correct 18 ms 10016 KB Output is correct
45 Correct 21 ms 10324 KB Output is correct
46 Correct 18 ms 10072 KB Output is correct
47 Correct 20 ms 10120 KB Output is correct
48 Correct 23 ms 10264 KB Output is correct
49 Correct 19 ms 10096 KB Output is correct
50 Correct 19 ms 10060 KB Output is correct
51 Correct 54 ms 11708 KB Output is correct
52 Correct 63 ms 11428 KB Output is correct
53 Correct 54 ms 11664 KB Output is correct
54 Correct 59 ms 11600 KB Output is correct
55 Correct 60 ms 11644 KB Output is correct
56 Correct 861 ms 44212 KB Output is correct
57 Correct 925 ms 44028 KB Output is correct
58 Correct 758 ms 42684 KB Output is correct
59 Correct 778 ms 43088 KB Output is correct
60 Correct 888 ms 44692 KB Output is correct