Submission #1040806

#TimeUsernameProblemLanguageResultExecution timeMemory
1040806n3rm1nToll (BOI17_toll)C++17
7 / 100
12 ms3672 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]; int a[MAXN], is[MAXN]; ll prefa[MAXN], cnt[MAXN]; void read() { cin >> k >> n >> m >> q; ll from, to, cost; for (ll i = 1; i <= m; ++ i) { cin >> from >> to >> cost; from ++; to ++; is[from] = 1; a[from] = cost; } for (int i = 1; i <= n; ++ i) { prefa[i] = prefa[i-1] + a[i]; cnt[i] = cnt[i-1] + is[i]; } while(q --) { int ql, qr; cin >> ql >> qr; ql ++; qr ++; int curr_cnt = cnt[qr-1] - cnt[ql-1]; if(curr_cnt != qr - ql)cout << -1 << endl; else cout << prefa[qr-1] - prefa[ql - 1] << endl; } } void queries() { ll ql, qr; for (ll i = 1; i <= q; ++ i) { cin >> ql >> qr; } } int main() { speed(); read(); // queries(); return 0; }
#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...