# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
134695 |
2019-07-23T07:32:27 Z |
송준혁(#3242) |
Sushi (JOI16_sushi) |
C++14 |
|
12000 ms |
240728 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
int N, Q, Sq=200;
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);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
632 KB |
Output is correct |
2 |
Correct |
20 ms |
632 KB |
Output is correct |
3 |
Correct |
19 ms |
632 KB |
Output is correct |
4 |
Correct |
20 ms |
632 KB |
Output is correct |
5 |
Correct |
19 ms |
632 KB |
Output is correct |
6 |
Correct |
19 ms |
632 KB |
Output is correct |
7 |
Correct |
17 ms |
504 KB |
Output is correct |
8 |
Correct |
18 ms |
504 KB |
Output is correct |
9 |
Correct |
20 ms |
632 KB |
Output is correct |
10 |
Correct |
20 ms |
632 KB |
Output is correct |
11 |
Correct |
50 ms |
888 KB |
Output is correct |
12 |
Correct |
50 ms |
944 KB |
Output is correct |
13 |
Correct |
40 ms |
888 KB |
Output is correct |
14 |
Correct |
20 ms |
504 KB |
Output is correct |
15 |
Correct |
21 ms |
760 KB |
Output is correct |
16 |
Correct |
9 ms |
636 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
552 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9008 ms |
233772 KB |
Output is correct |
2 |
Correct |
9121 ms |
233708 KB |
Output is correct |
3 |
Correct |
4778 ms |
233200 KB |
Output is correct |
4 |
Correct |
9047 ms |
233608 KB |
Output is correct |
5 |
Correct |
9382 ms |
233784 KB |
Output is correct |
6 |
Correct |
11438 ms |
233808 KB |
Output is correct |
7 |
Correct |
11602 ms |
233520 KB |
Output is correct |
8 |
Correct |
11492 ms |
233612 KB |
Output is correct |
9 |
Correct |
4225 ms |
233208 KB |
Output is correct |
10 |
Correct |
7937 ms |
233680 KB |
Output is correct |
11 |
Correct |
4195 ms |
233376 KB |
Output is correct |
12 |
Correct |
9374 ms |
235264 KB |
Output is correct |
13 |
Correct |
9070 ms |
235480 KB |
Output is correct |
14 |
Correct |
9086 ms |
235220 KB |
Output is correct |
15 |
Correct |
4752 ms |
234256 KB |
Output is correct |
16 |
Correct |
8909 ms |
235404 KB |
Output is correct |
17 |
Correct |
10616 ms |
238112 KB |
Output is correct |
18 |
Correct |
11507 ms |
238148 KB |
Output is correct |
19 |
Correct |
11517 ms |
237836 KB |
Output is correct |
20 |
Correct |
10591 ms |
237988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
632 KB |
Output is correct |
2 |
Correct |
20 ms |
632 KB |
Output is correct |
3 |
Correct |
19 ms |
632 KB |
Output is correct |
4 |
Correct |
20 ms |
632 KB |
Output is correct |
5 |
Correct |
19 ms |
632 KB |
Output is correct |
6 |
Correct |
19 ms |
632 KB |
Output is correct |
7 |
Correct |
17 ms |
504 KB |
Output is correct |
8 |
Correct |
18 ms |
504 KB |
Output is correct |
9 |
Correct |
20 ms |
632 KB |
Output is correct |
10 |
Correct |
20 ms |
632 KB |
Output is correct |
11 |
Correct |
50 ms |
888 KB |
Output is correct |
12 |
Correct |
50 ms |
944 KB |
Output is correct |
13 |
Correct |
40 ms |
888 KB |
Output is correct |
14 |
Correct |
20 ms |
504 KB |
Output is correct |
15 |
Correct |
21 ms |
760 KB |
Output is correct |
16 |
Correct |
9 ms |
636 KB |
Output is correct |
17 |
Correct |
2 ms |
504 KB |
Output is correct |
18 |
Correct |
2 ms |
504 KB |
Output is correct |
19 |
Correct |
2 ms |
504 KB |
Output is correct |
20 |
Correct |
2 ms |
504 KB |
Output is correct |
21 |
Correct |
2 ms |
552 KB |
Output is correct |
22 |
Correct |
2 ms |
504 KB |
Output is correct |
23 |
Correct |
9008 ms |
233772 KB |
Output is correct |
24 |
Correct |
9121 ms |
233708 KB |
Output is correct |
25 |
Correct |
4778 ms |
233200 KB |
Output is correct |
26 |
Correct |
9047 ms |
233608 KB |
Output is correct |
27 |
Correct |
9382 ms |
233784 KB |
Output is correct |
28 |
Correct |
11438 ms |
233808 KB |
Output is correct |
29 |
Correct |
11602 ms |
233520 KB |
Output is correct |
30 |
Correct |
11492 ms |
233612 KB |
Output is correct |
31 |
Correct |
4225 ms |
233208 KB |
Output is correct |
32 |
Correct |
7937 ms |
233680 KB |
Output is correct |
33 |
Correct |
4195 ms |
233376 KB |
Output is correct |
34 |
Correct |
9374 ms |
235264 KB |
Output is correct |
35 |
Correct |
9070 ms |
235480 KB |
Output is correct |
36 |
Correct |
9086 ms |
235220 KB |
Output is correct |
37 |
Correct |
4752 ms |
234256 KB |
Output is correct |
38 |
Correct |
8909 ms |
235404 KB |
Output is correct |
39 |
Correct |
10616 ms |
238112 KB |
Output is correct |
40 |
Correct |
11507 ms |
238148 KB |
Output is correct |
41 |
Correct |
11517 ms |
237836 KB |
Output is correct |
42 |
Correct |
10591 ms |
237988 KB |
Output is correct |
43 |
Correct |
5672 ms |
31508 KB |
Output is correct |
44 |
Correct |
5591 ms |
31656 KB |
Output is correct |
45 |
Correct |
2973 ms |
28620 KB |
Output is correct |
46 |
Correct |
5556 ms |
31944 KB |
Output is correct |
47 |
Correct |
5630 ms |
31712 KB |
Output is correct |
48 |
Correct |
7015 ms |
37460 KB |
Output is correct |
49 |
Correct |
6663 ms |
35904 KB |
Output is correct |
50 |
Correct |
6803 ms |
36180 KB |
Output is correct |
51 |
Correct |
6783 ms |
36364 KB |
Output is correct |
52 |
Correct |
11717 ms |
76576 KB |
Output is correct |
53 |
Correct |
11174 ms |
70184 KB |
Output is correct |
54 |
Correct |
11954 ms |
76068 KB |
Output is correct |
55 |
Correct |
11841 ms |
75164 KB |
Output is correct |
56 |
Correct |
11841 ms |
75420 KB |
Output is correct |
57 |
Correct |
11821 ms |
75740 KB |
Output is correct |
58 |
Correct |
7731 ms |
48100 KB |
Output is correct |
59 |
Correct |
7587 ms |
47692 KB |
Output is correct |
60 |
Correct |
9395 ms |
240728 KB |
Output is correct |
61 |
Correct |
10702 ms |
240064 KB |
Output is correct |
62 |
Correct |
10676 ms |
239956 KB |
Output is correct |
63 |
Correct |
10682 ms |
240428 KB |
Output is correct |
64 |
Correct |
2843 ms |
28688 KB |
Output is correct |
65 |
Correct |
3679 ms |
124444 KB |
Output is correct |
66 |
Correct |
3720 ms |
124452 KB |
Output is correct |
67 |
Correct |
10715 ms |
222616 KB |
Output is correct |
68 |
Execution timed out |
12053 ms |
207372 KB |
Time limit exceeded |
69 |
Halted |
0 ms |
0 KB |
- |