Submission #1040687

#TimeUsernameProblemLanguageResultExecution timeMemory
1040687n3rm1nToll (BOI17_toll)C++17
0 / 100
3051 ms12072 KiB
#include<bits/stdc++.h> #define endl '\n' using namespace std; typedef long long ll; const ll MAXN = 5e4 + 10; void speed() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); } struct querie { ll ql, qr, index; querie(){}; querie(ll _ql, ll _qr, ll _index) { ql = _ql; qr = _qr; index = _index; } }; ll k, n, m, q; vector < pair < ll, ll > > g[MAXN]; map < pair < ll, ll >, ll > mp; void read() { cin >> k >> n >> m >> q; ll from, to, cost; for (ll i = 1; i <= m; ++ i) { cin >> from >> to >> cost; from ++; to ++; mp[{from, to}] = cost; } } vector < pair < ll, ll > > ques[MAXN]; ll inf = 1e17; /// fix struct info { ll ver; ll u[MAXN]; info() { ver = 0; for (ll i = 1; i <= n; ++ i) u[i] = inf; }; }; deque < info > dq; ll ans[MAXN]; void queries() { ll ql, qr; for (ll i = 1; i <= q; ++ i) { cin >> ql >> qr; ql ++; qr ++; ques[ql].push_back(make_pair(qr, i)); } ll last_bucket = (n-1)/k, last = n; while((last-1) / k == last_bucket) { info newinfo; newinfo.ver = last; newinfo.u[last] = 0; dq.push_back(newinfo); last --; } ll i = last; while(i >= 1) { ll curr_bucket = (i-1)/k; // cout << "start at " << i << " " << curr_bucket << endl; ll cut_later = dq.size(); while(i >= 1 && (i-1)/k == curr_bucket) { info newinfo; newinfo.ver = i; newinfo.u[i] = 0; for (ll j = 0; j < cut_later; ++ j) { ll nb = dq[j].ver; ll newcost = mp[make_pair(i, nb)]; if(!newcost)continue; for (ll to = 1; to <= n; ++ to) { newinfo.u[to] = min(newinfo.u[to], dq[j].u[to] + newcost); } } dq.push_back(newinfo); i --; } while(cut_later --) dq.pop_front(); // cout << "* " << dq.size() << endl; for (ll j = 0; j < dq.size(); ++ j) { ll v = dq[j].ver; for (auto query: ques[v]) { ans[query.second] = dq[j].u[query.first]; //cout << "here act" << endl; } } } for (ll i = 1; i <= q; ++ i) { if(ans[i] == inf)cout << -1 << endl; else cout << ans[i] << endl; } } int main() { speed(); read(); queries(); return 0; }

Compilation message (stderr)

toll.cpp: In function 'void queries()':
toll.cpp:106:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::deque<info>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |         for (ll j = 0; j < dq.size(); ++ j)
      |                        ~~^~~~~~~~~~~
#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...