Submission #851568

#TimeUsernameProblemLanguageResultExecution timeMemory
851568owoovoPassport (JOI23_passport)C++14
0 / 100
8 ms25176 KiB
#include<bits/stdc++.h> using namespace std; const int maxn=3000; int n,qu; pair<int,int> ori[2510]; struct bit{ int o[2510]; void mo(int p,int x){ while(p<=n){ o[p]=min(o[p],x); p+=p&(-p); } return ; } int q(int p){ int ans=maxn; while(p){ ans=min(o[p],ans); p-=p&(-p); } return ans; } }; bit dp[2510]; int main(){ ios::sync_with_stdio(0); cin.tie(0); cin>>n; for(int i=1;i<=n;i++){ cin>>ori[i].first>>ori[i].second; } for(int i=0;i<=2505;i++){ for(int j=0;j<=2505;j++)dp[i].o[j]=maxn; } cin>>qu; int now=0; dp[1].mo(n,0); for(int i=0;i<qu;i++){ int x; cin>>x; while(now!=x){ now++; for(int j=n;j>=now;j--){ if(ori[j].first<now){ dp[now].mo(j,dp[ori[j].first].q(ori[j].second)+1); }else{ dp[now].mo(j,dp[now].q(ori[j].second)+1); } } } if(dp[x].q(x)==maxn){ cout<<"-1\n"; }else{ cout<<dp[x].q(x)<<"\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...