# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
695020 |
2023-02-04T16:43:02 Z |
rainboy |
Sushi (JOI16_sushi) |
C |
|
92 ms |
9608 KB |
#include <stdio.h>
#define N 400000
int aa[N], iq[N + 1], pq[N], cnt;
int lt(int i, int j) { return aa[i] > aa[j]; }
int p2(int p) {
return (p *= 2) > cnt ? 0 : (p < cnt && lt(iq[p + 1], iq[p]) ? p + 1 : p);
}
void pq_up(int i) {
int p, q, j;
for (p = pq[i]; (q = p / 2) && lt(i, j = iq[q]); p = q)
iq[pq[j] = p] = j;
iq[pq[i] = p] = i;
}
void pq_dn(int i) {
int p, q, j;
for (p = pq[i]; (q = p2(p)) && lt(j = iq[q], i); p = q)
iq[pq[j] = p] = j;
iq[pq[i] = p] = i;
}
int pq_first() {
return iq[1];
}
int main() {
int n, q, h, i;
scanf("%d%d", &n, &q);
for (i = 0; i < n; i++)
scanf("%d", &aa[i]);
if (n <= 2000 && q <= 2000) {
while (q--) {
int s, t, a, tmp;
scanf("%d%d%d", &s, &t, &a), s--, t--;
if (s <= t) {
for (i = s; i <= t; i++)
if (a < aa[i])
tmp = a, a = aa[i], aa[i] = tmp;
} else {
for (i = s; i < n; i++)
if (a < aa[i])
tmp = a, a = aa[i], aa[i] = tmp;
for (i = 0; i <= t; i++)
if (a < aa[i])
tmp = a, a = aa[i], aa[i] = tmp;
}
printf("%d\n", a);
}
} else {
for (i = 0; i < n; i++)
iq[pq[i] = ++cnt] = i;
for (h = cnt / 2; h > 0; h--)
pq_dn(iq[h]);
while (q--) {
int a;
scanf("%*d%*d%d", &a);
i = pq_first();
if (aa[i] > a)
printf("%d\n", aa[i]), aa[i] = a, pq_dn(i);
else
printf("%d\n", a);
}
}
return 0;
}
Compilation message
sushi.c: In function 'main':
sushi.c:36:2: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
36 | scanf("%d%d", &n, &q);
| ^~~~~~~~~~~~~~~~~~~~~
sushi.c:38:3: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | scanf("%d", &aa[i]);
| ^~~~~~~~~~~~~~~~~~~
sushi.c:43:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | scanf("%d%d%d", &s, &t, &a), s--, t--;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~
sushi.c:66:4: warning: ignoring return value of 'scanf' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%*d%*d%d", &a);
| ^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
212 KB |
Output is correct |
3 |
Correct |
4 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
324 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
3 ms |
212 KB |
Output is correct |
8 |
Correct |
3 ms |
212 KB |
Output is correct |
9 |
Correct |
4 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
312 KB |
Output is correct |
13 |
Correct |
8 ms |
212 KB |
Output is correct |
14 |
Correct |
6 ms |
312 KB |
Output is correct |
15 |
Correct |
5 ms |
320 KB |
Output is correct |
16 |
Correct |
2 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
92 ms |
5408 KB |
Output is correct |
2 |
Correct |
80 ms |
8248 KB |
Output is correct |
3 |
Correct |
74 ms |
6028 KB |
Output is correct |
4 |
Correct |
84 ms |
9528 KB |
Output is correct |
5 |
Correct |
72 ms |
9548 KB |
Output is correct |
6 |
Correct |
72 ms |
9548 KB |
Output is correct |
7 |
Correct |
90 ms |
9528 KB |
Output is correct |
8 |
Correct |
77 ms |
9556 KB |
Output is correct |
9 |
Correct |
47 ms |
5960 KB |
Output is correct |
10 |
Correct |
70 ms |
8064 KB |
Output is correct |
11 |
Correct |
50 ms |
5936 KB |
Output is correct |
12 |
Correct |
68 ms |
8124 KB |
Output is correct |
13 |
Correct |
77 ms |
9420 KB |
Output is correct |
14 |
Correct |
71 ms |
8064 KB |
Output is correct |
15 |
Correct |
49 ms |
6060 KB |
Output is correct |
16 |
Correct |
77 ms |
9504 KB |
Output is correct |
17 |
Correct |
76 ms |
9556 KB |
Output is correct |
18 |
Correct |
71 ms |
9584 KB |
Output is correct |
19 |
Correct |
70 ms |
9504 KB |
Output is correct |
20 |
Correct |
83 ms |
9580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
212 KB |
Output is correct |
2 |
Correct |
4 ms |
212 KB |
Output is correct |
3 |
Correct |
4 ms |
212 KB |
Output is correct |
4 |
Correct |
4 ms |
324 KB |
Output is correct |
5 |
Correct |
3 ms |
212 KB |
Output is correct |
6 |
Correct |
3 ms |
212 KB |
Output is correct |
7 |
Correct |
3 ms |
212 KB |
Output is correct |
8 |
Correct |
3 ms |
212 KB |
Output is correct |
9 |
Correct |
4 ms |
212 KB |
Output is correct |
10 |
Correct |
3 ms |
212 KB |
Output is correct |
11 |
Correct |
5 ms |
212 KB |
Output is correct |
12 |
Correct |
6 ms |
312 KB |
Output is correct |
13 |
Correct |
8 ms |
212 KB |
Output is correct |
14 |
Correct |
6 ms |
312 KB |
Output is correct |
15 |
Correct |
5 ms |
320 KB |
Output is correct |
16 |
Correct |
2 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
92 ms |
5408 KB |
Output is correct |
24 |
Correct |
80 ms |
8248 KB |
Output is correct |
25 |
Correct |
74 ms |
6028 KB |
Output is correct |
26 |
Correct |
84 ms |
9528 KB |
Output is correct |
27 |
Correct |
72 ms |
9548 KB |
Output is correct |
28 |
Correct |
72 ms |
9548 KB |
Output is correct |
29 |
Correct |
90 ms |
9528 KB |
Output is correct |
30 |
Correct |
77 ms |
9556 KB |
Output is correct |
31 |
Correct |
47 ms |
5960 KB |
Output is correct |
32 |
Correct |
70 ms |
8064 KB |
Output is correct |
33 |
Correct |
50 ms |
5936 KB |
Output is correct |
34 |
Correct |
68 ms |
8124 KB |
Output is correct |
35 |
Correct |
77 ms |
9420 KB |
Output is correct |
36 |
Correct |
71 ms |
8064 KB |
Output is correct |
37 |
Correct |
49 ms |
6060 KB |
Output is correct |
38 |
Correct |
77 ms |
9504 KB |
Output is correct |
39 |
Correct |
76 ms |
9556 KB |
Output is correct |
40 |
Correct |
71 ms |
9584 KB |
Output is correct |
41 |
Correct |
70 ms |
9504 KB |
Output is correct |
42 |
Correct |
83 ms |
9580 KB |
Output is correct |
43 |
Incorrect |
80 ms |
9608 KB |
Output isn't correct |
44 |
Halted |
0 ms |
0 KB |
- |