Desserts at Magnan

Time limit: 1.1s Memory limit: 256MB Input: Output:

Mr. Blind and Stefano are best friends and they both study at the same university.

There are mainly two student canteens they can choose from: Crous\textcolor{red}{Crous} or Magnan\textcolor{blue}{Magnan}. Mr. Blind usually eats at Crous\textcolor{red}{Crous} while Stefano - at Magnan\textcolor{blue}{Magnan}.

In this problem we will focus on Magnan, known for its friendly staff and delicious fruit-based desserts.

Illustrative picture of the plethora of fruity desserts found at Magnan..\text{Illustrative picture of the plethora of fruity desserts found at Magnan.}.

Mr. Blind and Stefano decided to eat at Magnan (to Blind's distress, as the 22€ difference in price is tremendous) and have come to pick their desserts.

Like in Figure above, there are NN desserts given on a line.

For each dessert, we only care about its sweetness SS and its primary fruit ingredient FF (i.e. SiS_i and FiF_i, for the ii-th dessert on the line).

Stefano is pretty unpredictable when choosing his desserts but Mr. Blind found out there are exactly QQ preferences he will choose from.

A preference is given by the tuple (l,r,k)(l, r, k), where [l,r][l, r] is the interval of how sweet the desserts must be, and kk is the amount of desserts that must be based on his favourite fruit, denoted by PP.

Task

Given NN, PP, arrays SS and FF and the QQ preferences, find out for each one of them whether Mr. Blind can get an order that satisfies it.

Input data

The first line of the input file contains integers NN and PP, the number of desserts and Stefano's favourite dessert.

The second line contains NN integers S0,S1,,SN1S_0, S_1, \cdots, S_{N-1}, representing the sweetness of each dessert.

The third line contains NN integers F0,F1,,FN1F_0, F_1, \cdots, F_{N-1}, representing the main fruit ingredient of each dessert.

The fourth line contains a single integer QQ, the number of preferences.

Each of the following QQ lines contain three integers, lil_i, rir_i, kik_i, with their meaning explained above.

Output data

The output file must contain QQ lines, each consisting of a single string: the ii-th line must be YES if Mr. Blind can find a suitable order for the ii-th preference, and NO otherwise.

Constraints and clarifications

  • 1N1051 \leq N \leq 10^5.
  • 1P1091 \leq P \leq 10^9.
  • Si106\vert S_i \vert \leq 10^6 for each i=0,,N1i = 0, \cdots, N - 1.
  • 1Fi1091 \leq F_i \leq 10^9, for each i=0,,N1i = 0, \cdots, N - 1.
  • 1Q1051 \leq Q \leq 10^5.
  • 106lr106-10^6 \leq l \leq r \leq 10^6, for each preference.
  • 1kN1 \leq k \leq N, for each preference.
# Score Constraints
1 0 Examples
2 20 1N,Q5000.1 \leq N, Q \leq 5000.
3 15 rl100r - l \leq 100, for all preferences.
4 5 l=106 and r=106l = -10^6 \text{ and } r = 10^6, for all preferences.
5 60 No additional restrictions

Example 1

stdin

7 3
4 5 7 4 5 3 3
3 2 3 1 6 5 3
3
1 9 2
3 6 2
3 6 3

stdout

YES
YES
NO

Explanation

In the first sample case, we know that N=7N = 7, P=3P = 3, S=[4,5,7,4,5,3,2]S = [4, 5, 7, 4, 5, 3, 2] and F=[3,2,3,1,6,5,3]F = [3, 2, 3, 1, 6, 5, 3].

For the first preference, because l=1l = 1 and r=9r = 9, we notice that any order that has k=2k = 2 desserts which use PP as an ingredient is a valid order. As such, for example, the orders given by indices {0,2}\{0, 2\}, {0,5,6}\{0, 5, 6\} and {1,2,6}\{1, 2, 6\} are all suitable orders for this preference, so the answer is YES. These are not the only valid orders.

For the second preference, one possible order is {0,1,3,6}\{0, 1, 3, 6\}.

For the third preference, one can notice that there are only 33 desserts that use PP, one of them being too sweet. Thus, there are no orders, so the answer is NO.

Example 2

stdin

10 9
10 -2 -8 -6 -7 5 0 3 -8 -5
9 9 9 13 9 9 9 9 12 12
5
-4 -3 6
-5 0 4
-7 -4 3
-9 -7 4
0 4 2

stdout

NO
NO
NO
NO
YES

Explanation

In the second sample case, notice that the sweetness of desserts can also be negative.

Log in or sign up to be able to send submissions!