This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define pb push_back
#define ln '\n'
//#define int long long
template <class _T>
bool chmin(_T &x, const _T &y){
bool flag = false;
if ( x > y ){
x = y; flag |= true;
}
return flag;
}
template <class _T>
bool chmax(_T &x, const _T &y){
bool flag = false;
if ( x < y ){
x = y; flag |= true;
}
return flag;
}
vector<int> label(int n, int k, vector<int> u, vector<int> v) {
vector <int> ans(n);
for ( int i = 0; i + 1 < n; i++ ){
if ( u[i] > v[i] ) swap(u[i], v[i]);
assert(u[i] == i / 2 && v[i] == i + 1);
}
for ( int i = 0; i < n; i++ ){
ans[i] = i;
}
return ans;
}
int find_next_station(int s, int t, vector<int> c) {
int bck = -1;
auto in = [&](int s, int t){
int x = __lg(s), y = __lg(t);
if ( x >= y ){
return false;
}
if ( s % 2 == 0 ){
if ( (s + 1) * (1ll << y - x) <= t ){
return false;
}
}
if ( s & 1 ){
if ( s * (1ll << y - x) > t ){
return false;
}
}
if ( (s * 2 + 1) * (1ll << y - x - 1) <= t ){
bck = s * 2 + 1;
} else bck = s * 2;
return true;
};
auto flag = in(s + 1, t + 1);
int res = flag ? bck - 1 : (s - 1) / 2;
assert(binary_search(all(c), res));
return in(s + 1, t + 1) ? bck - 1 : (s - 1) / 2;
}
Compilation message (stderr)
stations.cpp: In lambda function:
stations.cpp:48:38: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
48 | if ( (s + 1) * (1ll << y - x) <= t ){
| ~~^~~
stations.cpp:53:32: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
53 | if ( s * (1ll << y - x) > t ){
| ~~^~~
stations.cpp:57:42: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
57 | if ( (s * 2 + 1) * (1ll << y - x - 1) <= t ){
| ~~~~~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |