답안 #134793

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134793 2019-07-23T09:26:36 Z onjo0127 Sushi (JOI16_sushi) C++11
100 / 100
4545 ms 82348 KB
#include <bits/stdc++.h>
using namespace std;

const int sn = 632;
int N, X[400009];
priority_queue<int> pq[700], L[700];

inline int geti(int i) { return (i-1) / sn; }

void go(int s, int e, int &x) {
	if(s > e) return;
	int id = geti(s), bs = id*sn+1, be = min(bs + sn - 1, N);
	if(s != bs || e < be) {
		for(int i=bs; i<=be; i++) {
			L[id].push(-X[i]);
			X[i] = -L[id].top();
			L[id].pop();
		}
		L[id] = pq[id] = priority_queue<int>();
		for(int i=s; i<=min(be, e); i++) if(X[i] > x) swap(x, X[i]);
		for(int i=bs; i<=be; i++) pq[id].push(X[i]);
		go(be + 1, e, x);
	}
	else {
		L[id].push(-x);
		pq[id].push(x);
		x = pq[id].top(); pq[id].pop();
		go(be + 1, e, x);
	}
}

int main() {
	int Q; scanf("%d%d",&N,&Q);
	for(int i=1; i<=N; i++) {
		scanf("%d",&X[i]);
		pq[geti(i)].push(X[i]);
	}
	while(Q--) {
		int S, T, P; scanf("%d%d%d",&S,&T,&P);
		int x = P;
		if(S <= T) go(S, T, x);
		else {
			go(S, N, x);
			go(1, T, x);
		}
		printf("%d\n", x);
	}
	return 0;
}

Compilation message

sushi.cpp: In function 'int main()':
sushi.cpp:33:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  int Q; scanf("%d%d",&N,&Q);
         ~~~~~^~~~~~~~~~~~~~
sushi.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&X[i]);
   ~~~~~^~~~~~~~~~~~
sushi.cpp:39:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int S, T, P; scanf("%d%d%d",&S,&T,&P);
                ~~~~~^~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 504 KB Output is correct
2 Correct 58 ms 508 KB Output is correct
3 Correct 56 ms 504 KB Output is correct
4 Correct 58 ms 508 KB Output is correct
5 Correct 57 ms 376 KB Output is correct
6 Correct 59 ms 512 KB Output is correct
7 Correct 50 ms 504 KB Output is correct
8 Correct 49 ms 376 KB Output is correct
9 Correct 63 ms 760 KB Output is correct
10 Correct 65 ms 620 KB Output is correct
11 Correct 69 ms 504 KB Output is correct
12 Correct 69 ms 504 KB Output is correct
13 Correct 76 ms 504 KB Output is correct
14 Correct 65 ms 504 KB Output is correct
15 Correct 65 ms 632 KB Output is correct
16 Correct 29 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3636 ms 82052 KB Output is correct
2 Correct 3579 ms 80608 KB Output is correct
3 Correct 1843 ms 78524 KB Output is correct
4 Correct 3598 ms 82080 KB Output is correct
5 Correct 2924 ms 82104 KB Output is correct
6 Correct 3519 ms 82104 KB Output is correct
7 Correct 3512 ms 82220 KB Output is correct
8 Correct 3457 ms 82096 KB Output is correct
9 Correct 1709 ms 78472 KB Output is correct
10 Correct 2866 ms 80792 KB Output is correct
11 Correct 1699 ms 78704 KB Output is correct
12 Correct 2923 ms 80600 KB Output is correct
13 Correct 3477 ms 82004 KB Output is correct
14 Correct 3664 ms 80672 KB Output is correct
15 Correct 1841 ms 78640 KB Output is correct
16 Correct 3498 ms 82244 KB Output is correct
17 Correct 2940 ms 82220 KB Output is correct
18 Correct 3536 ms 82312 KB Output is correct
19 Correct 3495 ms 82340 KB Output is correct
20 Correct 3499 ms 82348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 59 ms 504 KB Output is correct
2 Correct 58 ms 508 KB Output is correct
3 Correct 56 ms 504 KB Output is correct
4 Correct 58 ms 508 KB Output is correct
5 Correct 57 ms 376 KB Output is correct
6 Correct 59 ms 512 KB Output is correct
7 Correct 50 ms 504 KB Output is correct
8 Correct 49 ms 376 KB Output is correct
9 Correct 63 ms 760 KB Output is correct
10 Correct 65 ms 620 KB Output is correct
11 Correct 69 ms 504 KB Output is correct
12 Correct 69 ms 504 KB Output is correct
13 Correct 76 ms 504 KB Output is correct
14 Correct 65 ms 504 KB Output is correct
15 Correct 65 ms 632 KB Output is correct
16 Correct 29 ms 504 KB Output is correct
17 Correct 2 ms 376 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 376 KB Output is correct
23 Correct 3636 ms 82052 KB Output is correct
24 Correct 3579 ms 80608 KB Output is correct
25 Correct 1843 ms 78524 KB Output is correct
26 Correct 3598 ms 82080 KB Output is correct
27 Correct 2924 ms 82104 KB Output is correct
28 Correct 3519 ms 82104 KB Output is correct
29 Correct 3512 ms 82220 KB Output is correct
30 Correct 3457 ms 82096 KB Output is correct
31 Correct 1709 ms 78472 KB Output is correct
32 Correct 2866 ms 80792 KB Output is correct
33 Correct 1699 ms 78704 KB Output is correct
34 Correct 2923 ms 80600 KB Output is correct
35 Correct 3477 ms 82004 KB Output is correct
36 Correct 3664 ms 80672 KB Output is correct
37 Correct 1841 ms 78640 KB Output is correct
38 Correct 3498 ms 82244 KB Output is correct
39 Correct 2940 ms 82220 KB Output is correct
40 Correct 3536 ms 82312 KB Output is correct
41 Correct 3495 ms 82340 KB Output is correct
42 Correct 3499 ms 82348 KB Output is correct
43 Correct 2973 ms 12252 KB Output is correct
44 Correct 2958 ms 12416 KB Output is correct
45 Correct 2337 ms 9132 KB Output is correct
46 Correct 2960 ms 12632 KB Output is correct
47 Correct 2976 ms 12612 KB Output is correct
48 Correct 3582 ms 12492 KB Output is correct
49 Correct 3786 ms 12576 KB Output is correct
50 Correct 3753 ms 12476 KB Output is correct
51 Correct 3748 ms 12504 KB Output is correct
52 Correct 3756 ms 19056 KB Output is correct
53 Correct 3643 ms 18372 KB Output is correct
54 Correct 4317 ms 18492 KB Output is correct
55 Correct 4478 ms 18276 KB Output is correct
56 Correct 4455 ms 18308 KB Output is correct
57 Correct 4479 ms 18484 KB Output is correct
58 Correct 2673 ms 14204 KB Output is correct
59 Correct 2687 ms 14284 KB Output is correct
60 Correct 3852 ms 81984 KB Output is correct
61 Correct 4545 ms 82200 KB Output is correct
62 Correct 4513 ms 82080 KB Output is correct
63 Correct 4532 ms 81820 KB Output is correct
64 Correct 1702 ms 8876 KB Output is correct
65 Correct 2001 ms 45052 KB Output is correct
66 Correct 2024 ms 45132 KB Output is correct
67 Correct 3839 ms 68588 KB Output is correct
68 Correct 4200 ms 68712 KB Output is correct
69 Correct 4127 ms 68768 KB Output is correct
70 Correct 4160 ms 68564 KB Output is correct