Submission #851572

#TimeUsernameProblemLanguageResultExecution timeMemory
851572owoovoPassport (JOI23_passport)C++14
0 / 100
6 ms24996 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>0){ 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--){ dp[now].mo(j,dp[min(now,ori[j].first)].q(ori[j].second)+1); } } if(dp[ori[x].first].q(ori[x].second)==maxn){ cout<<"-1\n"; }else{ cout<<dp[ori[x].first].q(ori[x].second)+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...