#P17156. [ICPC 2017 Xi'an R] LOVER II

    ID: 19434 远端评测题 2000ms 512MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>2017线段树ICPC双指针 two-pointer西安

[ICPC 2017 Xi'an R] LOVER II

Problem Description

One day nn girls and mm boys come to Xi'an to look for a mate. Each girl has a value aia_i, each boy has a value bib_i. Girl ii and boy jj will fall in love only if ai+bjka_i + b_j \ge k.

Then qq queries follow. Ask you to calculate if we only have boys labeled from LL to RR, can we make all girls find their lovers?

Input Format

Several test cases (no more than 1010).

First line an integer TT (1T10)(1 \le T \le 10). Indicates the number of test cases.

Then TT test cases follow. Each test case begins with three integers n,m,kn, m, k (1n,m2×105,0k109)(1 \le n, m \le 2 \times 10^5, 0 \le k \le 10^9). The next line has nn integers indicating a1a_1 to ana_n (0ai109)(0 \le a_i \le 10^9). The next line has mm integers indicating b1b_1 to bmb_m (0bi109)(0 \le b_i \le 10^9).

Then comes an integer qq. (1q105)(1 \le q \le 10^5).

The next qq lines each contain two integers L,RL, R (1LRm)(1 \le L \le R \le m) indicating each query.

Output Format

For each query, print "1" if we can make it or "0" otherwise.

1
3 4 5
1 1 1
4 4 4 3
2
1 3
2 4
1
0