Submission #1061968

# Submission time Handle Problem Language Result Execution time Memory
1061968 2024-08-16T16:08:06 Z steveonalex Train (APIO24_train) C++17
0 / 100
152 ms 24572 KB
#include <bits/stdc++.h>
#include "train.h" 


using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()
#define block_of_code if(true)
 
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}
ll gcd(ll a, ll b){return __gcd(a, b);}
ll lcm(ll a, ll b){return a / gcd(a, b) * b;}
 
ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ull mask){return __builtin_ctzll(mask);}
int logOf(ull mask){return 63 - __builtin_clzll(mask);}
 
mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}
 
template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }
 
template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }
 
template <class T>
    void printArr(T container, string separator = " ", string finish = "\n", ostream &out = cout){
        for(auto item: container) out << item << separator;
        out << finish;
    }
 
template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

const int N = 1e5 + 65;
const ll INF = 1e18 + 69;
const int INF_T = 1e9 + 69;
vector<pair<int,ll>> relevant_time[N];
vector<pair<int, int>> graph[N * 2];

void reset(int n, int m, int w){
    for(int i = 0; i<n; ++i) relevant_time[i].clear();
    for(int i = 0; i<n * 2; ++i){
        graph[i].clear();
    }
}

struct FenwickTree{
    int n;
    vector<int> a;

    FenwickTree(int _n){
        n = _n;
        a.resize(n+1);
    }

    void update(int i, int v){
        i = n - i + 1;
        while(i <= n){
            a[i] += v;
            i += LASTBIT(i);
        }
    }

    int get(int i){
        i = n - i + 1;
        int ans = 0;
        while(i > 0){
            ans += a[i];
            i -= LASTBIT(i);
        }
        return ans;
    }
};

ll solve(int n, int m, int w, vector<int> t, 
                vector<int> x, vector<int> y, vector<int> a, vector<int> b, vector<int> c, 
                vector<int> l, vector<int> r) {
    reset(n, m, w);

    vector<int> timeline = {-1, 0, INF_T};
    for(int i = 0; i<m; ++i){
        timeline.push_back(a[i]);
        timeline.push_back(b[i]);
    }
    remove_dup(timeline);

    for(int i= 0; i<m; ++i){
        a[i] = lower_bound(ALL(timeline), a[i]) - timeline.begin();
        b[i] = lower_bound(ALL(timeline), b[i]) - timeline.begin();
    }


    vector<pair<int, int>> relevant_pair;
    for(int i = 0; i<m; ++i){
        relevant_pair.push_back({a[i], x[i]});
        relevant_pair.push_back({b[i], y[i]});
    }
    relevant_pair.push_back({1, 0});
    relevant_pair.push_back({timeline.size() - 1, n-1});
    remove_dup(relevant_pair);

    for(int i = 0; i<m; ++i){
        pair<int, int> u = {a[i], x[i]}, v = {b[i], y[i]};
        int idx1 = lower_bound(ALL(relevant_pair), u) - relevant_pair.begin();
        int idx2 = lower_bound(ALL(relevant_pair), v) - relevant_pair.begin();
        graph[idx2].push_back({idx1, c[i]});
    }

    vector<ll> dis(relevant_pair.size(), INF);
    vector<pair<int, int>> range;
    for(int i = 0; i<w; ++i) {
        r[i] = upper_bound(ALL(timeline), r[i]) - timeline.begin() - 1;
        l[i] = lower_bound(ALL(timeline), l[i]) - timeline.begin();
        range.push_back({l[i], r[i]});
    }
    sort(ALL(range), [](pair<int,int> x, pair<int, int> y){
        return x.second > y.second;
    });

    FenwickTree bit(timeline.size() - 1);

    dis[0] = 0;
    for(int i = 0; i < relevant_pair.size(); ++i){
        pair<int, int> u = relevant_pair[i];
        while(range.size() && u.first > range.back().second){
            pair<int, int> cur = range.back(); range.pop_back();
            bit.update(cur.first - 1, 1);
        }
        for(pair<int, int> j: graph[i]) minimize(dis[i], dis[j.first] + j.second);
        if (relevant_time[u.second].size()){
            for(pair<int, int> j: relevant_time[u.second]){
                ll cur = j.second;
                cur += 1LL * bit.get(j.first) * t[u.second];
                minimize(dis[i], cur);
            }
        }
        relevant_time[u.second].push_back({u.first, dis[i]});
    }

    if (dis.back() == INF) return -1;
    return dis.back();
}


// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     clock_t start = clock();

//     int n, m, w; cin >> n >> m >> w;
//     vector<int> t(n), x(m), y(m), a(m), b(m), c(m), l(w), r(w);
//     for(int &i: t) cin >> i;
//     for(int &i: x) cin >> i;
//     for(int &i: y) cin >> i;
//     for(int &i: a) cin >> i;
//     for(int &i: b) cin >> i;
//     for(int &i: c) cin >> i;
//     for(int &i: l) cin >> i;
//     for(int &i: r) cin >> i;

//     cout << solve(n, m, w, t, x, y, a, b, c, l, r) << "\n";


//     cerr << "Time elapsed: " << clock() - start << " ms\n";

//     return 0;
// }

/*
5
4 3 2 1 0
6
0 1
1 2
2 3
3 4
0 1
1 2

*/

Compilation message

train.cpp: In function 'll solve(int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
train.cpp:141:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  141 |     for(int i = 0; i < relevant_pair.size(); ++i){
      |                    ~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7512 KB Integer -1486618496 violates the range [-1, 10^18]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 152 ms 24572 KB Integer -1974112897 violates the range [-1, 10^18]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 152 ms 24572 KB Integer -1974112897 violates the range [-1, 10^18]
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7512 KB Integer -1486618496 violates the range [-1, 10^18]
2 Halted 0 ms 0 KB -