-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4027.cpp
More file actions
executable file
·39 lines (35 loc) · 873 Bytes
/
Copy path4027.cpp
File metadata and controls
executable file
·39 lines (35 loc) · 873 Bytes
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
/**
* lcs->lis
* nlogn
* lis[i]表示长度为i的上升子序列最后一位最小是多少
**/
#include <iostream>
#include <stdio.h>
using namespace std;
int inv[100233], lis[100233], seq[100233], n, len, tmp;
int lower_bound(int lo, int hi, int a) {
if(lo >= hi) return lo;
int mi = (lo + hi) >> 1;
if(lis[mi] < a) return lower_bound(mi + 1, hi, a);
else return lower_bound(lo, mi, a);
}
int main() {
scanf("%d", &n);
for(int i = 1;i <= n;++ i) {
scanf("%d", &tmp);
inv[tmp] = i;
}
for(int i = 1;i <= n;++ i) {
scanf("%d", &tmp);
seq[i] = inv[tmp];
}
for(int i = 1;i <= n;++ i) {
if(seq[i] > lis[len]) {
lis[++ len] = seq[i];
} else {
int tmp1 = lower_bound(1, len, seq[i]);
lis[tmp1] = seq[i];
}
}
printf("%d\n", len);
}