All submissions for this problem are available.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Given an array A with n elements. There are q queries of the form (l, r). For each query you need to find the number of pairs (i, j) such that l ≤ i ≤ j ≤ r and and which satisfies the following condition: Ai ≤ Ai ^ Ai + 1 ≤ ... ≤ Ai ^ Ai + 1 ^ ... ^ Aj, where ^ is XOR.
- The first line contains one integer n, denoting the number of elements.
- The second line contains n space-separated integers: A1, A2, ... , An .
- The third line contains one integer q, denoting the number of queries.
- The i-th of the next q lines contains two integers: ai, bi. This is explained below.
You need to find the answers to the queries online, and so, the queries are encoded. To decode the queries from the data given in input, you need to perform the following transformations:
li = (ai + ansi-1) mod n + 1
ri = (bi + ansi-1) mod n + 1
Where ansi-1 is the answer for the previous query. (li, ri) is the decoded i-th query, for which you need to find and output the answer. Assume that ans0 = 0. The first query is (l1, r1).
For each query print the answer on a single line.
- 1 ≤ n, q ≤ 4 * 105
- 0 ≤ Ai ≤ 109
- 0 ≤ ai, bi < n
- 1 ≤ li ≤ ri ≤ n after decoding
Input: 4 1 2 3 4 3 1 3 0 3 3 1 Output: 4 6 4
|Time Limit:||2 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.5, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions
If you are still having problems, see a sample solution here.