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 <algorithm>
#include <iostream>
#include <numeric>
#include <cassert>
#include <vector>
typedef long long llong;
const int MAXN = 1000 + 10;
const int MAXQ = 5000 + 10;
int n, m, l, x;
std::vector <int> s;
std::vector <std::pair <llong,int>> buses;
std::vector <std::pair <llong,llong>> t[MAXN];
std::vector <llong> ifBegining[MAXN];
long long my_arrival_time(int pos, llong time)
{
for (int i = pos ; i + 1 < m ; ++i)
{
int l = 0, r = t[i].size(), mid;
while (l < r - 1)
{
mid = l + r >> 1;
if (t[i][mid].first < time) l = mid;
else r = mid;
}
time = std::max(time + 1LL * x * (s[i + 1] - s[i]), t[i][l].second);
}
return time;
}
void init(int L, int N, std::vector <long long> T, std::vector <int> W, int X, int M, std::vector <int> S)
{
n = N;
m = M;
s = S;
x = X;
for (int i = 0 ; i < n ; ++i)
{
buses.push_back({T[i], W[i]});
}
for (int i = 0 ; i + 1 < m ; ++i)
{
t[i].push_back({-1, 0});
std::vector <std::pair <llong,int>> newBuses;
std::sort(buses.begin(), buses.end());
for (const auto &[time, w] : buses)
{
llong arrive = 1LL * (s[i + 1] - s[i]) * w + time;
if (arrive > t[i].back().second)
{
t[i].push_back({time, arrive});
}
newBuses.push_back({t[i].back().second, w});
}
buses = newBuses;
}
for (int i = m - 2 ; i >= 0 ;--i)
{
for (int j = 0 ; j < t[i].size() ; ++j)
{
ifBegining[i].push_back(my_arrival_time(i + 1, t[i][j].second));
}
}
}
long long arrival_time(llong time)
{
for (int i = 0 ; i + 1 < m ; ++i)
{
int l = 0, r = t[i].size(), mid;
while (l < r - 1)
{
mid = l + r >> 1;
if (t[i][mid].first < time) l = mid;
else r = mid;
}
if (l != 0 && time + 1LL * x * (s[i + 1] - s[i]) < t[i][l].second)
{
return ifBegining[i][l];
}
time += 1LL * x * (s[i + 1] - s[i]);
}
return time;
}
Compilation message (stderr)
overtaking.cpp: In function 'long long int my_arrival_time(int, llong)':
overtaking.cpp:25:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
25 | mid = l + r >> 1;
| ~~^~~
overtaking.cpp: In function 'void init(int, int, std::vector<long long int>, std::vector<int>, int, int, std::vector<int>)':
overtaking.cpp:69:28: 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]
69 | for (int j = 0 ; j < t[i].size() ; ++j)
| ~~^~~~~~~~~~~~~
overtaking.cpp: In function 'long long int arrival_time(llong)':
overtaking.cpp:83:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
83 | mid = l + r >> 1;
| ~~^~~
# | 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... |