이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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;
VI dist0(n);
if (true) {
VPI tmp;
replr(i, 1, n-1) tmp.pb({dist0[i] = 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> C, D;
C.insert(l[A]);
D.insert(l[B]);
for (int X : order) {
/*cout << "PROCESSING " << X << endl;*/
/*cout << "A, B: " << A << ", " << B << endl;*/
int AX = getDistance(A, X);
int BX = getDistance(B, X);
l[X] = l[B] - BX;
stype[X] = 1;
if (l[X] != l[A]) {
int p = *D.upper_bound(max(l[A], l[X]));
if (AX == (p-l[X]) + (p-l[A])) goto end;
}
l[X] = l[A] + AX;
stype[X] = 2;
if (l[X] != l[B]) {
int p = *prev(C.lower_bound(min(l[B], l[X])));
if (BX == (l[X]-p) + (l[B]-p)) goto end;
}
/*cout << "VAX QU" << endl;*/
/*cout << "VAX QUUUUUUUUU" << endl;*/
/*cout << AX << " = (" << l[0] << " - " << l[A] << ") + " << dist0[X] << endl;*/
if (AX == (l[0]-l[A]) + dist0[X]) {
l[X] = l[A] + AX;
stype[X] = 2;
} else {
l[X] = l[B] - BX;
stype[X] = 1;
}
end:
if (stype[X] == 1) {
C.insert(l[X]);
if (l[X] < l[A]) A = X;
} else {
D.insert(l[X]);
if (l[X] > l[B]) B = X;
}
/*cout << "TYPE: " << stype[X] << endl;*/
/*cout << "LOCATION: " << l[X] << endl;*/
/*cout << endl;*/
}
}
# | 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... |