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 <bits/stdc++.h>
using namespace std;
#define int long long
#define ff first
#define ss second
set<pair<int, int>> restriction; // if "starts after a", has to "end after b" yk
int x, l;
void init(int32_t L, int32_t N, std::vector<long long> T, std::vector<int32_t> W, int32_t X, int32_t M, std::vector<int32_t> S)
{
x = X; l = L;
vector<vector<pair<int, int>>> restrictions(M);// yes
vector<pair<int, int>> cur;
for (int i = 0; i < N; i++) if (W[i] > X) cur.push_back({ T[i], W[i] - X });
for (int i = 0; i < M-1; i++) {
sort(cur.begin(), cur.end());
vector<pair<int, int>> res;
const int T = cur.size();
for (int j = 0; j < T; j++)
res.push_back({ cur[j].ff + cur[j].ss * (S[i + 1] - S[i]), cur[j].ss });
for (int j = 0; j < T - 1; j++)
if (res[j].ff > res[j + 1].ff)
res[j + 1].ff = res[j].ff;
int p = -1;
for (int j = 0; j < T; j++) {
if(res[j].ff != p){
if(j + 1 == T || cur[j].ff != cur[j+1].ff){
p = res[j].ff;
restrictions[i].push_back({ cur[j].ff+1, res[j].ff }); //start, end
}
}
}
swap(res, cur);
}
for (int i = 0; i < M; i++) {
reverse(restrictions[i].begin(), restrictions[i].end());
for(auto x : restrictions[i]){
//insert x
auto y = restriction.upper_bound(x);
if(restriction.size() == 0) y = restriction.end();
else if(y == restriction.begin()) y = restriction.end();
else y = prev(y);
if(y == restriction.end()){
restriction.insert(x);
continue;
}
if(y->second >= x.second) continue;
int t = x.first;
while(y != restriction.end() && y->second >= x.first){
t = y->first;
auto t = prev(y);
restriction.erase(t);
y = t;
}
restriction.insert({t, x.second});
}
}
return;
}
long long arrival_time(long long Y)
{
auto yes = prev(upper_bound(restriction.begin(), restriction.end(), make_pair( Y, numeric_limits<long long>::max() )));
if (yes != restriction.end()) Y = max(Y, yes->second);
return Y + x * l;
}
# | 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... |