This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// by me
#include "overtaking.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define all(x) x.begin(), x.end()
const int MOD = 1e9 + 7, SZ = 1e5 + 10, INF = 1e9;
// segment tree v0.2 :skull:
template<typename T> struct segTree{
vector<T> t;
int N;
segTree(int n) : N(1){
while(N < n) N *= 2;
t.assign(N * 2, T());
}
segTree(vector<int> &vec) : segTree(vec.size()){
for(int i = 0; i < vec.size(); i++){
t[i + N] = vec[i];
}
for(int i = N - 1; i > 0; i--){
t[i] = t[i * 2] + t[i * 2 + 1];
}
}
void upd(int i, T val){
i += N;
t[i] = val;
for(i /= 2; i; i /= 2){
t[i] = t[i * 2] + t[i * 2 + 1];
}
}
T get(int l, int r, int i, int from, int to){
if(from > r || to < l){
return T();
}
if(from >= l && to <= r){
return t[i];
}
int mid = (from + to) / 2;
return get(l, r, i * 2, from, mid) + get(l, r, i * 2 + 1, mid + 1, to);
}
T clc(int l, int r){
return get(l, r, 1, 1, N);
}
};
vector<vector<ll>> vec;
vector<int> w, s;
vector<ll> t;
int n, m, x;
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, w = W, s = S, t = T, x = X;
vec.assign(M, vector<ll>(N));
vector<pair<ll, int>> vv(n);
for(int i = 0; i < n; i++){
if(w[i] <= X) continue;
vv[i] = {t[i], w[i]};
}
sort(all(vv));
for(int i = 0; i < n; i++){
vec[0][i] = vv[i].first;
}
for(int j = 1; j < m; j++){
sort(all(vv));
for(int i = 0; i < n; i++){
vv[i].first += 1ll * vv[i].second * (s[j] - s[j - 1]);
if(i){
vv[i].first = max(vv[i].first, vv[i - 1].first);
}
vec[j][i] = vv[i].first;
}
}
// for(int j = 0; j < m; j++){
// for(int i = 0; i < n; i++){
// cout << vec[j][i] << ' ';
// }
// cout << endl;
// }
return;
}
long long arrival_time(long long Y)
{
ll ans = Y;
int idx = lower_bound(all(vec[0]), ans) - vec[0].begin();
if(idx == 0){
return 1ll * x * s[m - 1] + Y;
}
for(int j = 0; j < m; j++){
ll f = 1ll * x * (s[j] - (j ? s[j - 1] : 0));
if(idx && vec[j][idx - 1] > ans + f){
ans = vec[j][idx - 1];
// dif += abs(vec[j][idx - 1] - f - dif);
// f += vec[j][idx - 1] - ans - f;
// ans = vec[j]
}
else ans += f;
// idx = lower_bound(all(vec[j]), ans) - vec[j].begin();
while(idx && vec[j][idx - 1] >= ans) idx--;
}
return ans;
}
// int32_t main(){
// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// int L, N, X, M, Q;
// assert(5 == scanf("%d %d %d %d %d", &L, &N, &X, &M, &Q));
// std::vector<long long> T(N);
// for (int i = 0; i < N; i++)
// assert(1 == scanf("%lld", &T[i]));
// std::vector<int> W(N);
// for (int i = 0; i < N; i++)
// assert(1 == scanf("%d", &W[i]));
// std::vector<int> S(M);
// for (int i = 0; i < M; i++)
// assert(1 == scanf("%d", &S[i]));
// std::vector<long long> Y(Q);
// for (int i = 0; i < Q; i++)
// assert(1 == scanf("%lld", &Y[i]));
//
// // fclose(stdin);
//
// init(L, N, T, W, X, M, S);
// std::vector<long long> res(Q);
// for (int i = 0; i < Q; i++)
// res[i] = arrival_time(Y[i]);
//
// for (int i = 0; i < Q; i++)
// printf("%lld\n", res[i]);
// // fclose(stdout);
// return 0;
// }
// by me
# | 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... |