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 <utility>
#include <list>
#include <climits>
class Point
{
public:
long long t, w;
int i;
};
struct sort1
{
inline bool operator() (Point const& a, Point const& b)
{
if (a.t == b.t)
return a.w < b.w;
return a.t < b.t;
}
};
struct sort2
{
inline bool operator() (Point const& a, Point const& b)
{
if (a.t == b.t)
return b.w < a.w;
return a.t < b.t;
}
};
int _M;
std::vector<int> _S;
int _X;
std::vector<std::vector<long long>> arr;
std::vector<std::vector<long long>> ans;
void init(int L, int N, std::vector<long long> T, std::vector<int> W, int X, int M, std::vector<int> S)
{
_X = X;
_M = M;
_S = S;
std::vector<Point> TW;
TW.reserve(N);
for (int i = 0; i < N; i++)
{
if (W[i] < X)
continue;
Point p = { T[i], W[i] };
TW.push_back(p);
}
long long mb = 0;
arr = std::vector<std::vector<long long>>(TW.size(), std::vector<long long>(M));
ans = std::vector<std::vector<long long>>(TW.size(), std::vector<long long>(M));
std::sort(TW.begin(), TW.end(), sort1());
for (int i = 0; i < TW.size(); i++)
{
arr[i][0] = TW[i].t;
TW[i].i = i;
}
for (int j = 1; j < M; j++)
{
std::sort(TW.begin(), TW.end(), sort1());
mb = 0;
for (int i = 0; i < TW.size(); i++)
{
long long a = TW[i].t;
long long b = a + (_S[j] - _S[j - 1]) * TW[i].w;
if (b < mb)
b = mb;
else
mb = b;
arr[TW[i].i][j] = b;
TW[i].t = b;
}
}
for (int i = 0; i < TW.size(); i++)
{
ans[i][M-1] = arr[i][M - 1];
}
for (int j = M - 2; j >= 1; j--)
{
std::vector<Point> w;
for (int i = 0; i < TW.size(); i++)
{
w.push_back({ arr[i][j],arr[i][j + 1],i });
}
std::sort(w.begin(), w.end(), sort1());
for (int i = 0; i < TW.size(); i++)
{
ans[i][j] = arr[i][j] + 1LL * (_S[M - 1] - _S[j]) * X;
if (w[0].t < arr[i][j])
{
int l = 0, r = w.size();
while (l < r)
{
int m = (l + r + 1) / 2;
if (w[m].t < arr[i][j])
{
l = m;
}
else
{
r = m - 1;
}
}
int ii = w[l].i;
l = j;
r = arr[ii].size();
while (l < r)
{
int m = (l + r) / 2;
long long c = arr[i][j] + 1LL * (_S[m] - _S[j]) * X;
if (arr[ii][m] < c)
{
l = m + 1;
}
else
{
r = m;
}
}
if (l < arr[ii].size())
{
ans[i][j] = ans[ii][l];
}
}
}
}
}
long long arrival_time(long long Y)
{
long long b = Y + 1LL * _S[_M - 1] * _X;
if (arr.size() == 0)
return b;
int i = 0;
if (arr[0][0] >= Y)
return b;
int l = 0, r = arr.size();
while (l < r)
{
int m = (l + r + 1) / 2;
if (m == arr.size())
{
break;
}
else if (arr[m][0] < Y)
{
l = m;
}
else
{
r = m - 1;
}
}
i = l;
l = 0;
r = arr[i].size();
while (l < r)
{
int m = (l + r) / 2;
long long c = Y + 1LL * _S[m] * _X;
if (arr[i][m] < c)
{
l = m + 1;
}
else
{
r = m;
}
}
if (l == arr[i].size())
return b;
return ans[i][l];
}
Compilation message (stderr)
overtaking.cpp: In function 'void init(int, int, std::vector<long long int>, std::vector<int>, int, int, std::vector<int>)':
overtaking.cpp:60:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
60 | for (int i = 0; i < TW.size(); i++)
| ~~^~~~~~~~~~~
overtaking.cpp:69:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
69 | for (int i = 0; i < TW.size(); i++)
| ~~^~~~~~~~~~~
overtaking.cpp:83:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
83 | for (int i = 0; i < TW.size(); i++)
| ~~^~~~~~~~~~~
overtaking.cpp:90:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
90 | for (int i = 0; i < TW.size(); i++)
| ~~^~~~~~~~~~~
overtaking.cpp:96:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<Point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
96 | for (int i = 0; i < TW.size(); i++)
| ~~^~~~~~~~~~~
overtaking.cpp:131:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | if (l < arr[ii].size())
| ~~^~~~~~~~~~~~~~~~
overtaking.cpp: In function 'long long int arrival_time(long long int)':
overtaking.cpp:155:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
155 | if (m == arr.size())
| ~~^~~~~~~~~~~~~
overtaking.cpp:184:11: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
184 | if (l == arr[i].size())
| ~~^~~~~~~~~~~~~~~~
# | 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... |