# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
127289 | 2019-07-09T07:53:15 Z | choikiwon | Sushi (JOI16_sushi) | C++17 | 463 ms | 1016 KB |
#include<bits/stdc++.h> using namespace std; const int MN = 100010; const int SQ = 500; const int BS = (MN + SQ - 1) / SQ; int N, Q; int A[MN]; multiset<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++) { auto it = V[bid].begin(); if(it == V[bid].end() || A[i] < *it) continue; int x = *it; V[bid].insert(A[i]); A[i] = x; V[bid].erase(V[bid].find(x)); } V[bid].clear(); X[bid].clear(); for(int i = l; i <= r; i++) X[bid].insert(A[i]); } int proc1(int s, int e, int p) { int bid = s / SQ; prop(bid); X[bid].insert(p); for(int i = s; i <= e; i++) if(A[i] > p) swap(A[i], p); X[bid].erase(X[bid].find(p)); return p; } int proc2(int bid, int v) { V[bid].insert(v); X[bid].insert(v); int mx = *X[bid].rbegin(); X[bid].erase(X[bid].find(mx)); return mx; } int solve(int s, int e, int p) { if(s / SQ == e / SQ) { return proc1(s, e, p); } else { p = proc1(s, (s / SQ + 1) * SQ - 1, p); for(int i = s / SQ + 1; i < e / SQ; i++) p = proc2(i, p); p = proc1(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].insert(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
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 329 ms | 664 KB | Output is correct |
2 | Correct | 329 ms | 560 KB | Output is correct |
3 | Correct | 328 ms | 684 KB | Output is correct |
4 | Correct | 328 ms | 672 KB | Output is correct |
5 | Correct | 328 ms | 540 KB | Output is correct |
6 | Correct | 336 ms | 636 KB | Output is correct |
7 | Correct | 243 ms | 512 KB | Output is correct |
8 | Correct | 246 ms | 516 KB | Output is correct |
9 | Correct | 328 ms | 636 KB | Output is correct |
10 | Correct | 327 ms | 504 KB | Output is correct |
11 | Correct | 288 ms | 684 KB | Output is correct |
12 | Correct | 291 ms | 632 KB | Output is correct |
13 | Correct | 293 ms | 584 KB | Output is correct |
14 | Correct | 463 ms | 680 KB | Output is correct |
15 | Correct | 457 ms | 504 KB | Output is correct |
16 | Correct | 135 ms | 632 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 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 21 ms | 1016 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 329 ms | 664 KB | Output is correct |
2 | Correct | 329 ms | 560 KB | Output is correct |
3 | Correct | 328 ms | 684 KB | Output is correct |
4 | Correct | 328 ms | 672 KB | Output is correct |
5 | Correct | 328 ms | 540 KB | Output is correct |
6 | Correct | 336 ms | 636 KB | Output is correct |
7 | Correct | 243 ms | 512 KB | Output is correct |
8 | Correct | 246 ms | 516 KB | Output is correct |
9 | Correct | 328 ms | 636 KB | Output is correct |
10 | Correct | 327 ms | 504 KB | Output is correct |
11 | Correct | 288 ms | 684 KB | Output is correct |
12 | Correct | 291 ms | 632 KB | Output is correct |
13 | Correct | 293 ms | 584 KB | Output is correct |
14 | Correct | 463 ms | 680 KB | Output is correct |
15 | Correct | 457 ms | 504 KB | Output is correct |
16 | Correct | 135 ms | 632 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 | Execution timed out | 21 ms | 1016 KB | Time limit exceeded (wall clock) |
24 | Halted | 0 ms | 0 KB | - |