#ifndef ETHANKIM8683
#include "circus.h"
#endif
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
using I = int;
using Lli = long long int;
/*
Something to note is that jumps may only get
smaller and smaller the closer the performer
gets to the entrance, the inverse is also true.
let a = this rope's distance to the entrance
let b = that rope's distance to the ceiling
let c = that rope's distance to the entrance
`c - a >= b`, therefore `a <= c - b`
The closest rope that satisfies this property
solves the current rope.
*/
const I N = 100000;
const I LOGN = 17;
const I MAX = 1e9;
priority_queue<pair<I, I>> que;
I diss[N];
vector<I> cpss;
I spas[N + 1][LOGN];
I cps(I x) {
return lower_bound(cpss.begin(), cpss.end(), x) - cpss.begin();
}
void cmb(I& a, I b) {
a = min(a, b);
}
void asn(I i, I val) {
cmb(spas[i][0], val);
}
void bld() {
for (I i = 1; i < LOGN; i++)
for (I j = 0; j + (1 << (i - 1)) < cpss.size(); j++)
spas[j][i] = min(spas[j][i - 1], spas[j + (1 << (i - 1))][i - 1]);
}
I qry(I l, I r) {
if (l == r)
return spas[l][0];
const I dis = 31 - __builtin_clz(r - l);
return min(spas[l][dis], spas[r - (1 << dis)][dis]);
}
void init(I n, I m, I p_arr[]) {
fill(&spas[0][0], &spas[0][0] + sizeof(spas) / sizeof(I), MAX);
que.push({m - 0, m});
sort(p_arr, p_arr + n);
I clo = MAX;
for (I i = n - 1; i >= 0; i--) {
const auto p = p_arr[i];
while (!que.empty() && p <= que.top().first) {
const auto [d, a] = que.top();
clo = min(clo, a);
que.pop();
}
que.push({p - (diss[i] = clo - p), p});
}
for (I i = 0; i < n; i++)
cpss.push_back(p_arr[i] - diss[i]);
cpss.push_back(m - 0);
sort(cpss.begin(), cpss.end());
cpss.erase(unique(cpss.begin(), cpss.end()), cpss.end());
for (I i = 0; i < n; i++) {
const I p = p_arr[i];
asn(cps(p - diss[i]), p);
}
asn(cps(m - 0), m);
bld();
}
I minLength(I d) {
return qry(cps(d), cpss.size()) - d;
}
#ifdef ETHANKIM8683
#include <iostream>
#include <cstdio>
I main(void) {
cin.tie(0)->sync_with_stdio(0);
I n, m;
cin >> n >> m;
static I p[N];
for (I i = 0; i < n; i++)
cin >> p[i];
init(n, m, p);
while (true) {
I d = -1;
cin >> d;
if (d == -1)
break;
printf("%i\n", minLength(d));
}
}
#endif
Compilation message
circus.cpp: In function 'void bld()':
circus.cpp:51:38: warning: comparison of integer expressions of different signedness: 'I' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for (I j = 0; j + (1 << (i - 1)) < cpss.size(); j++)
| ~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
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 |
38 ms |
9092 KB |
Output is correct |
2 |
Correct |
38 ms |
9296 KB |
Output is correct |
3 |
Correct |
39 ms |
9136 KB |
Output is correct |
4 |
Correct |
43 ms |
9092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
6868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
6868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
6868 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
9092 KB |
Output is correct |
2 |
Correct |
38 ms |
9296 KB |
Output is correct |
3 |
Correct |
39 ms |
9136 KB |
Output is correct |
4 |
Correct |
43 ms |
9092 KB |
Output is correct |
5 |
Incorrect |
3 ms |
6868 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
38 ms |
9092 KB |
Output is correct |
2 |
Correct |
38 ms |
9296 KB |
Output is correct |
3 |
Correct |
39 ms |
9136 KB |
Output is correct |
4 |
Correct |
43 ms |
9092 KB |
Output is correct |
5 |
Incorrect |
3 ms |
6868 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |