Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

8/27/2021 Newton School

Newton School PL

back
Save and Run Hidden Test
Newton's Grand Contest 2021 - Ultron's Army (Public Contest: August 2021) by Pranav 01:42:36
Run Cases
Lad

Ultron's Army (Public Contest: August 2021)

standard input/output: 1.5s/256000 kB

There are N robots standing in a row. Ultron wants to delegate a task of difficulty X to two of them. Each robot has its own ability, A[i] for the ith robot from the left. The task
can only be completed if the sum of the abilities of the two robots is exactly equal to X. Ultron wants to find out the number of distinct unordered pairs of robots he can
choose to complete this task. He wants to find this number for Q (not necessarily distinct) subarrays of robots.

Formally, for each query, you will be given two integers L and R and you need to calculate the number of pairs (i, j) such that L ≤ i < j ≤ R and A[i] + A[j] = X.

Further, these subarrays have a nice property that for every pair of them at least one of the following three statements hold:

1. Their intersection is one of the two intervals itself (for example, segments [2, 6] and [2, 4]).

2. Their intersection is empty (for example, segments [2, 6] and [7, 8]).

3. Their intersection consists of exactly one element (for example, segments [2, 5] and [5, 8]).

For another example, note that the segments [2, 5] and [4, 7] do not satisfy any of the above conditions, and thus cannot both appear in the input.

You need to find the answer to each one of Ultron's queries and report the XOR of their answers.

Note: Since the input is large, it is recommended that you use fast input/output methods.

Input
The first line of the input contains two space-separated integers, N, the number of robots and X, the difficulty of the task.

The second line contains N space-separated integers A[1], A[2], ... A[n] - the abilities of the robots.

The third line of input contains an integer Q - the number of queries Ultron has.

Q lines follow, the ith of them contains two integers L and R for the ith query.

It is guaranteed that the given subarrays satisfy the properties mentioned in the problem statement.

Constraints:
2 ≤ N ≤ 400000

1 ≤ X ≤ 1000000

0 ≤ A[i] ≤ X

1 ≤ Q ≤ 400000

1 ≤ L < R ≤ N for each query

Output
Print a single integer, the bitwise XOR of the answers of the Q queries.

Example
Sample Input:
7 10
2 9 1 8 4 4 6
5
1 7
2 5
1 6
3 4
4 5
 
Sample Output:

Code Reset C++ (GCC 9.2.0) Custom Input


1
1 #include <bits/stdc++.h> // header file includes every Standard library
2 using namespace std;
3  
4 int main() {
5  
6     // Your code here
7     return 0;
8 }
9  

STDOUT STDERR COMPILE OUTPUT MESSAGE


1

Help

https://my.newtonschool.co/playground/code/0o5npm4ozef6/ 1/2
8/27/2021 Newton School
Test Cases Previous Submissions

Test case 0 Hidden test case Status Test Cases Passed

Test case 1

Test case 2

Test case 3

Test case 4

Test case 5

Test case 6

Test case 7

Test case 8

Test case 9

Test case 10

© 2021 Incanus Technologies Pvt Ltd


For any queries, you can reach us at Follow us on
All rights reserved. (Terms) support@newtonschool.co

https://my.newtonschool.co/playground/code/0o5npm4ozef6/ 2/2

You might also like