#K84197. Pair Sum Query

    ID: 36366 Type: Default 1000ms 256MiB

Pair Sum Query

Pair Sum Query

You are given an array of positive integers and a series of queries. Each query is specified by three integers \(l\), \(r\), and \(X\), which represent a subarray from index \(l\) to \(r\) (inclusive) and a target sum \(X\). Your task is to determine whether there exists a pair of distinct indices within the given subarray such that the sum of the two corresponding elements equals \(X\).

Formally, for each query, check if there exist indices \(i\) and \(j\) (with \(l \le i < j \le r\)) such that \(arr[i] + arr[j] = X\). All indices are 1-indexed.

You must read the input from standard input and write the results to standard output.

inputFormat

The input consists of multiple lines:

  1. The first line contains an integer \(N\) representing the number of elements in the array.
  2. The second line contains \(N\) positive integers separated by spaces, representing the array elements.
  3. The third line contains an integer \(Q\) denoting the number of queries.
  4. Each of the next \(Q\) lines contains three integers \(l\), \(r\), and \(X\) separated by spaces.

outputFormat

For each query, print a single line containing YES if there exists a valid pair in the subarray whose sum equals \(X\); otherwise, print NO.

## sample
5
1 2 3 4 5
3
1 4 5
2 5 7
1 5 10
YES

YES NO

</p>