KQUERYO - K-Query Online
Given a sequence of n numbers a1, a2, ..., an and a number of k-queries. A k-query is a triple (i, j, k) (1 ≤ i ≤ j ≤ n). For each k-query (i, j, k), you have to return the number of elements greater than k in the subsequence ai, ai+1, ..., aj.
Input
- Line 1: n (1 ≤ n ≤ 30000).
- Line 2: n numbers a1, a2, ..., an (1 ≤ ai ≤ 109).
- Line 3: q (1 ≤ q ≤ 200000), the number of k- queries.
- In the next q lines, each line contains 3 numbers a, b, c representing a k-query. You should do the following:
- i = a xor last_ans
- j = b xor last_ans
- k = c xor last_ans
Where last_ans = the answer to the last query (for the first query it's 0).
Output
For each k-query (i, j, k), print the number of elements greater than k in the subsequence ai, ai+1, ..., aj in a single line.
Example
Input: 6 8 9 3 5 1 9 5 2 3 5 3 3 7 0 0 11 0 0 2 3 7 4 Output: 1 1 0 0 2
[Edited by EB]
There are invalid queries. Assume the following:- if i < 1: i = 1
- if j > n: j = n
- if i > j: ans = 0
hide comments
Satyaki Upadhyay:
2015-04-19 17:48:25
After the execution of the third query, the answer is 0. So, for the fourth query, the actual range is [0^0, 0^0] which is [0, 0] but doesn't lie in the range [1, n]. Is this a mistake or is the test case fine?
|
Added by: | amirmd76 |
Date: | 2015-04-17 |
Time limit: | 0.200s |
Source limit: | 50000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | All |