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

33397번 - StrCartesian 스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
13 초 2048 MB0000.000%

문제

Given are two sets of strings $A = \{a_1, a_2, \ldots, a_n\}$ and $B = \{b_1, b_2, \ldots, b_m\}$. Define a sequence of $n \cdot m$ pairwise concatenations of $a_i$ and $b_j$: $$S=(a_1 b_1, a_1 b_2, \ldots, a_1 b_m, a_2 b_1, a_2 b_2, \ldots, a_2 b_m, \ldots, a_n b_1, a_n b_2, \ldots, a_n b_m)\text{.}$$

Now sort the sequence $S$ lexicographically, and let the sorted sequence be $C = (c_1, c_2, \ldots, c_{n \cdot m})$.

We want to know the sequence $C,ドル but it is too large. So we make $q$ queries to your program, and the $i$-th query asks for $c_{k_i}$.

However, $c_{k_i}$ is still too long to output. If the answer equals $c = a_f + b_s,ドル then your program only needs to output the pair $(f, s)$.

입력

The first line contains two integers $n$ and $m$ (1ドル \le n, m \le 5 \cdot 10^4$), the sizes of sets $A$ and set $B$.

The following $n$ lines contain $n$ distinct non-empty strings $a_1, a_2, \ldots, a_n$.

The total length of strings in set $A$ does not exceed 10ドル^6$.

The following $m$ lines contain $m$ distinct non-empty strings $b_1, b_2, \ldots, b_m$.

The total length of strings in set $B$ does not exceed 10ドル^6$.

All strings consist of lowercase English letters.

The next line contains one integer $q$ (1ドル \le q \le 1000$), the number of queries.

In the following $q$ lines, the $i$-th line contains an integer $k_i$ (1ドル \le k_i \le n \cdot m$), specifying that the query asks for the $k_i$-th element of $C$.

출력

Print $q$ lines. The $i$-th line must contain two integers $f_i$ and $s_i$ (1ドル \le f_i \le n$; 1ドル \le s_i \le m$) specifying that the answer $c_{k_i}$ equals to $a_{f_i} b_{s_i}$. If there are multiple correct answers, your program may output any one of them.

제한

예제 입력 1

2 3
a
ab
a
aa
ba
2
3
4

예제 출력 1

2 1
1 3

힌트

출처

Camp > Petrozavodsk Programming Camp > Summer 2023 > Day 7: Peking U Contest F번

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

출처

대학교 대회

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

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