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 <iostream>
#include <algorithm>
#include <vector>
#define f first
#define s second
#define get getDistance
using namespace std;
long long cur, dis, pos, l, r, mid, xx;
vector<long long> c, d;
vector<pair<long long, long long>> tmp;
pair<long long,long long> dist[5010];
void findLocation(int n, int x, int location[], int stype[])
{
for (int i = 1; i < n; i++) dist[i] = {get(0,i),i};
sort(dist+1,dist+n);
location[0] = x; stype[0] = 1;
location[dist[1].s] = x+dist[1].f; stype[dist[1].s] = 2;
d.push_back(x+dist[1].f);
cur = dist[1].s;
for (int i = 2; i < n; i++) {
dis = get(cur,dist[i].s);
pos = d.back()-dis;
l = 0; r = d.size()-1;
while (l <= r) {
mid = (l+r)/2;
if (pos < d[mid]) r = mid-1;
else l = mid+1;
}
//for (int i = 0; i < d.size(); i++) cout << d[i] << " ";
//cout << endl;
//cout << dist[i].f << " " << dist[i].s << " " << dis << " " << pos << " " << d[l] << endl;
if (dist[i].f == d[l]-x+(d[l]-pos)) {
if (pos < x) tmp.push_back({dist[i].f-dist[1].f*2,dist[i].s});
else location[dist[i].s] = pos, stype[dist[i].s] = 1;
} else {
d.push_back(x+dist[i].f);
cur = dist[i].s;
location[dist[i].s] = x+dist[i].f;
stype[dist[i].s] = 2;
}
}
if (tmp.size()) {
location[tmp[0].s] = x-tmp[0].f; stype[tmp[0].s] = 1;
c.push_back(x-tmp[0].f);
cur = tmp[0].s;
}
for (int i = 1; i < tmp.size(); i++) {
dis = get(cur,tmp[i].s);
pos = c.back()+dis;
l = 0; r = c.size()-1;
while (l <= r) {
mid = (l+r)/2;
if (pos < c[mid]) l = mid+1;
else r = mid-1;
}
if (tmp[i].f == x-c[l]+pos-c[l]) {
location[tmp[i].s] = pos, stype[tmp[i].s] = 2;
} else {
c.push_back(x-tmp[i].f);
cur = tmp[i].s;
location[tmp[i].s] = x-tmp[i].f;
stype[tmp[i].s] = 1;
}
}
}
Compilation message (stderr)
rail.cpp: In function 'void findLocation(int, int, int*, int*)':
rail.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
50 | for (int i = 1; i < tmp.size(); i++) {
| ~~^~~~~~~~~~~~
# | 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... |