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 "overtaking.h"
#include <bits/stdc++.h>
#define MAX 1000001
#define INF LLONG_MAX
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define ins insert
#define ff first
#define ss second
#define gett(x,m) get<m>(x)
#define all(a) a.begin(),a.end()
#define lb(a,b) lower_bound(all(a),b)
#define ub(a,b) upper_bound(all(a),b)
#define sortv(a) sort(all(a))
#define sorta(a,sz) sort(a,a+sz)
#define inputar(a,b){\
for(int i=0;i<b;i++){\
cin >> a[i];\
}\
}
#define inputvec(a,b){\
for(int i=0;i<b;i++){\
ll num;\
cin >> num;\
a.pb(num);\
}\
}
#define outputar(a,b){\
for(int i=0;i<b;i++){\
cout << a[i] << " ";\
}\
cout << "\n";\
}
#define outputvec(a){\
for(auto x:a){\
cout << x << " ";\
}\
cout << "\n";\
}
#define reset(a,n,v){\
for(int i=0;i<n;i++){\
a[i]=v;\
}\
}
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef tuple<ll,ll,ll> tll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef double db;
typedef long double ldb;
ll n,m,q,spd,road_len,b[1001],d[1001];
ll a[1001];
ll e[1001][1001];
vector<pll> g[1001];
ll p[1001][1001];
set<pll> v;
ll get_res(ll x){
pll p1=mp(x,INF);
auto it=v.upper_bound(p1);
if(it!=v.begin()){
--it;
x=max(x,(*it).ss);
}
return x;
}
void upd(ll x,ll y){
pll p1=mp(x,INF);
auto it=v.upper_bound(p1);
if(it!=v.begin() && (*(--it)).ss>=y){
return;
}
v.ins(mp(x,y));
it=v.upper_bound(p1);
while(it!=v.end() && (*it).ss<=y){
v.erase(*it);
it=v.upper_bound(p1);
}
}
void init(int L, int N, std::vector<long long> T, std::vector<int> W, int X, int M, std::vector<int> S)
{
road_len=L;
n=N;
spd=X;
m=M;
for(int i=0;i<n;i++){
a[i]=T[i];
}
// a avtobusların çıxma vaxtı üçün
for(int i=0;i<n;i++){
b[i]=W[i];
}
// b avtobusların sürətləri üçün
for(int i=0;i<m;i++){
d[i]=S[i];
}
// d stansiyalar üçün
// e stansiyalara çatma vaxtı üçün
// p g prefix max üçün
for(int i=0;i<n;i++){
e[i][0]=a[i];
}
for(int j=1;j<m;j++){
vector<pll> f; // avtobusların stansiyaya çatma vaxtına əsasən sıralayıb digər stansiyaya çatma vaxtını o(n)-ə hesablamaq üçün
for(int i=0;i<n;i++){
f.pb(mp(e[i][j-1],i));
}
sortv(f);
g[j-1]=f;
ll h=-1; // digər stansiyaya max çatma vaxtı
int z=0;
while(z<n){
int z1=z;
while(z1<n && f[z1].ff==f[z].ff){
e[f[z1].ss][j]=max(h,f[z1].ff+b[f[z1].ss]*(d[j]-d[j-1]));
z1++;
}
while(z<z1){
h=max(h,e[f[z].ss][j]);
z++;
}
}
}
vector<pll> f;
for(int i=0;i<n;i++){
f.pb(mp(e[i][m-1],i));
}
sortv(f);
g[m-1]=f;
for(int j=0;j<m;j++){
p[0][j]=g[j][0].ff;
for(int i=1;i<n;i++){
p[i][j]=max(p[i-1][j],g[j][i].ff);
}
}
for(int j=m-1;j>0;j--){
vector<pll> v1;
for(int i=0;i<n;i++){
v1.pb(mp(e[i][j-1],get_res(e[i][j]+(d[m-1]-d[j])*spd)));
}
for(auto x:v1){
upd(x.ff+1+(d[m-1]-d[j-1])*spd,x.ss);
}
}
return;
}
long long arrival_time(long long Y)
{
return get_res(Y+d[m-1]*spd);
}
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |