Submission #577035

#TimeUsernameProblemLanguageResultExecution timeMemory
577035definitelynotmeeRoller Coaster Railroad (IOI16_railroad)C++98
0 / 100
952 ms61368 KiB
#include<bits/stdc++.h>
#include"railroad.h"
#define mp make_pair
#define mt make_tuple
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
using namespace std;
template <typename T>
using matrix = vector<vector<T>>;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll INFL = (1LL<<62)-1;
const int INF = (1<<30)-1;
const double EPS = 1e-7;
const int MOD = 1e9 + 7;
const int RANDOM = chrono::high_resolution_clock::now().time_since_epoch().count();
const int MAXN = 1e6+1;

long long plan_roller_coaster(std::vector<int> s, std::vector<int> t) {
    int n = s.size();
    set<int> vals;
    vals.insert(0);
    vals.insert(INF);
 
    for(int i = 0; i < n; i++){
        vals.insert(s[i]);
        vals.insert(t[i]);
    }
    map<int,int> dic, rev;
 
    for(int i : vals)
        rev[dic.size()] = i, dic[i] = dic.size();
    int m = dic.rbegin()->ss;
    vector<int> delta(m+2);
    for(int i = 0; i < n; i++){
        int u = dic[s[i]], v = dic[t[i]];
        delta[u]--;
        delta[v]++;
    }

    ll cur = 1;
    ll resp = 0;
    for(int i = 0; i < m; i++){
        cur+=delta[i];
        if(cur < 0){
            auto it = rev.find(i);
            auto it2 = it;
            it2++;
            resp+=abs(cur)*(it2->ss-it->ss);
        }
    }

    return resp;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...