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

    ID: 16762 Type: RemoteJudge 2000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 7 Uploaded By: Tags>2017线段树ICPC双指针 two-pointer西安Hall 定理

[ICPC 2017 Xi'an R] LOVER II

题目描述

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+bj≥ka_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?

输入格式

Several test cases (no more than 1010).

First line an integer TT (1≤T≤10)(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 (1≤n,m≤2×105,0≤k≤109)(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 (0≤ai≤109)(0 \le a_i \le 10^9). The next line has mm integers indicating b1b_1 to bmb_m (0≤bi≤109)(0 \le b_i \le 10^9).

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

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

输出格式

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