# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1027714 |
2024-07-19T09:25:34 Z |
우민규(#10951) |
Sushi (JOI16_sushi) |
C++17 |
|
3937 ms |
82140 KB |
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int bucket = 623;
int n, q;
struct Segment {
vector<int> arr;
priority_queue<int> in_arr;
vector<int> queued;
int push(int x) {
queued.push_back(x);
in_arr.push(x);
auto out = in_arr.top();
in_arr.pop();
return out;
}
void apply() {
// rebuild arr, clear queued, don't modify in_arr
priority_queue<int, vector<int>, greater<int>> in_queue;
for (auto q : queued) in_queue.push(q);
for (auto& a : arr) {
in_queue.push(a);
a = in_queue.top();
in_queue.pop();
}
queued.clear();
}
void build() {
while (!in_arr.empty()) in_arr.pop();
for (auto a : arr) in_arr.push(a);
}
};
void solve() {
cin >> n >> q;
vector<Segment> segments((n + bucket - 1) / bucket);
for (int i = 0; i < n; ++i) {
int x;
cin >> x;
segments[i / bucket].arr.push_back(x);
}
for (auto& s : segments) s.build();
auto query_naive = [&](int l, int r, int b, int p) {
segments[b].apply();
for (int i = l; i < r; ++i) {
if (p < segments[b].arr[i]) {
swap(p, segments[b].arr[i]);
}
}
segments[b].build();
return p;
};
auto query = [&](int s, int t, int p) {
int sb = s / bucket, tb = (t - 1) / bucket;
if (sb == tb) {
return query_naive(s - sb * bucket, t - sb * bucket, sb, p);
}
p = query_naive(s - sb * bucket, bucket, sb, p);
for (int i = sb + 1; i < tb; ++i) {
p = segments[i].push(p);
}
return query_naive(0, t - tb * bucket, tb, p);
};
for (int i = 0; i < q; ++i) {
if (i == 3) {
int x = 3;
}
int s, t, p;
cin >> s >> t >> p;
s -= 1;
// s -> t-1
if (s >= t) {
// s -> N-1, 0 -> t
p = query(s, n, p);
s = 0;
}
cout << query(s, t, p) << "\n";
}
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
while (t--) {
solve();
}
return 0;
}
Compilation message
sushi.cpp: In function 'void solve()':
sushi.cpp:70:11: warning: unused variable 'x' [-Wunused-variable]
70 | int x = 3;
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
548 KB |
Output is correct |
2 |
Correct |
139 ms |
348 KB |
Output is correct |
3 |
Correct |
117 ms |
344 KB |
Output is correct |
4 |
Correct |
113 ms |
540 KB |
Output is correct |
5 |
Correct |
139 ms |
508 KB |
Output is correct |
6 |
Correct |
117 ms |
344 KB |
Output is correct |
7 |
Correct |
41 ms |
344 KB |
Output is correct |
8 |
Correct |
40 ms |
516 KB |
Output is correct |
9 |
Correct |
116 ms |
348 KB |
Output is correct |
10 |
Correct |
135 ms |
348 KB |
Output is correct |
11 |
Correct |
113 ms |
344 KB |
Output is correct |
12 |
Correct |
112 ms |
532 KB |
Output is correct |
13 |
Correct |
129 ms |
540 KB |
Output is correct |
14 |
Correct |
145 ms |
540 KB |
Output is correct |
15 |
Correct |
154 ms |
348 KB |
Output is correct |
16 |
Correct |
52 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1401 ms |
82140 KB |
Output is correct |
2 |
Correct |
1415 ms |
81044 KB |
Output is correct |
3 |
Correct |
876 ms |
79868 KB |
Output is correct |
4 |
Correct |
1533 ms |
81944 KB |
Output is correct |
5 |
Correct |
1004 ms |
82000 KB |
Output is correct |
6 |
Correct |
1597 ms |
81920 KB |
Output is correct |
7 |
Correct |
1558 ms |
82044 KB |
Output is correct |
8 |
Correct |
1398 ms |
81836 KB |
Output is correct |
9 |
Correct |
758 ms |
79840 KB |
Output is correct |
10 |
Correct |
1006 ms |
81224 KB |
Output is correct |
11 |
Correct |
676 ms |
79924 KB |
Output is correct |
12 |
Correct |
898 ms |
81284 KB |
Output is correct |
13 |
Correct |
1314 ms |
81616 KB |
Output is correct |
14 |
Correct |
1319 ms |
81184 KB |
Output is correct |
15 |
Correct |
769 ms |
80008 KB |
Output is correct |
16 |
Correct |
1370 ms |
82088 KB |
Output is correct |
17 |
Correct |
808 ms |
82004 KB |
Output is correct |
18 |
Correct |
1393 ms |
79388 KB |
Output is correct |
19 |
Correct |
1416 ms |
79460 KB |
Output is correct |
20 |
Correct |
1505 ms |
79352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
133 ms |
548 KB |
Output is correct |
2 |
Correct |
139 ms |
348 KB |
Output is correct |
3 |
Correct |
117 ms |
344 KB |
Output is correct |
4 |
Correct |
113 ms |
540 KB |
Output is correct |
5 |
Correct |
139 ms |
508 KB |
Output is correct |
6 |
Correct |
117 ms |
344 KB |
Output is correct |
7 |
Correct |
41 ms |
344 KB |
Output is correct |
8 |
Correct |
40 ms |
516 KB |
Output is correct |
9 |
Correct |
116 ms |
348 KB |
Output is correct |
10 |
Correct |
135 ms |
348 KB |
Output is correct |
11 |
Correct |
113 ms |
344 KB |
Output is correct |
12 |
Correct |
112 ms |
532 KB |
Output is correct |
13 |
Correct |
129 ms |
540 KB |
Output is correct |
14 |
Correct |
145 ms |
540 KB |
Output is correct |
15 |
Correct |
154 ms |
348 KB |
Output is correct |
16 |
Correct |
52 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1401 ms |
82140 KB |
Output is correct |
24 |
Correct |
1415 ms |
81044 KB |
Output is correct |
25 |
Correct |
876 ms |
79868 KB |
Output is correct |
26 |
Correct |
1533 ms |
81944 KB |
Output is correct |
27 |
Correct |
1004 ms |
82000 KB |
Output is correct |
28 |
Correct |
1597 ms |
81920 KB |
Output is correct |
29 |
Correct |
1558 ms |
82044 KB |
Output is correct |
30 |
Correct |
1398 ms |
81836 KB |
Output is correct |
31 |
Correct |
758 ms |
79840 KB |
Output is correct |
32 |
Correct |
1006 ms |
81224 KB |
Output is correct |
33 |
Correct |
676 ms |
79924 KB |
Output is correct |
34 |
Correct |
898 ms |
81284 KB |
Output is correct |
35 |
Correct |
1314 ms |
81616 KB |
Output is correct |
36 |
Correct |
1319 ms |
81184 KB |
Output is correct |
37 |
Correct |
769 ms |
80008 KB |
Output is correct |
38 |
Correct |
1370 ms |
82088 KB |
Output is correct |
39 |
Correct |
808 ms |
82004 KB |
Output is correct |
40 |
Correct |
1393 ms |
79388 KB |
Output is correct |
41 |
Correct |
1416 ms |
79460 KB |
Output is correct |
42 |
Correct |
1505 ms |
79352 KB |
Output is correct |
43 |
Correct |
3421 ms |
8932 KB |
Output is correct |
44 |
Correct |
3308 ms |
8788 KB |
Output is correct |
45 |
Correct |
1797 ms |
8928 KB |
Output is correct |
46 |
Correct |
2969 ms |
13448 KB |
Output is correct |
47 |
Correct |
3140 ms |
13448 KB |
Output is correct |
48 |
Correct |
2662 ms |
13328 KB |
Output is correct |
49 |
Correct |
3185 ms |
13440 KB |
Output is correct |
50 |
Correct |
3181 ms |
13296 KB |
Output is correct |
51 |
Correct |
3464 ms |
13396 KB |
Output is correct |
52 |
Correct |
3501 ms |
20444 KB |
Output is correct |
53 |
Correct |
3152 ms |
15712 KB |
Output is correct |
54 |
Correct |
2958 ms |
15508 KB |
Output is correct |
55 |
Correct |
3811 ms |
15752 KB |
Output is correct |
56 |
Correct |
3937 ms |
15476 KB |
Output is correct |
57 |
Correct |
3684 ms |
15572 KB |
Output is correct |
58 |
Correct |
2064 ms |
11348 KB |
Output is correct |
59 |
Correct |
1687 ms |
11164 KB |
Output is correct |
60 |
Correct |
1419 ms |
79400 KB |
Output is correct |
61 |
Correct |
2000 ms |
79312 KB |
Output is correct |
62 |
Correct |
2110 ms |
79372 KB |
Output is correct |
63 |
Correct |
1959 ms |
79460 KB |
Output is correct |
64 |
Correct |
869 ms |
8784 KB |
Output is correct |
65 |
Correct |
793 ms |
43308 KB |
Output is correct |
66 |
Correct |
796 ms |
43344 KB |
Output is correct |
67 |
Correct |
1740 ms |
66524 KB |
Output is correct |
68 |
Correct |
2217 ms |
66444 KB |
Output is correct |
69 |
Correct |
2244 ms |
66436 KB |
Output is correct |
70 |
Correct |
2284 ms |
66360 KB |
Output is correct |