Description

給你兩個長度皆為n的數列$A[i]$、$B[i]$

對於數列$C$

$C[i] = \max \limits_{B[i] \le j \le i}(A[j])$

且保證 $ 0\le B[i-1] \le B[i] \le i$

請輸出整個數列 $C$

Input Format

$a[0] a[1] a[2] a[3] ... a[n-1]$
$b[0] b[1] b[2] b[3] ... b[n-1]$
$1 \le n \le 10 ^ 7 $
$0 \le a_i \le 1000$

$ 0 \le B[i-1] \le B[i] \le i$

Output Format

請輸出整個數列 $C$

Sample Input 1

5
1 2 6 4 5
0 0 0 0 0

Sample Output 1

1 2 6 6 6

Sample Input 2

5
2 23 1 12 203
0 0 1 2 3

Sample Output 2

2 23 23 12 203

Hints

好無聊好單調喔

Subtasks

No. Testdata Range Score

TopCoder

FHVirus
你好,我是一條鱸蛇

User's AC Ratio

80.0% (8/10)

Tags

Problem Source

Testdata and Limits

No. Time Limit (ms) Memory Limit (VSS, KiB) Memory Limit (RSS, KiB) Output Limit (KiB) Subtasks
0 2500 250000 250000 65536
1 2500 250000 250000 65536
2 2500 250000 250000 65536
3 2500 250000 250000 65536
4 2500 250000 250000 65536