Submission #1318154

#TimeUsernameProblemLanguageResultExecution timeMemory
1318154vaishakhvToll (BOI17_toll)C++20
0 / 100
22 ms4788 KiB
// Source: https://usaco.guide/general/io

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define eb emplace_back // faster than push_back xD

// pbds UwU
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define oset tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> // use pair for ms

// my io library :D
#define m1(x) template<class T, class... U> void x(T&& a, U&&... b)
#define m2(x) (ll[]){(x forward<U>(b),0)...}

m1(pr){cout << forward<T>(a);  m2(cout << " " <<); cout << "\n";}
m1(re){cin >> forward<T>(a); m2(cin >>);}

const ll cap = 5e4+1;
ll dist[cap];
vector<pair<ll,ll>> adj[cap];

void dijkstra(ll s){
    priority_queue<pair<ll,ll>> pq;
    fill(dist, dist+cap, 1e18);
    pq.push({0, s});
    dist[s] = 0;

    while (!pq.empty()){
        pair<ll,ll> oknext = pq.top(); pq.pop();
        oknext.first *= -1;
        for (auto u: adj[oknext.second]){
            if (dist[oknext.second] + u.second < dist[u.first]){
                dist[u.first] = dist[oknext.second] + u.second;
                pq.push({-dist[u.first], u.first});
            }    
        }   
    }
}

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

    ll k, n, m, o;
    re(k, n, m, o);

    vector<ll> w(n, -1);
    for (ll i{}; i < m; i++){
        ll a, b, t; re(a, b, t);
        adj[a].eb(make_pair(b, t));
        if (b == a + 1) {
            if (w[a] == -1) w[a] = t;
            else w[a] = min(w[a], t);
        }
    }

    vector<ll> pref(n, 0);
    for (ll i{}; i < n-1; i++){
        if (w[i] == -1) pref[i+1] = -1;
        else if (pref[i] == -1) pref[i+1] = -1;
        else pref[i+1] = pref[i] + w[i];
    }

    for (ll i{}; i < o; i++){
        ll a, b; re(a, b);
        if (pref[a] == -1 || pref[b] == -1) pr(-1);
        else pr(pref[b] - pref[a]);
    }
}
#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...