이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "overtaking.h"
#include <bits/stdc++.h>
using namespace std;
long long off = 0;
vector<pair<pair<long long, long long>, long long>> ranges2;
void init(int len, int N, vector<long long> T, vector<int> W, int X, int M, vector<int> S) {
vector<pair<long long, int>> cur_T;
for (int i = 0; i < N; i++) {
if (W[i] > X) {
cur_T.emplace_back(T[i], W[i]);
}
}
vector<pair<long long, long long>> queries;
for (int i = 0; i < M - 1; i++) {
sort(cur_T.begin(), cur_T.end());
vector<pair<long long, int>> nxt_T(cur_T.size());
int start = 0;
long long mx = 0;
int dist = S[i + 1] - S[i];
for (int j = 0; j < (int)cur_T.size(); j++) {
if (j > 0 && cur_T[j].first != cur_T[j - 1].first) {
for (int k = start; k < j; k++) {
mx = max(mx, nxt_T[k].first);
}
start = j;
}
nxt_T[j] = {max(mx, cur_T[j].first + 1LL * cur_T[j].second * dist), cur_T[j].second};
}
for (int j = (int)cur_T.size() - 1; j >= 0; j--) {
queries.emplace_back(cur_T[j].first - off, nxt_T[j].first - off - 1LL * X * dist);
}
off += 1LL * X * dist;
cur_T.swap(nxt_T);
}
set<pair<long long, pair<long long, long long>>> ranges1;
for (auto [A, B]: queries) {
A++;
B--;
if (A > B) {
continue;
}
auto it = ranges1.lower_bound({A, {-1, -1}});
if (it == ranges1.end()) {
ranges1.emplace(B + 1, make_pair(A, B));
continue;
}
long long L = min(it->second.first, A);
long long R = min(B, it->second.first - 1);
while (it->first <= B) {
R = it->second.second;
it = ranges1.erase(it);
if (it == ranges1.end()) {
R = B;
break;
}
if (R < B) {
R = min(B, it->second.first - 1);
}
}
if (L <= R) {
ranges1.emplace(B + 1, make_pair(L, R));
}
}
for (auto [val, pos]: ranges1) {
ranges2.emplace_back(make_pair(pos.second, pos.first), val);
}
}
long long arrival_time(long long Y) {
auto it = lower_bound(ranges2.begin(), ranges2.end(), make_pair(make_pair(Y, -1LL), -1LL));
if (it != ranges2.end() && it->first.second <= Y) {
Y = it->second;
}
Y += off;
return Y;
}
# | 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... |