This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "rail.h"
void findLocation(int n, int LOCATION0, int l[], int stype[]) {
int A, B;
A = 0;
l[A] = LOCATION0;
stype[A] = 1;
if (n == 1) return;
VI order;
if (true) {
VPI tmp;
replr(i, 1, n-1) tmp.pb({getDistance(0, i), i});
sort(all(tmp));
reverse(all(tmp));
B = tmp.back().ss;
l[B] = l[A] + tmp.back().ff;
stype[B] = 2;
tmp.pop_back();
reverse(all(tmp));
for (auto[d, ind] : tmp) order.pb(ind);
}
set<int> D;
D.insert(l[B]);
for (int X : order) {
int AX = getDistance(A, X);
int BX = getDistance(B, X);
l[X] = l[B] - BX;
stype[X] = 1;
if (l[X] < A) {
int p = *D.upper_bound(l[A]);
if (AX == (p-l[X]) + (p-l[A])) goto end;
} else if (l[X] > A) {
int p = *D.upper_bound(l[X]);
if (AX == (p-l[A]) + (p-l[X])) goto end;
}
l[X] = l[A] + AX;
stype[X] = 2;
end:
if (stype[X] == 1) {
if (l[X] < l[A]) A = X;
} else {
D.insert(l[X]);
if (l[X] > l[B]) B = X;
}
}
}
Compilation message (stderr)
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:51:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
51 | for (auto[d, ind] : tmp) order.pb(ind);
| ^
# | 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... |