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

19324번 - Three Arrays 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 256 MB55333159.615%

문제

You are given three arrays: $a$ containing $n_a$ elements, $b$ containing $n_b$ elements and $c$ containing $n_c$ elements. These arrays are sorted in non-decreasing order: that is, for every $i$ such that 1ドル \le i < n_a$ we have $a_i \le a_{i + 1},ドル for every $j$ such that 1ドル \le j < n_b$ we have $b_j \le b_{j + 1},ドル and for every $k$ such that 1ドル \le k < n_c$ we have $c_k \le c_{k + 1}$.

Your task is to calculate the number of triples $(i, j, k)$ such that $|a_i - b_j| \le d,ドル $|a_i - c_k| \le d,ドル and $|b_j - c_k| \le d$.

입력

The input contains one or more test cases. Each test case consists of four lines.

The first line of each test case contains four integers: $d,ドル $n_a,ドル $n_b,ドル and $n_c$ (1ドル \le d \le 10^9,ドル 1ドル \le n_a, n_b, n_c \le 5 \cdot 10^5$).

The second line contains $n_a$ integers $a_1, a_2, \ldots, a_{n_a}$: the array $a$ ($-10^9 \le a_i \le 10^9$).

The third line contains $n_b$ integers $b_1, b_2, \ldots, b_{n_b}$: the array $b$ ($-10^9 \le b_i \le 10^9$).

The fourth line contains $n_c$ integers $c_1, c_2, \ldots, c_{n_c}$: the array $c$ ($-10^9 \le c_i \le 10^9$).

All arrays are sorted in non-decreasing order. The total sum of $n_a$ over all testcases does not exceed 5ドル \cdot 10^5$. The total sum of $n_b$ over all testcases does not exceed 5ドル \cdot 10^5$. The total sum of all $n_c$ over all testcases does not exceed 5ドル \cdot 10^5$. The test cases just follow one another without any special separators.

출력

For each test case, print a single integer: the number of triples $(i, j, k)$ such that $|a_i - b_j| \le d,ドル $|a_i - c_k| \le d,ドル and $|b_j - c_k| \le d$.

제한

예제 입력 1

1 3 3 3
1 2 3
1 2 3
1 2 3
1 6 6 6
1 1 2 2 3 3
2 2 3 3 4 4
3 3 4 4 5 5

예제 출력 1

15
56

힌트

출처

Camp > Petrozavodsk Programming Camp > Winter 2018 > Day 8: Saratov SU Contest A번

Contest > Open Cup > 2017/2018 Season > Stage 13: Grand Prix of Saratov A번

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

출처

대학교 대회

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

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