Under construction

Still being built. Things may change

Great Party

Time limit1sMemory limit1024 MB

Summary
For each query range [l, r], count the sub-segments whose stone piles give the first player a win in the merge-and-remove game.
Level

Hard9 of 10

Topics
Game theory, Bit manipulation, Two pointers
Solved
No attempts yet

Problem

Grammy joined a great party.

There is an interesting game at the party. There are nn piles of stones on the table. The ii-th pile has aia_i stones. Two players take turns operating the stones.

On each turn, a player does the following two steps:

  1. Select a non-empty pile and remove a positive number of stones from it.
  2. Either keep the remaining stones in that pile, or merge all of them into another non-empty pile.

A player who cannot operate loses the game.

Grammy has qq questions. For each question, count the sub-segments of [l,r][l, r] for which the first player wins when the piles in that sub-segment are played alone as a game.

Input

The first line contains two integers nn and qq (1≤n,q≤1051 \leq n, q \leq 10^5).

The second line contains nn integers a1,a2,…,ana_1, a_2, \ldots, a_n (1≤ai≤1061 \leq a_i \leq 10^6).

The ii-th of the next qq lines contains two integers lil_i and rir_i (1≤li≤ri≤n1 \leq l_i \leq r_i \leq n).

Output

The output contains qq lines. Each line contains a single integer, the answer to the question.

Examples2

  1. Example 1

    Input
    4 5
    1 2 2 4
    1 2
    2 3
    3 4
    1 3
    2 4
    
    Expected output
    3
    2
    3
    5
    5
    
  2. Example 2

    Input
    4 5
    5 6 7 8
    1 2
    2 3
    3 4
    1 3
    2 4
    
    Expected output
    3
    3
    3
    6
    6