#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 time |
Memory |
Grader output |
1 |
Correct |
5 ms |
24924 KB |
Output is correct |
2 |
Correct |
5 ms |
24996 KB |
Output is correct |
3 |
Correct |
5 ms |
24924 KB |
Output is correct |
4 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
24924 KB |
Output is correct |
2 |
Correct |
5 ms |
24924 KB |
Output is correct |
3 |
Correct |
5 ms |
24924 KB |
Output is correct |
4 |
Correct |
5 ms |
24924 KB |
Output is correct |
5 |
Correct |
6 ms |
24924 KB |
Output is correct |
6 |
Correct |
5 ms |
24924 KB |
Output is correct |
7 |
Correct |
5 ms |
24924 KB |
Output is correct |
8 |
Incorrect |
5 ms |
24976 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
24924 KB |
Output is correct |
2 |
Correct |
5 ms |
24924 KB |
Output is correct |
3 |
Correct |
5 ms |
24924 KB |
Output is correct |
4 |
Correct |
5 ms |
24924 KB |
Output is correct |
5 |
Correct |
6 ms |
24924 KB |
Output is correct |
6 |
Correct |
5 ms |
24924 KB |
Output is correct |
7 |
Correct |
5 ms |
24924 KB |
Output is correct |
8 |
Incorrect |
5 ms |
24976 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
24924 KB |
Output is correct |
2 |
Correct |
5 ms |
24924 KB |
Output is correct |
3 |
Correct |
5 ms |
24924 KB |
Output is correct |
4 |
Correct |
5 ms |
24924 KB |
Output is correct |
5 |
Correct |
6 ms |
24924 KB |
Output is correct |
6 |
Correct |
5 ms |
24924 KB |
Output is correct |
7 |
Correct |
5 ms |
24924 KB |
Output is correct |
8 |
Incorrect |
5 ms |
24976 KB |
Output isn't correct |
9 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
24924 KB |
Output is correct |
2 |
Correct |
5 ms |
24996 KB |
Output is correct |
3 |
Correct |
5 ms |
24924 KB |
Output is correct |
4 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |