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<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
const int MAX_N = 1e5,MAX_M=3e5,MAX_Q=1e5;
int n, m,q,cnt,res[MAX_Q];
vector<int> t[MAX_N+1],idx[MAX_N+1],adj[MAX_M*2];
pair<int, int> query[MAX_Q];
struct st {
int a, b, x, y;
}s[MAX_M];
bool ck[MAX_M * 2];
int maxi=-1;
void dfs(int h) {
if (h < idx[1].size()) maxi = max(maxi, t[1][h]);
if (ck[h]) return;
ck[h] = true;
for (auto t : adj[h]) dfs(t);
}
int main() {
scanf("%d %d", &n, &m);
for (int i = 0; i < m; i++){
scanf("%d %d %d %d", &s[i].a, &s[i].b, &s[i].x, &s[i].y);
t[s[i].a].push_back(s[i].x);
t[s[i].b].push_back(s[i].y);
}
for (int i = 1; i <= n; i++) {
sort(t[i].begin(), t[i].end());
unique(t[i].begin(), t[i].end());
for (int j = 0; j < t[i].size(); j++) {
if (j) adj[cnt].push_back(cnt - 1);
idx[i].push_back(cnt++);
}
}
for (int i = 0; i < m; i++) {
int a = lower_bound(t[s[i].a].begin(), t[s[i].a].end(), s[i].x) - t[s[i].a].begin(),
b = lower_bound(t[s[i].b].begin(), t[s[i].b].end(), s[i].y) - t[s[i].b].begin();
adj[idx[s[i].b][b]].push_back(idx[s[i].a][a]);
}
scanf("%d", &q);
for (int i = 0; i < q; i++) {
scanf("%d",&query[i].first);
query[i].second=i;
}
sort(query, query + q);
for (int i = 0; i < q; i++) {
int a = upper_bound(t[n].begin(), t[n].end(), query[i].first) - t[n].begin() - 1;
if(a>=0) dfs(idx[n][a]);
res[query[i].second] = maxi;
}
for (int i = 0; i < q; i++) printf("%d\n", res[i]);
return 0;
}
# | 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... |