Submission #1031998

#TimeUsernameProblemLanguageResultExecution timeMemory
1031998GrindMachineOvertaking (IOI23_overtaking)C++17
65 / 100
3536 ms47700 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pb push_back
#define endl '\n'
#define sz(a) (int)a.size()
#define setbits(x) __builtin_popcountll(x)
#define ff first
#define ss second
#define conts continue
#define ceil2(x,y) ((x+y-1)/(y))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define yes cout << "Yes" << endl
#define no cout << "No" << endl

#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep1(i,n) for(int i = 1; i <= n; ++i)
#define rev(i,s,e) for(int i = s; i >= e; --i)
#define trav(i,a) for(auto &i : a)

template<typename T>
void amin(T &a, T b) {
    a = min(a,b);
}

template<typename T>
void amax(T &a, T b) {
    a = max(a,b);
}

#ifdef LOCAL
#include "debug.h"
#else
#define debug(x) 42
#endif

/*

already knew some key ideas

*/

const int MOD = 1e9 + 7;
const int N = 1e3 + 5;
const int inf1 = int(1e9) + 5;
const ll inf2 = ll(1e18) + 5;

#include "overtaking.h"

vector<ll> T;
vector<int> W,S;
ll X,m;
vector<ll> tim[N], pmx[N];

void init(int L, int n, std::vector<long long> T_, std::vector<int> W_, int X_, int M, std::vector<int> S_)
{
    T = T_, W = W_, S = S_;
    X = X_, m = M;

    ll e[n][m], t[n][m];
    rep(i,n){
        e[i][0] = t[i][0] = T[i];
    }

    rep1(j,m-1){
        rep(i,n){
            e[i][j] = t[i][j-1]+(ll)W[i]*(S[j]-S[j-1]);
            t[i][j] = e[i][j];
        }

        vector<pll> ord;
        rep(i,n){
            ord.pb({t[i][j-1],i});
        }

        sort(all(ord));
        ll ptr = 0, mx = 0;

        rep(i,n){
            while(ptr < n and ord[ptr].ff < ord[i].ff){
                amax(mx,e[ord[ptr].ss][j]);
                ptr++;
            }

            amax(t[ord[i].ss][j],mx);
        }

        mx = 0;
        rep(i,n){
            tim[j-1].pb(ord[i].ff);
            amax(mx,t[ord[i].ss][j]);
            pmx[j-1].pb(mx);
        }
    }

    {
        ll j = m;

        vector<pll> ord;
        rep(i,n){
            ord.pb({t[i][j-1],i});
        }

        sort(all(ord));

        ll mx = 0;
        rep(i,n){
            tim[j-1].pb(ord[i].ff);
            amax(mx,t[ord[i].ss][j]);
            pmx[j-1].pb(mx);
        }
    }
}

long long arrival_time(long long t)
{
    rep(j,m-1){
        ll pos = lower_bound(all(tim[j]),t)-tim[j].begin()-1;
        t += X*(S[j+1]-S[j]);
        if(pos >= 0){
            amax(t,pmx[j][pos]);
        }
    }
    
    return t;    
}
#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...