Submission #896383

#TimeUsernameProblemLanguageResultExecution timeMemory
896383AiperiiiPassport (JOI23_passport)C++14
22 / 100
2060 ms49500 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; signed main(){ ios_base::sync_with_stdio(); cin.tie(0); int n; cin>>n; vector <int> l(n+1),r(n+1),mx(n+1); for(int i=1;i<=n;i++){ cin>>l[i]>>r[i]; mx[i]=max(mx[i-1],r[i]); } int query; cin>>query; while(query--){ int s; cin>>s; if(s==1){ int x=r[s]; int ans=1; while(x!=n){ if(mx[x]==x){ ans=-1; break; } ans++; x=mx[x]; } cout<<ans<<"\n"; continue; } queue < pair <int,int> > q; q.push({l[s],r[s]}); vector <vector <int> > dis(n+1,vector <int> (n+1,1e18)); dis[l[s]][r[s]]=1; while(!q.empty()){ int left=q.front().ff; int right=q.front().ss; q.pop(); for(int i=left;i<=right;i++){ if(dis[min(left,l[i])][max(right,r[i])]>dis[left][right]+1){ dis[min(left,l[i])][max(right,r[i])]=dis[left][right]+1; q.push({min(left,l[i]),max(right,r[i])}); } } } if(dis[1][n]==1e18)cout<<-1<<"\n"; else cout<<dis[1][n]<<"\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...