#include "circus.h"
#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> p, mn;
deque<pair<int, int>> to_left, to_right;
void init(int N, int M, int P[]) {
for (int i = 0; i < N; i++) p.push_back(P[i]);
sort(p.begin(), p.end());
p.erase(unique(p.begin(), p.end()), p.end());
n = p.size(), m = M;
mn = vector<int>(n, INT_MAX);
for (int i = n - 1; ~i; i--) {
int dist = m - p[i];
auto lb = lower_bound(to_left.begin(), to_left.end(), make_pair(p[i], 0));
if (lb != to_left.end()) dist = min(dist, lb->second - p[i]);
mn[i] = min(mn[i], dist);
while (to_left.size() && p[i] - mn[i] >= to_left[0].first)
to_left.pop_front();
to_left.push_front({p[i] - mn[i], p[i]});
}
to_left.clear();
// for (int i = 0; i < n; i++) cout << mn[i] << ' ';
// cout << '\n';
for (int i = 0; i < n; i++) {
int dist = m - p[i];
auto ub = upper_bound(to_right.begin(), to_right.end(), make_pair(p[i], INT_MAX));
if (ub != to_right.begin()) dist = min(dist, p[i] - prev(ub)->second);
mn[i] = min(mn[i], dist);
while (to_right.size() && p[i] + mn[i] <= to_right.back().first)
to_right.pop_back();
to_right.push_back({p[i] + mn[i], p[i]});
}
to_right.clear();
// for (int i = 0; i < n; i++) cout << mn[i] << ' ';
// cout << '\n';
for (int i = n - 1; ~i; i--) {
int dist = m - p[i];
auto lb = lower_bound(to_left.begin(), to_left.end(), make_pair(p[i], 0));
if (lb != to_left.end()) dist = min(dist, lb->second - p[i]);
mn[i] = min(mn[i], dist);
while (to_left.size() && p[i] - mn[i] >= to_left[0].first)
to_left.pop_front();
to_left.push_front({p[i] - mn[i], p[i]});
}
to_left.clear();
// for (int i = 0; i < n; i++) cout << mn[i] << ' ';
// cout << '\n';
for (int i = 0; i < n; i++)
if (!to_left.size() || p[i] - mn[i] > to_left.back().first)
to_left.push_back({p[i] - mn[i], p[i]});
for (int i = n - 1; ~i; i--)
if (!to_right.size() || p[i] + mn[i] < to_right[0].first)
to_right.push_front({p[i] + mn[i], p[i]});
}
int minLength(int D) {
int ans = m - D;
auto lb = lower_bound(to_left.begin(), to_left.end(), make_pair(D, 0));
if (lb != to_left.end()) ans = min(ans, lb->second - D);
auto ub = upper_bound(to_right.begin(), to_right.end(), make_pair(D, INT_MAX));
if (ub != to_right.begin()) ans = min(ans, D - prev(ub)->second);
return ans;
}
Compilation message
grader.cpp: In function 'int main()':
grader.cpp:14:12: warning: unused variable 'max_code' [-Wunused-variable]
14 | long long max_code;
| ^~~~~~~~
grader.cpp:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
16 | scanf("%d%d", &N, &M);
| ~~~~~^~~~~~~~~~~~~~~~
grader.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
18 | scanf("%d", &P[i]);
| ~~~~~^~~~~~~~~~~~~
grader.cpp:21:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
21 | scanf("%d", &Q);
| ~~~~~^~~~~~~~~~
grader.cpp:23:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
23 | scanf("%d", &d);
| ~~~~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
2660 KB |
Output is correct |
2 |
Correct |
50 ms |
3556 KB |
Output is correct |
3 |
Correct |
50 ms |
3428 KB |
Output is correct |
4 |
Correct |
49 ms |
3428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
2 ms |
364 KB |
Output is correct |
6 |
Correct |
2 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
2 ms |
364 KB |
Output is correct |
9 |
Correct |
471 ms |
8428 KB |
Output is correct |
10 |
Correct |
499 ms |
4972 KB |
Output is correct |
11 |
Correct |
486 ms |
4332 KB |
Output is correct |
12 |
Correct |
516 ms |
9200 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
2660 KB |
Output is correct |
2 |
Correct |
50 ms |
3556 KB |
Output is correct |
3 |
Correct |
50 ms |
3428 KB |
Output is correct |
4 |
Correct |
49 ms |
3428 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
56 ms |
3552 KB |
Output is correct |
14 |
Correct |
52 ms |
3564 KB |
Output is correct |
15 |
Correct |
49 ms |
3300 KB |
Output is correct |
16 |
Correct |
49 ms |
3300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
2660 KB |
Output is correct |
2 |
Correct |
50 ms |
3556 KB |
Output is correct |
3 |
Correct |
50 ms |
3428 KB |
Output is correct |
4 |
Correct |
49 ms |
3428 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
2 ms |
364 KB |
Output is correct |
10 |
Correct |
2 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
471 ms |
8428 KB |
Output is correct |
14 |
Correct |
499 ms |
4972 KB |
Output is correct |
15 |
Correct |
486 ms |
4332 KB |
Output is correct |
16 |
Correct |
516 ms |
9200 KB |
Output is correct |
17 |
Correct |
56 ms |
3552 KB |
Output is correct |
18 |
Correct |
52 ms |
3564 KB |
Output is correct |
19 |
Correct |
49 ms |
3300 KB |
Output is correct |
20 |
Correct |
49 ms |
3300 KB |
Output is correct |
21 |
Correct |
765 ms |
15500 KB |
Output is correct |
22 |
Correct |
794 ms |
15708 KB |
Output is correct |
23 |
Correct |
778 ms |
19044 KB |
Output is correct |
24 |
Correct |
788 ms |
21352 KB |
Output is correct |