# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1027709 |
2024-07-19T09:23:06 Z |
우민규(#10951) |
Sushi (JOI16_sushi) |
C++17 |
|
12000 ms |
73164 KB |
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
const int bucket = 1;
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();
if (queued.size() > bucket) {
// rebuild this segment
apply();
build();
}
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:75:11: warning: unused variable 'x' [-Wunused-variable]
75 | int x = 3;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
856 KB |
Output is correct |
2 |
Correct |
84 ms |
860 KB |
Output is correct |
3 |
Correct |
94 ms |
860 KB |
Output is correct |
4 |
Correct |
92 ms |
856 KB |
Output is correct |
5 |
Correct |
85 ms |
600 KB |
Output is correct |
6 |
Correct |
88 ms |
848 KB |
Output is correct |
7 |
Correct |
89 ms |
820 KB |
Output is correct |
8 |
Correct |
88 ms |
604 KB |
Output is correct |
9 |
Correct |
114 ms |
860 KB |
Output is correct |
10 |
Correct |
86 ms |
868 KB |
Output is correct |
11 |
Correct |
87 ms |
872 KB |
Output is correct |
12 |
Correct |
93 ms |
860 KB |
Output is correct |
13 |
Correct |
92 ms |
860 KB |
Output is correct |
14 |
Correct |
162 ms |
856 KB |
Output is correct |
15 |
Correct |
162 ms |
876 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
456 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
12063 ms |
73164 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
87 ms |
856 KB |
Output is correct |
2 |
Correct |
84 ms |
860 KB |
Output is correct |
3 |
Correct |
94 ms |
860 KB |
Output is correct |
4 |
Correct |
92 ms |
856 KB |
Output is correct |
5 |
Correct |
85 ms |
600 KB |
Output is correct |
6 |
Correct |
88 ms |
848 KB |
Output is correct |
7 |
Correct |
89 ms |
820 KB |
Output is correct |
8 |
Correct |
88 ms |
604 KB |
Output is correct |
9 |
Correct |
114 ms |
860 KB |
Output is correct |
10 |
Correct |
86 ms |
868 KB |
Output is correct |
11 |
Correct |
87 ms |
872 KB |
Output is correct |
12 |
Correct |
93 ms |
860 KB |
Output is correct |
13 |
Correct |
92 ms |
860 KB |
Output is correct |
14 |
Correct |
162 ms |
856 KB |
Output is correct |
15 |
Correct |
162 ms |
876 KB |
Output is correct |
16 |
Correct |
1 ms |
600 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
456 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Execution timed out |
12063 ms |
73164 KB |
Time limit exceeded |
24 |
Halted |
0 ms |
0 KB |
- |