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;
const int N = 1e5+15, M =3e5+5;
int a[M],b[M],x[M],y[M];
vector<pair<int,int> > adj[N];
int mini[M];
void dfs(int root,int T,int R){
int u,i,id;
while(!adj[root].empty()){
id= adj[root].back().second;
if(adj[root].back().first<=T){
adj[root].pop_back();
}
else
break;
mini[id] = R;
dfs(a[id]^b[id]^root,x[id],R);
}
}
int R[N],X[N];
int main(){
//freopen("input.txt","r",stdin);
int n,m;
cin>>n>>m;
memset(mini,-1,sizeof(mini));
vector<pair<int,int> >edge;
for(int i=0;i<m;++i){
scanf("%d%d%d%d",&a[i],&b[i],&x[i],&y[i]);
if(b[i]!= n)
adj[b[i]].push_back(make_pair(y[i],i));
else{
edge.push_back(make_pair(y[i],i));
if(a[i]==1)
mini[i]= y[i];
}
}
sort(edge.begin(),edge.end());
for(int i=1;i<=n;++i){
sort(adj[i].begin(),adj[i].end());
reverse(adj[i].begin(),adj[i].end());
}
for(int i=0;i<edge.size();++i){
int id = edge[i].second;
dfs(a[id],x[id],y[id]);
}
edge.clear();
for(int i=0;i<m;++i){
if(a[i]==1 && mini[i]!=-1){
edge.push_back(make_pair(mini[i],x[i]));
}
}
int pos=1;
for(int i=0;i<edge.size();++i){
X[pos++]= edge[i].first;
}
sort(X+1,X+pos);
pos = unique(X+1,X+pos)- X;
R[0]= -1;
int id;
for(int i=0;i<edge.size();++i){
id = lower_bound(X+1,X+pos+1, edge[i].first)- X;
R[id]= max(R[id],edge[i].second);
}
for(int i=1;i<=pos;++i)
R[i] = max(R[i],R[i-1]);
int q,l;
cin>>q;
for(int i=0;i<q;++i){
scanf("%d",&l);
id = lower_bound(X+1,X+pos+1, l+1)- X-1;
printf("%d\n",R[id]);
}
}
Compilation message (stderr)
bus.cpp: In function 'void dfs(int, int, int)':
bus.cpp:17:6: warning: unused variable 'u' [-Wunused-variable]
int u,i,id;
^
bus.cpp:17:8: warning: unused variable 'i' [-Wunused-variable]
int u,i,id;
^
bus.cpp: In function 'int main()':
bus.cpp:58:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<edge.size();++i){
^
bus.cpp:69:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<edge.size();++i){
^
bus.cpp:76:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int i=0;i<edge.size();++i){
^
bus.cpp:41:44: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d%d",&a[i],&b[i],&x[i],&y[i]);
^
bus.cpp:86:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d",&l);
^
# | 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... |