# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
134708 |
2019-07-23T07:40:15 Z |
송준혁(#3242) |
Sushi (JOI16_sushi) |
C++14 |
|
11065 ms |
205856 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int N, Q, Sq=230;
int A[404040];
priority_queue<int> D[2020], P[2020];
priority_queue<int, vector<int>, greater<int>> C[2020];
int main(){
scanf("%d %d", &N, &Q);
for (int i=1; i<=N; i++){
scanf("%d", &A[i]);
D[i/Sq].push(A[i]);
}
while (Q--){
int S, T, X;
scanf("%d %d %d", &S, &T, &X);
int p = S/Sq, q = T/Sq;
for (int i=max(1,p*Sq); i<min((p+1)*Sq, N+1); i++) C[p].push(A[i]), A[i] = C[p].top(), C[p].pop();
while (!C[p].empty()) C[p].pop();
for (int i=max(1,q*Sq); i<min((q+1)*Sq, N+1); i++) C[q].push(A[i]), A[i] = C[q].top(), C[q].pop();
while (!C[q].empty()) C[q].pop();
if (S <= T){
for (int i=S; i<min((p+1)*Sq, T+1); i++) if (X < A[i]) {
while (!P[p].empty() && D[p].top() == P[p].top()) D[p].pop(), P[p].pop();
P[p].push(A[i]), swap(A[i], X), D[p].push(A[i]);
}
for (p++; p<q; p++) {
while (!P[p].empty() && D[p].top() == P[p].top()) D[p].pop(), P[p].pop();
C[p].push(X), D[p].push(X);
X = D[p].top(), D[p].pop();
}
for (int i=max(S,q*Sq); i<=T; i++) if (X < A[i]) {
while (!P[q].empty() && D[q].top() == P[q].top()) D[q].pop(), P[q].pop();
P[q].push(A[i]), swap(A[i], X), D[q].push(A[i]);
}
}
else{
for (int i=S; i<min((p+1)*Sq, N+1); i++) if (X < A[i]) {
while (!P[p].empty() && D[p].top() == P[p].top()) D[p].pop(), P[p].pop();
P[p].push(A[i]), swap(A[i], X), D[p].push(A[i]);
}
for (p++; p<=N/Sq; p++) {
while (!P[p].empty() && D[p].top() == P[p].top()) D[p].pop(), P[p].pop();
C[p].push(X), D[p].push(X);
X = D[p].top(), D[p].pop();
}
for (p=0; p<q; p++) {
while (!P[p].empty() && D[p].top() == P[p].top()) D[p].pop(), P[p].pop();
C[p].push(X), D[p].push(X);
X = D[p].top(), D[p].pop();
}
for (int i=max(1,q*Sq); i<=T; i++) if (X < A[i]) {
while (!P[q].empty() && D[q].top() == P[q].top()) D[q].pop(), P[q].pop();
P[q].push(A[i]), swap(A[i], X), D[q].push(A[i]);
}
}
printf("%d\n", X);
}
return 0;
}
/*
7 100
13
90
35
60
38
64
83
1 4 33
7 1 14
4 5 47
1 7 82
6 1 93
6 5 56
*/
Compilation message
sushi.cpp: In function 'int main()':
sushi.cpp:12:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &Q);
~~~~~^~~~~~~~~~~~~~~~~
sushi.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &A[i]);
~~~~~^~~~~~~~~~~~~
sushi.cpp:19:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &S, &T, &X);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
632 KB |
Output is correct |
2 |
Correct |
20 ms |
632 KB |
Output is correct |
3 |
Correct |
20 ms |
632 KB |
Output is correct |
4 |
Correct |
21 ms |
760 KB |
Output is correct |
5 |
Correct |
20 ms |
632 KB |
Output is correct |
6 |
Correct |
20 ms |
632 KB |
Output is correct |
7 |
Correct |
18 ms |
504 KB |
Output is correct |
8 |
Correct |
18 ms |
504 KB |
Output is correct |
9 |
Correct |
21 ms |
632 KB |
Output is correct |
10 |
Correct |
20 ms |
632 KB |
Output is correct |
11 |
Correct |
56 ms |
1016 KB |
Output is correct |
12 |
Correct |
54 ms |
1076 KB |
Output is correct |
13 |
Correct |
43 ms |
888 KB |
Output is correct |
14 |
Correct |
21 ms |
632 KB |
Output is correct |
15 |
Correct |
22 ms |
632 KB |
Output is correct |
16 |
Correct |
10 ms |
760 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
508 KB |
Output is correct |
19 |
Correct |
2 ms |
508 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7739 ms |
203864 KB |
Output is correct |
2 |
Correct |
7913 ms |
203416 KB |
Output is correct |
3 |
Correct |
3983 ms |
203156 KB |
Output is correct |
4 |
Correct |
7857 ms |
203896 KB |
Output is correct |
5 |
Correct |
8589 ms |
203824 KB |
Output is correct |
6 |
Correct |
9531 ms |
203800 KB |
Output is correct |
7 |
Correct |
9507 ms |
203624 KB |
Output is correct |
8 |
Correct |
9466 ms |
203648 KB |
Output is correct |
9 |
Correct |
3581 ms |
203220 KB |
Output is correct |
10 |
Correct |
6947 ms |
203328 KB |
Output is correct |
11 |
Correct |
3604 ms |
203288 KB |
Output is correct |
12 |
Correct |
7028 ms |
203540 KB |
Output is correct |
13 |
Correct |
7808 ms |
203776 KB |
Output is correct |
14 |
Correct |
7967 ms |
203224 KB |
Output is correct |
15 |
Correct |
4019 ms |
203224 KB |
Output is correct |
16 |
Correct |
7856 ms |
203908 KB |
Output is correct |
17 |
Correct |
8562 ms |
203860 KB |
Output is correct |
18 |
Correct |
9505 ms |
203756 KB |
Output is correct |
19 |
Correct |
9490 ms |
203920 KB |
Output is correct |
20 |
Correct |
9432 ms |
204040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
21 ms |
632 KB |
Output is correct |
2 |
Correct |
20 ms |
632 KB |
Output is correct |
3 |
Correct |
20 ms |
632 KB |
Output is correct |
4 |
Correct |
21 ms |
760 KB |
Output is correct |
5 |
Correct |
20 ms |
632 KB |
Output is correct |
6 |
Correct |
20 ms |
632 KB |
Output is correct |
7 |
Correct |
18 ms |
504 KB |
Output is correct |
8 |
Correct |
18 ms |
504 KB |
Output is correct |
9 |
Correct |
21 ms |
632 KB |
Output is correct |
10 |
Correct |
20 ms |
632 KB |
Output is correct |
11 |
Correct |
56 ms |
1016 KB |
Output is correct |
12 |
Correct |
54 ms |
1076 KB |
Output is correct |
13 |
Correct |
43 ms |
888 KB |
Output is correct |
14 |
Correct |
21 ms |
632 KB |
Output is correct |
15 |
Correct |
22 ms |
632 KB |
Output is correct |
16 |
Correct |
10 ms |
760 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
508 KB |
Output is correct |
19 |
Correct |
2 ms |
508 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
504 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
7739 ms |
203864 KB |
Output is correct |
24 |
Correct |
7913 ms |
203416 KB |
Output is correct |
25 |
Correct |
3983 ms |
203156 KB |
Output is correct |
26 |
Correct |
7857 ms |
203896 KB |
Output is correct |
27 |
Correct |
8589 ms |
203824 KB |
Output is correct |
28 |
Correct |
9531 ms |
203800 KB |
Output is correct |
29 |
Correct |
9507 ms |
203624 KB |
Output is correct |
30 |
Correct |
9466 ms |
203648 KB |
Output is correct |
31 |
Correct |
3581 ms |
203220 KB |
Output is correct |
32 |
Correct |
6947 ms |
203328 KB |
Output is correct |
33 |
Correct |
3604 ms |
203288 KB |
Output is correct |
34 |
Correct |
7028 ms |
203540 KB |
Output is correct |
35 |
Correct |
7808 ms |
203776 KB |
Output is correct |
36 |
Correct |
7967 ms |
203224 KB |
Output is correct |
37 |
Correct |
4019 ms |
203224 KB |
Output is correct |
38 |
Correct |
7856 ms |
203908 KB |
Output is correct |
39 |
Correct |
8562 ms |
203860 KB |
Output is correct |
40 |
Correct |
9505 ms |
203756 KB |
Output is correct |
41 |
Correct |
9490 ms |
203920 KB |
Output is correct |
42 |
Correct |
9432 ms |
204040 KB |
Output is correct |
43 |
Correct |
5109 ms |
23496 KB |
Output is correct |
44 |
Correct |
5056 ms |
23752 KB |
Output is correct |
45 |
Correct |
2619 ms |
21768 KB |
Output is correct |
46 |
Correct |
5038 ms |
23520 KB |
Output is correct |
47 |
Correct |
5046 ms |
23532 KB |
Output is correct |
48 |
Correct |
6424 ms |
28564 KB |
Output is correct |
49 |
Correct |
6185 ms |
26180 KB |
Output is correct |
50 |
Correct |
6218 ms |
26380 KB |
Output is correct |
51 |
Correct |
6287 ms |
26640 KB |
Output is correct |
52 |
Correct |
10242 ms |
58924 KB |
Output is correct |
53 |
Correct |
9767 ms |
54568 KB |
Output is correct |
54 |
Correct |
10596 ms |
60240 KB |
Output is correct |
55 |
Correct |
10563 ms |
58336 KB |
Output is correct |
56 |
Correct |
10588 ms |
59096 KB |
Output is correct |
57 |
Correct |
10617 ms |
58188 KB |
Output is correct |
58 |
Correct |
7361 ms |
37540 KB |
Output is correct |
59 |
Correct |
5971 ms |
35760 KB |
Output is correct |
60 |
Correct |
8221 ms |
205856 KB |
Output is correct |
61 |
Correct |
9441 ms |
205128 KB |
Output is correct |
62 |
Correct |
9377 ms |
205128 KB |
Output is correct |
63 |
Correct |
9394 ms |
205004 KB |
Output is correct |
64 |
Correct |
2462 ms |
22228 KB |
Output is correct |
65 |
Correct |
3258 ms |
105768 KB |
Output is correct |
66 |
Correct |
3215 ms |
105836 KB |
Output is correct |
67 |
Correct |
9288 ms |
190244 KB |
Output is correct |
68 |
Correct |
10987 ms |
186300 KB |
Output is correct |
69 |
Correct |
10888 ms |
191280 KB |
Output is correct |
70 |
Correct |
11065 ms |
192920 KB |
Output is correct |