이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//by szh
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pii pair<int,int>
#define pll pair<long long,long long>
#define pb push_back
#define debug(x) cerr<<#x<<"="<<x<<endl
#define pq priority_queue
#define inf 0x3f
#define rep(i,a,b) for (int i=a;i<(b);i++)
#define MP make_pair
#define SZ(x) (int(x.size()))
#define ll long long
#define mod 1000000007
#define ALL(x) x.begin(),x.end()
void inc(int &a,int b) {a=(a+b)%mod;}
void dec(int &a,int b) {a=(a-b+mod)%mod;}
int lowbit(int x) {return x&(-x);}
ll p0w(ll base,ll p) {ll ret=1;while(p>0){if (p%2ll==1ll) ret=ret*base%mod;base=base*base%mod;p/=2ll;}return ret;}
#include "rail.h"
const int maxn = 1e6+10;;
int dis0[maxn],dis1[maxn],dis2[maxn];
int mark[maxn];
void findLocation(int N, int first, int location[], int stype[])
{
rep(i,0,N) stype[i]=-1;
location[0] = first;
stype[0] = 1;
int pos=1;
rep(i,1,N) {
int tmp = getDistance(i,0);
dis0[i] = tmp;
if (dis0[i]<dis0[pos]) pos=i;
}
location[pos] = first + dis0[pos];
memset(mark,-1,sizeof(mark));
mark[location[0]] = 1;
stype[pos] = 2;
debug(location[pos]);
rep(i,0,N) {
if (i==pos) continue;
dis1[i] = getDistance(i,pos);
}
vector <pii> lft,rit;
rep(i,1,N) if (stype[i]==-1) {
if (dis0[i] == dis1[i] + dis1[0]) {
if (dis1[i]<dis0[pos]) location[i] = location[pos] - dis1[i], stype[i] = 1, mark[location[i]] =1;
else lft.pb({dis1[i],i});
}
else rit.pb({dis0[i],i});
}
sort(ALL(lft));
int cmin = 0;
for (auto itt:lft) {
int it = itt.se;
int hi = getDistance(it,cmin);
// debug(hi);debug(dis1[it]);
int tmp = dis1[cmin] + hi - dis1[it];
tmp/=2;
// debug(location[cmin]+tmp);
if (mark[location[cmin] + tmp]==1) {
stype[it] = 2;
location[it] = location[cmin] + hi;
}
else {
stype[it] = 1, location[it] = location[pos] - dis1[it];
cmin = it;
mark[location[it]] = 1;
}
}
memset(mark,-1,sizeof(mark));
mark[location[pos]] = 1;
sort(ALL(rit));
int dmax = pos;
for (auto itt:rit) {
int it = itt.se;
int hi = getDistance(it,dmax);
int tmp = dis0[dmax] + hi - dis0[it];
tmp/=2;
if (mark[location[dmax] - tmp]==1) {
stype[it] = 1;
location[it] = location[dmax] - hi;
}
else {
stype[it] = 2, location[it] = first + dis0[it];
dmax = it;
mark[location[it]] = 1;
}
}
return;
}
# | 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... |