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 "rail.h"
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define forn(i,n) for(int i=0;i<int(n);i++)
#define forsn(i,s,n) for(int i=int(s);i<int(n);i++)
#define fst first
#define snd second
typedef pair<int,int> ii;
const int C = 1, D = 2;
void findLocation(int n, int first, int loc[], int stype[]) {
vector<ii> p(n);
forsn(i,1,n) p[i]={getDistance(0,i),i};
sort(ALL(p));
set<ii> Cs, Ds;
for(auto [d0,i]:p) {
if(Cs.empty()) {
loc[i]=first;
stype[i]=C;
Cs.insert((ii){loc[i],i});
continue;
}
int minC = Cs.begin()->snd;
if(Ds.empty()) {
loc[i]=loc[minC]+d0;
stype[i]=D;
Ds.insert((ii){loc[i],i});
continue;
}
int maxD = Ds.rbegin()->snd;
int distItoC = getDistance(i,minC);
int distItoD = getDistance(maxD,i);
loc[i] = loc[minC] + distItoC;
int target = (loc[i] + loc[maxD] - distItoD)/2;
auto it = Cs.lower_bound((ii){target,0});
if(it != Cs.end() && loc[i] - it->fst + loc[maxD] - it->fst == distItoD) {
stype[i] = D;
Ds.insert((ii){loc[i],i});
continue;
}
loc[i] = loc[maxD] - distItoD;
target = (distItoC + loc[i] + loc[minC])/2;
it = Ds.lower_bound((ii){target,0});
if(it != Ds.end() && it->fst - loc[i] + it->fst - loc[minC] == distItoC) {
stype[i] = C;
Cs.insert((ii){loc[i],i});
continue;
}
loc[i] = loc[minC] + distItoC;
if(d0 == loc[i] - loc[0]) {
stype[i] = D;
Ds.insert((ii){loc[i],i});
} else {
loc[i] = loc[maxD] - distItoD;
stype[i] = C;
Cs.insert((ii){loc[i],i});
}
}
}
Compilation message (stderr)
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:18:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
18 | for(auto [d0,i]:p) {
| ^
# | 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... |