Submission #1193693

#TimeUsernameProblemLanguageResultExecution timeMemory
1193693Zbyszek99Overtaking (IOI23_overtaking)C++20
0 / 100
0 ms840 KiB
#include "overtaking.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vi vector<int>
#define vl vector<long long>
#define pb push_back
#define rep(i, b) for(int i = 0; i < (b); ++i)
#define rep2(i,a,b) for(int i = a; i <= (b); ++i)
#define rep3(i,a,b,c) for(int i = a; i <= (b); i+=c)
#define count_bits(x) __builtin_popcountll((x))
#define all(x) (x).begin(),(x).end()
#define siz(x) (int)(x).size()
#define forall(it,x) for(auto& it:(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
mt19937 mt;void random_start(){mt.seed(chrono::time_point_cast<chrono::milliseconds>(chrono::high_resolution_clock::now()).time_since_epoch().count());}
ll los(ll a, ll b) {return a + (mt() % (b-a+1));}
const int INF = 1e9+50;
const ll INF_L = 1e18+40;
const ll MOD = 1e9+7;

ll L;
int n,m;
ll T[1001];
ll W[1001];
ll S[1001];
ll arr_time[1001][1001];
set<pll> end_sets[1001];
ll X;

void init(int L2, int N2, vl T2, vi W2, int X2, int M2, vi S2)
{
    L = L2;
    n = N2;
    rep(i,n) T[i] = T2[i];
    rep(i,n) W[i] = W2[i];
    X = X2;
    m = M2;
    rep(i,m) S[i] = S2[i];
    vector<pll> bus;
    rep(i,n) bus.pb({W[i],T[i]});
    sort(all(bus));
    reverse(all(bus));
    n = 0;
    forall(it,bus)
    {
        if(it.ff <= X) break;
        W[n] = it.ff;
        T[n] = it.ss;
        n++;
    }
    rep(i,n)
    {
        ll time_ = T[i];
        rep(j,m-1)
        {
            arr_time[i][j] = time_;
            auto nxt = end_sets[j].lower_bound({time_,-1e18});
            if(nxt == end_sets[j].begin())
            {
                time_ += W[i] * (S[j+1] - S[j]);
                continue;
            }
            nxt--;
            if((*nxt).ss >= time_ + W[i]*(S[j+1]-S[j]))
            {
                time_ = (*nxt).ss;
            }
            else
            {
                time_ += W[i] * (S[j+1] - S[j]);
            }
        }
        arr_time[i][m-1] = time_;
        rep(j,m-1)
        {
            auto nxt = end_sets[j].lower_bound({arr_time[i][j]+1,-1e18});
            if(nxt == end_sets[j].begin())
            {
                end_sets[j].insert({arr_time[i][j],arr_time[i][j+1]});
                continue;
            }
            nxt--;
            if((*nxt).ss >= arr_time[i][j+1]) continue;
            while(true)
            {
                auto it = end_sets[j].lower_bound({arr_time[i][j],-1e18});
                if(it == end_sets[j].begin()) break;
                it--;
                if((*it).ss <= arr_time[i][j+1])
                {
                    end_sets[j].erase(it);
                }
                else break;
            }
            end_sets[j].insert({arr_time[i][j],arr_time[i][j+1]});
        }
    }
    return;
}

ll arrival_time(ll time_)
{
    int cur_stop = 0;
    while(cur_stop != m-1)
    {
        pair<ld,int> com = {1e18,-1};
        rep(i,n)
        {
            ld c = (ld)(-(S[cur_stop] - time_ * (ld)1/(ld)X) + (S[cur_stop] - arr_time[i][cur_stop] * (ld)1/(ld)W[i])) * (ld)(X * W[i])/(ld)(W[i]-X);
            if(c > time_)
            {
                com = min(com,{c,i});
            }
        }
        if(com.ss == -1)
        {
            time_ += (S[m-1] - S[cur_stop]) * X;
            return time_;
        }
        ll poz = (ld)(com.ff - time_) * (ld)1/(ld)X + S[cur_stop];
        int l = cur_stop;
        int r = m-1;
        int ans = -1;
        while(l <= r)
        {
            int mid = (l+r)/2;
            if(S[mid] < poz)
            {
                ans = mid;
                l = mid+1;
            }
            else
            {
                r = mid-1;
            }
        }
        if(ans == m-1)
        {
            time_ += (S[m-1] - S[cur_stop]) * X;
            return time_;
        }
        time_ = arr_time[com.ss][ans+1];
        cur_stop = ans+1;
    }
    return time_;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...