# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
105717 | 2019-04-14T04:22:06 Z | Pro_ktmr | Sushi (JOI16_sushi) | C++14 | 6059 ms | 82888 KB |
#include"bits/stdc++.h" using namespace std; int N,Q; int X[400000]; int S[25000],T[25000],P[25000]; const int B = 633; priority_queue<int> s[B]; priority_queue<int,vector<int>,greater<int>> memo[B]; int main(){ scanf("%d%d", &N, &Q); for(int i=0; i<N; i++) scanf("%d",X+i); for(int i=0; i<Q; i++){ scanf("%d%d%d", S+i, T+i, P+i); S[i]--; } for(int i=0; i<N; i++) s[i/B].push(X[i]); // for(int q=0; q<Q; q++){ int beginB = S[q] / B; int endB = (T[q] - 1) / B; if(S[q] < T[q]){ while(!s[beginB].empty()) s[beginB].pop(); for(int i=beginB*B; i<(beginB+1)*B && i<N; i++){ memo[beginB].push(X[i]); X[i] = memo[beginB].top(); memo[beginB].pop(); if(S[q] <= i && i < T[q] && X[i] > P[q]){ swap(P[q], X[i]); } s[beginB].push(X[i]); } while(!memo[beginB].empty()) memo[beginB].pop(); for(int i=beginB+1; i<endB; i++){ if(s[i].top() > P[q]){ int tmp = s[i].top(); s[i].pop(); s[i].push(P[q]); memo[i].push(P[q]); P[q] = tmp; } } if(beginB != endB){ while(!s[endB].empty()) s[endB].pop(); for(int i=endB*B; i<(endB+1)*B && i<N; i++){ memo[endB].push(X[i]); X[i] = memo[endB].top(); memo[endB].pop(); if(S[q] <= i && i < T[q] && X[i] > P[q]){ swap(P[q], X[i]); } s[endB].push(X[i]); } while(!memo[endB].empty()) memo[endB].pop(); } } else{ while(!s[beginB].empty()) s[beginB].pop(); for(int i=beginB*B; i<(beginB+1)*B && i<N; i++){ memo[beginB].push(X[i]); X[i] = memo[beginB].top(); memo[beginB].pop(); if(S[q] <= i && X[i] > P[q]){ swap(P[q], X[i]); } s[beginB].push(X[i]); } while(!memo[beginB].empty()) memo[beginB].pop(); for(int i=beginB+1; i<=(N-1)/B; i++){ if(s[i].top() > P[q]){ int tmp = s[i].top(); s[i].pop(); s[i].push(P[q]); memo[i].push(P[q]); P[q] = tmp; } } for(int i=0; i<endB; i++){ if(s[i].top() > P[q]){ int tmp = s[i].top(); s[i].pop(); s[i].push(P[q]); memo[i].push(P[q]); P[q] = tmp; } } while(!s[endB].empty()) s[endB].pop(); for(int i=endB*B; i<(endB+1)*B && i<N; i++){ memo[endB].push(X[i]); X[i] = memo[endB].top(); memo[endB].pop(); if(i < T[q] && X[i] > P[q]){ swap(P[q], X[i]); } s[endB].push(X[i]); } while(!memo[endB].empty()) memo[endB].pop(); } printf("%d\n", P[q]); } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 199 ms | 792 KB | Output is correct |
2 | Correct | 220 ms | 512 KB | Output is correct |
3 | Correct | 205 ms | 552 KB | Output is correct |
4 | Correct | 228 ms | 604 KB | Output is correct |
5 | Correct | 175 ms | 496 KB | Output is correct |
6 | Correct | 214 ms | 512 KB | Output is correct |
7 | Correct | 108 ms | 384 KB | Output is correct |
8 | Correct | 80 ms | 512 KB | Output is correct |
9 | Correct | 182 ms | 552 KB | Output is correct |
10 | Correct | 180 ms | 632 KB | Output is correct |
11 | Correct | 169 ms | 512 KB | Output is correct |
12 | Correct | 178 ms | 656 KB | Output is correct |
13 | Correct | 180 ms | 512 KB | Output is correct |
14 | Correct | 199 ms | 512 KB | Output is correct |
15 | Correct | 209 ms | 640 KB | Output is correct |
16 | Correct | 111 ms | 632 KB | Output is correct |
17 | Correct | 3 ms | 412 KB | Output is correct |
18 | Correct | 2 ms | 320 KB | Output is correct |
19 | Correct | 3 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 3 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5665 ms | 82888 KB | Output is correct |
2 | Correct | 5952 ms | 80996 KB | Output is correct |
3 | Correct | 1060 ms | 6124 KB | Output is correct |
4 | Correct | 6059 ms | 82188 KB | Output is correct |
5 | Correct | 5692 ms | 82144 KB | Output is correct |
6 | Correct | 5688 ms | 82168 KB | Output is correct |
7 | Correct | 5862 ms | 82152 KB | Output is correct |
8 | Correct | 5741 ms | 82144 KB | Output is correct |
9 | Correct | 837 ms | 6084 KB | Output is correct |
10 | Correct | 5422 ms | 76480 KB | Output is correct |
11 | Correct | 772 ms | 6040 KB | Output is correct |
12 | Correct | 5553 ms | 77532 KB | Output is correct |
13 | Correct | 5569 ms | 82652 KB | Output is correct |
14 | Correct | 5692 ms | 81208 KB | Output is correct |
15 | Correct | 1054 ms | 6140 KB | Output is correct |
16 | Correct | 5858 ms | 82336 KB | Output is correct |
17 | Correct | 4952 ms | 82220 KB | Output is correct |
18 | Correct | 5808 ms | 82140 KB | Output is correct |
19 | Correct | 5786 ms | 82260 KB | Output is correct |
20 | Correct | 5601 ms | 82244 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 199 ms | 792 KB | Output is correct |
2 | Correct | 220 ms | 512 KB | Output is correct |
3 | Correct | 205 ms | 552 KB | Output is correct |
4 | Correct | 228 ms | 604 KB | Output is correct |
5 | Correct | 175 ms | 496 KB | Output is correct |
6 | Correct | 214 ms | 512 KB | Output is correct |
7 | Correct | 108 ms | 384 KB | Output is correct |
8 | Correct | 80 ms | 512 KB | Output is correct |
9 | Correct | 182 ms | 552 KB | Output is correct |
10 | Correct | 180 ms | 632 KB | Output is correct |
11 | Correct | 169 ms | 512 KB | Output is correct |
12 | Correct | 178 ms | 656 KB | Output is correct |
13 | Correct | 180 ms | 512 KB | Output is correct |
14 | Correct | 199 ms | 512 KB | Output is correct |
15 | Correct | 209 ms | 640 KB | Output is correct |
16 | Correct | 111 ms | 632 KB | Output is correct |
17 | Correct | 3 ms | 412 KB | Output is correct |
18 | Correct | 2 ms | 320 KB | Output is correct |
19 | Correct | 3 ms | 384 KB | Output is correct |
20 | Correct | 2 ms | 384 KB | Output is correct |
21 | Correct | 3 ms | 384 KB | Output is correct |
22 | Correct | 2 ms | 384 KB | Output is correct |
23 | Correct | 5665 ms | 82888 KB | Output is correct |
24 | Correct | 5952 ms | 80996 KB | Output is correct |
25 | Correct | 1060 ms | 6124 KB | Output is correct |
26 | Correct | 6059 ms | 82188 KB | Output is correct |
27 | Correct | 5692 ms | 82144 KB | Output is correct |
28 | Correct | 5688 ms | 82168 KB | Output is correct |
29 | Correct | 5862 ms | 82152 KB | Output is correct |
30 | Correct | 5741 ms | 82144 KB | Output is correct |
31 | Correct | 837 ms | 6084 KB | Output is correct |
32 | Correct | 5422 ms | 76480 KB | Output is correct |
33 | Correct | 772 ms | 6040 KB | Output is correct |
34 | Correct | 5553 ms | 77532 KB | Output is correct |
35 | Correct | 5569 ms | 82652 KB | Output is correct |
36 | Correct | 5692 ms | 81208 KB | Output is correct |
37 | Correct | 1054 ms | 6140 KB | Output is correct |
38 | Correct | 5858 ms | 82336 KB | Output is correct |
39 | Correct | 4952 ms | 82220 KB | Output is correct |
40 | Correct | 5808 ms | 82140 KB | Output is correct |
41 | Correct | 5786 ms | 82260 KB | Output is correct |
42 | Correct | 5601 ms | 82244 KB | Output is correct |
43 | Correct | 3150 ms | 10292 KB | Output is correct |
44 | Correct | 3351 ms | 10340 KB | Output is correct |
45 | Correct | 1707 ms | 6048 KB | Output is correct |
46 | Correct | 3373 ms | 10356 KB | Output is correct |
47 | Correct | 3372 ms | 10140 KB | Output is correct |
48 | Correct | 4756 ms | 11848 KB | Output is correct |
49 | Correct | 5172 ms | 11716 KB | Output is correct |
50 | Correct | 5062 ms | 11756 KB | Output is correct |
51 | Correct | 5196 ms | 11792 KB | Output is correct |
52 | Correct | 3185 ms | 11136 KB | Output is correct |
53 | Correct | 3200 ms | 10932 KB | Output is correct |
54 | Correct | 4664 ms | 14312 KB | Output is correct |
55 | Correct | 5042 ms | 14364 KB | Output is correct |
56 | Correct | 5305 ms | 14384 KB | Output is correct |
57 | Correct | 4860 ms | 14348 KB | Output is correct |
58 | Correct | 5036 ms | 14660 KB | Output is correct |
59 | Correct | 4889 ms | 14852 KB | Output is correct |
60 | Correct | 5228 ms | 82272 KB | Output is correct |
61 | Correct | 5913 ms | 82304 KB | Output is correct |
62 | Correct | 5780 ms | 82416 KB | Output is correct |
63 | Correct | 5289 ms | 82164 KB | Output is correct |
64 | Correct | 1258 ms | 6148 KB | Output is correct |
65 | Correct | 3465 ms | 43456 KB | Output is correct |
66 | Correct | 3632 ms | 43832 KB | Output is correct |
67 | Correct | 4485 ms | 48916 KB | Output is correct |
68 | Correct | 4765 ms | 49036 KB | Output is correct |
69 | Correct | 4532 ms | 49084 KB | Output is correct |
70 | Correct | 4569 ms | 48876 KB | Output is correct |