Submission #851540

#TimeUsernameProblemLanguageResultExecution timeMemory
851540willychanPassport (JOI23_passport)C++14
0 / 100
2127 ms972336 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; //#include<bits/extc++.h> //__gnu_pbds const int N = 2e5+5; vector<int> side[N]; int main(){ ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0); int n;cin>>n; for(int i=1;i<=n;i++){ int l,r;cin>>l>>r; for(int j=l;j<=r;j++) side[j].push_back(i); } int dis1[n+1]={0}; int disn[n+1]={0}; dis1[1]=1; disn[n]=1; queue<int> q; q.push(1); while(q.size()){ int a = q.front(); q.pop(); for(auto i : side[a]){ if(dis1[i]) continue; dis1[i] = dis1[a]+1; q.push(i); } } queue<int> q2; q2.push(n); while(q2.size()){ int a = q2.front(); q2.pop(); for(auto i : side[a]){ if(disn[i]) continue; disn[i] = disn[a]+1; q2.push(i); } } int Q;cin>>Q; while(Q--){ int x;cin>>x; if(dis1[x]==0 || disn[x]==0){ cout<<-1<<"\n"; continue; } cout<<max(dis1[x],disn[x])-1<<"\n"; } 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...