Submission #888690

#TimeUsernameProblemLanguageResultExecution timeMemory
888690vjudge1Passport (JOI23_passport)C++14
0 / 100
613 ms1048576 KiB
#include <bits/stdc++.h> #define int long long #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back using namespace std; const int N=1e5+5; vector <int> g[N]; signed main(){ ios_base::sync_with_stdio(); cin.tie(0); int n; cin>>n; vector <int> l(n),r(n); for(int i=0;i<n;i++)cin>>l[i]>>r[i]; for(int i=0;i<n;i++){ for(int j=l[i];j<=r[i];j++){ g[i+1].pb(j); } } int q;cin>>q; set <pair <int,int> > st; while(q--){ int x;cin>>x; vector <int> d(n+1,1e18),p(n+1); d[x]=0; st.insert({0,x}); while(!st.empty()){ int v=st.begin()->second; d[v]++; st.erase(st.begin()); for(auto to : g[v]){ if(d[to]>d[v]){ p[to]=v; st.erase({d[to],to}); d[to]=d[v]; st.insert({d[to],to}); } } } int mx=0; set <int> st; for(int i=1;i<=n;i++){ mx=max(mx,d[i]); if(d[i]==1e18)break; int curv=i; while(curv!=x){ curv=p[curv]; st.insert(curv); //cout<<curv<<" "; } //cout<<endl; } if(mx==1e18)cout<<-1<<"\n"; else cout<<st.size()<<"\n"; } }
#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...