A - Two Sequences 2 Editorial /

Time Limit: 2 sec / Memory Limit: 1024 MB

配点 : 300300

問題文

すぬけ君は長さ NN の数列 a,ba,b を持っています。 a,ba,bii 番目の数はそれぞれ ai,bia_i,b_i です。

すぬけ君は a,ba,b を使って長さ NN の数列 cc を作ることにしました。 1nN1 \leq n \leq N を満たす nn について、ccnn 番目の数 cnc_n1ijn1 \leq i \leq j \leq n を満たすような (i,j)(i,j) について aibja_i b_j を計算したときの最大値です。より形式的には cnc_ncn=max1ijnaibjc_n = \max_{1 \leq i \leq j \leq n} a_{i}b_{j} で表される数です。

c1,c2,,cNc_1, c_2, \ldots, c_{N} を求めてください。

制約

  • 与えられる入力は全て整数
  • 1N2×1051 \leq N \leq 2 \times 10^{5}
  • 1ai,bi1091 \leq a_i, b_i \leq 10^9

入力

入力は以下の形式で標準入力から与えられる。

NN
a1a_{1} a2a_{2} \cdots aNa_{N}
b1b_{1} b2b_{2} \cdots bNb_{N}

出力

NN 行出力せよ。上から nn 行目では cnc_{n} を出力せよ。


入力例 1Copy

Copy
3
3 2 20
1 4 1

出力例 1Copy

Copy
3
12
20
  • c1=max(a1b1)=3c_{1} = \max(a_{1}b_{1}) = 3 です。
  • c2=max(a1b1,a1b2,a2b2)=12c_{2} = \max(a_{1}b_{1}, a_{1}b_{2},a_{2}b_{2}) = 12 です。
  • c3=max(a1b1,a1b2,a1b3,a2b2,a2b3,a3b3)=20c_{3} = \max(a_{1}b_{1}, a_{1}b_{2}, a_{1}b_{3}, a_{2}b_{2},a_{2}b_{3},a_{3}b_{3}) = 20 です。

入力例 2Copy

Copy
20
715806713 926832846 890153850 433619693 890169631 501757984 778692206 816865414 50442173 522507343 546693304 851035714 299040991 474850872 133255173 905287070 763360978 327459319 193289538 140803416
974365976 488724815 821047998 371238977 256373343 218153590 546189624 322430037 131351929 768434809 253508808 935670831 251537597 834352123 337485668 272645651 61421502 439773410 621070911 578006919

出力例 2Copy

Copy
697457706539596888
697457706539596888
760974252688942308
760974252688942308
760974252688942308
760974252688942308
760974252688942308
760974252688942308
760974252688942308
760974252688942308
760974252688942308
867210459214915026
867210459214915026
867210459214915026
867210459214915026
867210459214915026
867210459214915026
867210459214915026
867210459214915026
867210459214915026

Score : 300300 points

Problem Statement

Snuke has two number sequences aa and bb, each of length NN. The ii-th number of aa is aia_i, and that of bb is bib_i.

Using these sequences, he has decided to make a new sequence cc of length NN. For each nn such that 1nN1 \leq n \leq N, cnc_n, the nn-th number of cc, is the maximum value of aibja_i b_j for a pair (i,j)(i,j) such that 1ijn1 \leq i \leq j \leq n. Formally, we have cn=max1ijnaibjc_n = \max_{1 \leq i \leq j \leq n} a_{i}b_{j}.

Find c1,c2,,cNc_1, c_2, \ldots, c_{N}.

Constraints

  • All values in input are integers.
  • 1N2×1051 \leq N \leq 2 \times 10^{5}
  • 1ai,bi1091 \leq a_i, b_i \leq 10^9

Input

Input is given from Standard Input in the following format:

NN
a1a_{1} a2a_{2} \cdots aNa_{N}
b1b_{1} b2b_{2} \cdots bNb_{N}

Print

Print NN lines. The nn-th line from the top should contain cnc_{n}.


Sample Input 1Copy

Copy
3
3 2 20
1 4 1

Sample Output 1Copy

Copy
3
12
20

We have:

  • c1=max(a1b1)=3c_{1} = \max(a_{1}b_{1}) = 3;
  • c2=max(a1b1,a1b2,a2b2)=12c_{2} = \max(a_{1}b_{1}, a_{1}b_{2},a_{2}b_{2}) = 12;
  • c3=max(a1b1,a1b2,a1b3,a2b2,a2b3,a3b3)=20c_{3} = \max(a_{1}b_{1}, a_{1}b_{2}, a_{1}b_{3}, a_{2}b_{2},a_{2}b_{3},a_{3}b_{3}) = 20.

Sample Input 2Copy

Copy
20
715806713 926832846 890153850 433619693 890169631 501757984 778692206 816865414 50442173 522507343 546693304 851035714 299040991 474850872 133255173 905287070 763360978 327459319 193289538 140803416
974365976 488724815 821047998 371238977 256373343 218153590 546189624 322430037 131351929 768434809 253508808 935670831 251537597 834352123 337485668 272645651 61421502 439773410 621070911 578006919

Sample Output 2Copy

Copy
697457706539596888
697457706539596888
760974252688942308
760974252688942308
760974252688942308
760974252688942308
760974252688942308
760974252688942308
760974252688942308
760974252688942308
760974252688942308
867210459214915026
867210459214915026
867210459214915026
867210459214915026
867210459214915026
867210459214915026
867210459214915026
867210459214915026
867210459214915026


2025-03-29 (Sat)
11:42:13 +00:00