# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
597483 |
2022-07-16T06:00:47 Z |
79brue |
Sushi (JOI16_sushi) |
C++17 |
|
8390 ms |
88988 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int LIM = 550;
int n, q;
int arr[400002];
priority_queue<int> exist[2000]; /// 존재하는 수들의 multiset
priority_queue<int, vector<int>, greater<int> > add[2000]; /// 추가될 수들의 multiset
void remakePQ(int g){
int s = g*LIM, e = min(g*LIM+LIM-1, n-1);
while(!add[g].empty()) add[g].pop();
while(!exist[g].empty()) exist[g].pop();
for(int i=s; i<=e; i++) exist[g].push(arr[i]);
}
void resolve(int g){
int s = g*LIM, e = min(g*LIM+LIM-1, n-1);
for(int i=s; i<=e; i++){
add[g].push(arr[i]);
arr[i] = add[g].top();
add[g].pop();
}
remakePQ(g);
}
int solve(int s, int e, int v){ /// s에서 e 사이에 v를 추가한다
int sg = s/LIM, eg = e/LIM;
if(sg == eg){
resolve(sg);
for(int i=s; i<=e; i++){
if(arr[i] > v) swap(arr[i], v);
}
remakePQ(sg);
return v;
}
{ /// sg 처리
resolve(sg);
for(int i=s; i<(sg+1)*LIM; i++) if(arr[i] > v) swap(arr[i], v);
remakePQ(sg);
}
for(int i=sg+1; i<eg; i++){
add[i].push(v);
exist[i].push(v);
v = exist[i].top();
exist[i].pop();
}
{ /// sg 처리
resolve(eg);
for(int i=eg*LIM; i<=e; i++) if(arr[i] > v) swap(arr[i], v);
remakePQ(eg);
}
return v;
}
int main(){
scanf("%d %d", &n, &q);
for(int i=0; i<n; i++){
scanf("%d", &arr[i]);
}
for(int i=0; (i+1)*LIM<n; i++) remakePQ(i);
for(int i=1; i<=q; i++){
int s, e, v;
scanf("%d %d %d", &s, &e, &v);
s--, e--;
if(s<=e) printf("%d\n", solve(s, e, v));
else printf("%d\n", solve(0, e, solve(s, n-1, v)));
}
}
Compilation message
sushi.cpp: In function 'int main()':
sushi.cpp:61:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
61 | scanf("%d %d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~~
sushi.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | scanf("%d", &arr[i]);
| ~~~~~^~~~~~~~~~~~~~~
sushi.cpp:68:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
68 | scanf("%d %d %d", &s, &e, &v);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
296 ms |
440 KB |
Output is correct |
2 |
Correct |
305 ms |
444 KB |
Output is correct |
3 |
Correct |
318 ms |
448 KB |
Output is correct |
4 |
Correct |
293 ms |
584 KB |
Output is correct |
5 |
Correct |
308 ms |
340 KB |
Output is correct |
6 |
Correct |
323 ms |
560 KB |
Output is correct |
7 |
Correct |
122 ms |
436 KB |
Output is correct |
8 |
Correct |
119 ms |
340 KB |
Output is correct |
9 |
Correct |
320 ms |
456 KB |
Output is correct |
10 |
Correct |
295 ms |
572 KB |
Output is correct |
11 |
Correct |
306 ms |
452 KB |
Output is correct |
12 |
Correct |
304 ms |
456 KB |
Output is correct |
13 |
Correct |
325 ms |
572 KB |
Output is correct |
14 |
Correct |
423 ms |
572 KB |
Output is correct |
15 |
Correct |
402 ms |
340 KB |
Output is correct |
16 |
Correct |
132 ms |
460 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4062 ms |
88864 KB |
Output is correct |
2 |
Correct |
4051 ms |
88928 KB |
Output is correct |
3 |
Correct |
1789 ms |
88580 KB |
Output is correct |
4 |
Correct |
3961 ms |
88808 KB |
Output is correct |
5 |
Correct |
3253 ms |
88884 KB |
Output is correct |
6 |
Correct |
4160 ms |
88864 KB |
Output is correct |
7 |
Correct |
4248 ms |
88816 KB |
Output is correct |
8 |
Correct |
4119 ms |
88940 KB |
Output is correct |
9 |
Correct |
1754 ms |
88556 KB |
Output is correct |
10 |
Correct |
3177 ms |
88732 KB |
Output is correct |
11 |
Correct |
1684 ms |
88548 KB |
Output is correct |
12 |
Correct |
3265 ms |
88796 KB |
Output is correct |
13 |
Correct |
3910 ms |
88784 KB |
Output is correct |
14 |
Correct |
4017 ms |
88736 KB |
Output is correct |
15 |
Correct |
1774 ms |
88604 KB |
Output is correct |
16 |
Correct |
3931 ms |
88988 KB |
Output is correct |
17 |
Correct |
3246 ms |
88864 KB |
Output is correct |
18 |
Correct |
4133 ms |
88884 KB |
Output is correct |
19 |
Correct |
4192 ms |
88928 KB |
Output is correct |
20 |
Correct |
4066 ms |
88756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
296 ms |
440 KB |
Output is correct |
2 |
Correct |
305 ms |
444 KB |
Output is correct |
3 |
Correct |
318 ms |
448 KB |
Output is correct |
4 |
Correct |
293 ms |
584 KB |
Output is correct |
5 |
Correct |
308 ms |
340 KB |
Output is correct |
6 |
Correct |
323 ms |
560 KB |
Output is correct |
7 |
Correct |
122 ms |
436 KB |
Output is correct |
8 |
Correct |
119 ms |
340 KB |
Output is correct |
9 |
Correct |
320 ms |
456 KB |
Output is correct |
10 |
Correct |
295 ms |
572 KB |
Output is correct |
11 |
Correct |
306 ms |
452 KB |
Output is correct |
12 |
Correct |
304 ms |
456 KB |
Output is correct |
13 |
Correct |
325 ms |
572 KB |
Output is correct |
14 |
Correct |
423 ms |
572 KB |
Output is correct |
15 |
Correct |
402 ms |
340 KB |
Output is correct |
16 |
Correct |
132 ms |
460 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
4062 ms |
88864 KB |
Output is correct |
24 |
Correct |
4051 ms |
88928 KB |
Output is correct |
25 |
Correct |
1789 ms |
88580 KB |
Output is correct |
26 |
Correct |
3961 ms |
88808 KB |
Output is correct |
27 |
Correct |
3253 ms |
88884 KB |
Output is correct |
28 |
Correct |
4160 ms |
88864 KB |
Output is correct |
29 |
Correct |
4248 ms |
88816 KB |
Output is correct |
30 |
Correct |
4119 ms |
88940 KB |
Output is correct |
31 |
Correct |
1754 ms |
88556 KB |
Output is correct |
32 |
Correct |
3177 ms |
88732 KB |
Output is correct |
33 |
Correct |
1684 ms |
88548 KB |
Output is correct |
34 |
Correct |
3265 ms |
88796 KB |
Output is correct |
35 |
Correct |
3910 ms |
88784 KB |
Output is correct |
36 |
Correct |
4017 ms |
88736 KB |
Output is correct |
37 |
Correct |
1774 ms |
88604 KB |
Output is correct |
38 |
Correct |
3931 ms |
88988 KB |
Output is correct |
39 |
Correct |
3246 ms |
88864 KB |
Output is correct |
40 |
Correct |
4133 ms |
88884 KB |
Output is correct |
41 |
Correct |
4192 ms |
88928 KB |
Output is correct |
42 |
Correct |
4066 ms |
88756 KB |
Output is correct |
43 |
Correct |
6637 ms |
9132 KB |
Output is correct |
44 |
Correct |
6706 ms |
9168 KB |
Output is correct |
45 |
Correct |
3363 ms |
8924 KB |
Output is correct |
46 |
Correct |
6657 ms |
9136 KB |
Output is correct |
47 |
Correct |
6678 ms |
9336 KB |
Output is correct |
48 |
Correct |
6302 ms |
9148 KB |
Output is correct |
49 |
Correct |
6784 ms |
9352 KB |
Output is correct |
50 |
Correct |
6731 ms |
9224 KB |
Output is correct |
51 |
Correct |
6702 ms |
9464 KB |
Output is correct |
52 |
Correct |
8310 ms |
17512 KB |
Output is correct |
53 |
Correct |
8082 ms |
16816 KB |
Output is correct |
54 |
Correct |
7715 ms |
17332 KB |
Output is correct |
55 |
Correct |
8384 ms |
16852 KB |
Output is correct |
56 |
Correct |
8390 ms |
16688 KB |
Output is correct |
57 |
Correct |
8381 ms |
16784 KB |
Output is correct |
58 |
Correct |
4558 ms |
12060 KB |
Output is correct |
59 |
Correct |
3836 ms |
11776 KB |
Output is correct |
60 |
Correct |
4014 ms |
88668 KB |
Output is correct |
61 |
Correct |
4799 ms |
88940 KB |
Output is correct |
62 |
Correct |
4738 ms |
88632 KB |
Output is correct |
63 |
Correct |
4733 ms |
88708 KB |
Output is correct |
64 |
Correct |
2297 ms |
8976 KB |
Output is correct |
65 |
Correct |
3229 ms |
47692 KB |
Output is correct |
66 |
Correct |
3225 ms |
47808 KB |
Output is correct |
67 |
Correct |
6587 ms |
72516 KB |
Output is correct |
68 |
Correct |
7448 ms |
72668 KB |
Output is correct |
69 |
Correct |
7430 ms |
72608 KB |
Output is correct |
70 |
Correct |
7346 ms |
72672 KB |
Output is correct |