This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
int n, m, q, in[300300];
priority_queue<array<int, 3>, vector<array<int, 3>>, greater<>> pq;
vector<array<int, 2>> v[100100];
int main(){
cin.tie(0)->sync_with_stdio(0);
cin >> n >> m;
for(int i=1;i<=m;i++) {
int a, b, c, d; cin >> a >> b >> c >> d;
pq.push({c, i, a}), pq.push({d, -i, b});
}
memset(in, -1, sizeof in);
while(!pq.empty()) {
auto [t, id, u] = pq.top(); pq.pop();
if(id < 0) {
id = -id;
if(in[id] < 0 || (!v[u].empty() && v[u].back()[1] >= in[id])) continue;
v[u].push_back({t, in[id]});
} else {
if(v[u].empty()) {
if(u == 1) in[id] = t;
continue;
}
in[id] = v[u].back()[1];
}
}
cin >> q;
while(q--) {
int x; cin >> x;
auto it = lower_bound(v[n].begin(), v[n].end(), array<int, 2>({x, INF}));
cout << (it == v[n].begin() ? -1 : (*prev(it))[1]) << "\n";
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |