# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
127423 | 2019-07-09T11:08:57 Z | choikiwon | Sushi (JOI16_sushi) | C++17 | 8960 ms | 100212 KB |
#include<bits/stdc++.h> using namespace std; const int MN = 400010; const int SQ = 500; const int BS = (MN + SQ - 1) / SQ; int N, Q; int A[MN]; priority_queue<int> V[BS], X[BS]; void prop(int bid) { int l = bid * SQ; int r = min(N - 1, l + SQ - 1); for(int i = l; i <= r; i++) { if(V[bid].empty() || -V[bid].top() >= A[i]) continue; V[bid].push(-A[i]); A[i] = -V[bid].top(); V[bid].pop(); } while(!V[bid].empty()) V[bid].pop(); while(!X[bid].empty()) X[bid].pop(); } int go1(int s, int e, int p) { int bid = s / SQ; int l = bid * SQ; int r = min(N - 1, l + SQ - 1); prop(bid); for(int i = s; i <= e; i++) if(A[i] > p) swap(A[i], p); for(int i = l; i <= r; i++) X[bid].push(A[i]); return p; } int go2(int bid, int p) { V[bid].push(-p); X[bid].push(p); int mx = X[bid].top(); X[bid].pop(); return mx; } int solve(int s, int e, int p) { if(s / SQ == e / SQ) { return go1(s, e, p); } else { p = go1(s, (s / SQ + 1) * SQ - 1, p); for(int i = s / SQ + 1; i < e / SQ; i++) p = go2(i, p); p = go1(e / SQ * SQ, e, p); return p; } } int main() { scanf("%d %d", &N, &Q); for(int i = 0; i < N; i++) { scanf("%d", &A[i]); } for(int i = 0; i < N; i++) { X[i / SQ].push(A[i]); } for(int i = 0; i < Q; i++) { int s, e, p; scanf("%d %d %d", &s, &e, &p); s--; e--; if(s <= e) { printf("%d\n", solve(s, e, p)); } else { p = solve(s, N - 1, p); printf("%d\n", solve(0, e, p)); } } }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 203 ms | 632 KB | Output is correct |
2 | Correct | 202 ms | 504 KB | Output is correct |
3 | Correct | 201 ms | 504 KB | Output is correct |
4 | Correct | 202 ms | 508 KB | Output is correct |
5 | Correct | 202 ms | 512 KB | Output is correct |
6 | Correct | 205 ms | 632 KB | Output is correct |
7 | Correct | 84 ms | 504 KB | Output is correct |
8 | Correct | 84 ms | 504 KB | Output is correct |
9 | Correct | 205 ms | 504 KB | Output is correct |
10 | Correct | 203 ms | 496 KB | Output is correct |
11 | Correct | 205 ms | 640 KB | Output is correct |
12 | Correct | 215 ms | 632 KB | Output is correct |
13 | Correct | 217 ms | 504 KB | Output is correct |
14 | Correct | 282 ms | 736 KB | Output is correct |
15 | Correct | 280 ms | 632 KB | Output is correct |
16 | Correct | 85 ms | 512 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 | 380 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 | 6031 ms | 99616 KB | Output is correct |
2 | Correct | 6119 ms | 98560 KB | Output is correct |
3 | Correct | 2707 ms | 96376 KB | Output is correct |
4 | Correct | 6091 ms | 100100 KB | Output is correct |
5 | Correct | 5098 ms | 100084 KB | Output is correct |
6 | Correct | 6193 ms | 100044 KB | Output is correct |
7 | Correct | 6185 ms | 99984 KB | Output is correct |
8 | Correct | 6179 ms | 100040 KB | Output is correct |
9 | Correct | 2430 ms | 96460 KB | Output is correct |
10 | Correct | 5185 ms | 98560 KB | Output is correct |
11 | Correct | 2418 ms | 96384 KB | Output is correct |
12 | Correct | 5138 ms | 98516 KB | Output is correct |
13 | Correct | 6074 ms | 99928 KB | Output is correct |
14 | Correct | 6085 ms | 98512 KB | Output is correct |
15 | Correct | 2715 ms | 96660 KB | Output is correct |
16 | Correct | 6065 ms | 100000 KB | Output is correct |
17 | Correct | 5070 ms | 99972 KB | Output is correct |
18 | Correct | 6184 ms | 99960 KB | Output is correct |
19 | Correct | 6225 ms | 99916 KB | Output is correct |
20 | Correct | 6101 ms | 100104 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 203 ms | 632 KB | Output is correct |
2 | Correct | 202 ms | 504 KB | Output is correct |
3 | Correct | 201 ms | 504 KB | Output is correct |
4 | Correct | 202 ms | 508 KB | Output is correct |
5 | Correct | 202 ms | 512 KB | Output is correct |
6 | Correct | 205 ms | 632 KB | Output is correct |
7 | Correct | 84 ms | 504 KB | Output is correct |
8 | Correct | 84 ms | 504 KB | Output is correct |
9 | Correct | 205 ms | 504 KB | Output is correct |
10 | Correct | 203 ms | 496 KB | Output is correct |
11 | Correct | 205 ms | 640 KB | Output is correct |
12 | Correct | 215 ms | 632 KB | Output is correct |
13 | Correct | 217 ms | 504 KB | Output is correct |
14 | Correct | 282 ms | 736 KB | Output is correct |
15 | Correct | 280 ms | 632 KB | Output is correct |
16 | Correct | 85 ms | 512 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 | 380 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 2 ms | 376 KB | Output is correct |
23 | Correct | 6031 ms | 99616 KB | Output is correct |
24 | Correct | 6119 ms | 98560 KB | Output is correct |
25 | Correct | 2707 ms | 96376 KB | Output is correct |
26 | Correct | 6091 ms | 100100 KB | Output is correct |
27 | Correct | 5098 ms | 100084 KB | Output is correct |
28 | Correct | 6193 ms | 100044 KB | Output is correct |
29 | Correct | 6185 ms | 99984 KB | Output is correct |
30 | Correct | 6179 ms | 100040 KB | Output is correct |
31 | Correct | 2430 ms | 96460 KB | Output is correct |
32 | Correct | 5185 ms | 98560 KB | Output is correct |
33 | Correct | 2418 ms | 96384 KB | Output is correct |
34 | Correct | 5138 ms | 98516 KB | Output is correct |
35 | Correct | 6074 ms | 99928 KB | Output is correct |
36 | Correct | 6085 ms | 98512 KB | Output is correct |
37 | Correct | 2715 ms | 96660 KB | Output is correct |
38 | Correct | 6065 ms | 100000 KB | Output is correct |
39 | Correct | 5070 ms | 99972 KB | Output is correct |
40 | Correct | 6184 ms | 99960 KB | Output is correct |
41 | Correct | 6225 ms | 99916 KB | Output is correct |
42 | Correct | 6101 ms | 100104 KB | Output is correct |
43 | Correct | 4986 ms | 13100 KB | Output is correct |
44 | Correct | 4980 ms | 13096 KB | Output is correct |
45 | Correct | 2665 ms | 9528 KB | Output is correct |
46 | Correct | 5036 ms | 13088 KB | Output is correct |
47 | Correct | 5019 ms | 13124 KB | Output is correct |
48 | Correct | 6210 ms | 13272 KB | Output is correct |
49 | Correct | 6545 ms | 13056 KB | Output is correct |
50 | Correct | 6487 ms | 13008 KB | Output is correct |
51 | Correct | 6579 ms | 13248 KB | Output is correct |
52 | Correct | 8193 ms | 22420 KB | Output is correct |
53 | Correct | 7846 ms | 21648 KB | Output is correct |
54 | Correct | 8657 ms | 21752 KB | Output is correct |
55 | Correct | 8960 ms | 21664 KB | Output is correct |
56 | Correct | 8957 ms | 21928 KB | Output is correct |
57 | Correct | 8940 ms | 21892 KB | Output is correct |
58 | Correct | 4850 ms | 15816 KB | Output is correct |
59 | Correct | 4922 ms | 15916 KB | Output is correct |
60 | Correct | 5174 ms | 100212 KB | Output is correct |
61 | Correct | 6065 ms | 99912 KB | Output is correct |
62 | Correct | 6134 ms | 99824 KB | Output is correct |
63 | Correct | 6116 ms | 99976 KB | Output is correct |
64 | Correct | 1994 ms | 9648 KB | Output is correct |
65 | Correct | 3438 ms | 53776 KB | Output is correct |
66 | Correct | 3471 ms | 53768 KB | Output is correct |
67 | Correct | 7989 ms | 82612 KB | Output is correct |
68 | Correct | 8594 ms | 82524 KB | Output is correct |
69 | Correct | 8704 ms | 82572 KB | Output is correct |
70 | Correct | 8569 ms | 82448 KB | Output is correct |