# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
127420 | 2019-07-09T11:05:14 Z | choikiwon | Sushi (JOI16_sushi) | C++17 | 283 ms | 1920 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]; 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 | 204 ms | 712 KB | Output is correct |
2 | Correct | 204 ms | 504 KB | Output is correct |
3 | Correct | 200 ms | 512 KB | Output is correct |
4 | Correct | 201 ms | 376 KB | Output is correct |
5 | Correct | 202 ms | 504 KB | Output is correct |
6 | Correct | 206 ms | 376 KB | Output is correct |
7 | Correct | 83 ms | 432 KB | Output is correct |
8 | Correct | 84 ms | 376 KB | Output is correct |
9 | Correct | 207 ms | 604 KB | Output is correct |
10 | Correct | 201 ms | 480 KB | Output is correct |
11 | Correct | 208 ms | 376 KB | Output is correct |
12 | Correct | 209 ms | 748 KB | Output is correct |
13 | Correct | 218 ms | 376 KB | Output is correct |
14 | Correct | 283 ms | 376 KB | Output is correct |
15 | Correct | 279 ms | 504 KB | Output is correct |
16 | Correct | 85 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 | Execution timed out | 22 ms | 1920 KB | Time limit exceeded (wall clock) |
2 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 204 ms | 712 KB | Output is correct |
2 | Correct | 204 ms | 504 KB | Output is correct |
3 | Correct | 200 ms | 512 KB | Output is correct |
4 | Correct | 201 ms | 376 KB | Output is correct |
5 | Correct | 202 ms | 504 KB | Output is correct |
6 | Correct | 206 ms | 376 KB | Output is correct |
7 | Correct | 83 ms | 432 KB | Output is correct |
8 | Correct | 84 ms | 376 KB | Output is correct |
9 | Correct | 207 ms | 604 KB | Output is correct |
10 | Correct | 201 ms | 480 KB | Output is correct |
11 | Correct | 208 ms | 376 KB | Output is correct |
12 | Correct | 209 ms | 748 KB | Output is correct |
13 | Correct | 218 ms | 376 KB | Output is correct |
14 | Correct | 283 ms | 376 KB | Output is correct |
15 | Correct | 279 ms | 504 KB | Output is correct |
16 | Correct | 85 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 | Execution timed out | 22 ms | 1920 KB | Time limit exceeded (wall clock) |
24 | Halted | 0 ms | 0 KB | - |