Logo
(追記) (追記ここまで)

23245번 - Similarity 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 (추가 시간 없음) 1024 MB53121118942.377%

문제

In modern application systems, a recommendation system is very widely used to recommend books, music, ads, items, etc. The recommendation system needs to attract other users by providing the most interested items to each user. One way of recommendation is to find the most similar user to the current user, then recommend the items that the most similar user purchased to the current user. To help the recommendation system, we design a similarity measure. A user is represented by a sequence $p = p_1, p_2, \dots, p_n$ where $n$ denotes the number of items. It denotes a list of the preference magnitudes of the user for items. When we are given two sequences $p = p_1, p_2, \dots, p_n$ and $q = q_1, q_2, \dots, q_n,ドル a similar tuple is defined as a tuple $(i, j, k)$ such that $p_i < p_j < p_k$ and $q_i < q_j < q_k$. For given two sequences $p = p_1, p_2, \dots, p_n$ and $q = q_1, q_2, \dots, q_n,ドル the similarity is defined as the number of similar tuples.

For example, if the given two sequences are $p = 2, 5, 9, 5, 1$ and $q = 1, 4, 5, 3, 2,ドル the similar tuples are $(1, 2, 3),ドル $(1, 4, 3),ドル $(5, 2, 3),ドル and $(5, 4, 3)$ The similarity of the two sequences is 4ドル$.

Given two sequences $p = p_1, p_2, \dots, p_n$ and $q = q_1, q_2, \dots, q_n,ドル write a program to output the similarity of them.

입력

Your program is to read from standard input. The input starts with a line containing one integer $n$ (1ドル \le n \le 100,000$), where $n$ is the length of a sequence. In the following two lines, each line contains $n$ integers in range $[0, 10^6]$ that represent a sequence.

출력

Your program is to write to standard output. Print exactly one line. The line should contain the similarity of the two sequences.

제한

예제 입력 1

5
2 5 9 5 1
1 4 5 3 2

예제 출력 1

4

예제 입력 2

4
3 2 1 1
3 2 1 1

예제 출력 2

2

힌트

출처

ICPC > Regionals > Asia Pacific > Korea > Nationwide Internet Competition > Seoul Nationalwide Internet Competition 2021 H번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /