-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUntitled6.cpp
57 lines (47 loc) · 897 Bytes
/
Untitled6.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
vector<pair<int,int> > v;
map<int,int> m;
map<int,int> rev;
int arr[10001];
int ans[10001];
int main(){
int num;
scanf("%d",&num);
int tmp;
for(int i=0;i<num;i++){
scanf("%d",&tmp);
m.insert(make_pair(tmp,i));
rev.insert(make_pair(i,tmp));
v.push_back(make_pair(i,0));
}
for(int i=0;i<num;i++){
scanf("%d",&tmp);
v[i].second = m[tmp];
}
// sort(v.begin(),v.end());
int len =1;
arr[0]=v[0].second;
for(int i=1;i<num;i++){
int a = upper_bound(arr,arr+len,v[i].second)-arr;
arr[a]=v[i].second;
if(a==len){
len++;
for(int i=0;i<len;i++){
ans[i]=arr[i];
}
}
}
printf("%d\n",len);
vector<int> vv;
for(int i=0;i<len;i++){
vv.push_back(rev[ans[i]]);
}
sort(vv.begin(),vv.end());
for(int i=0;i<len;i++){
printf("%d ",vv[i]);
}
}