Snow Boots

For each of B boots with limits on snow depth and step length, decide whether the farmer can walk from tile 1 to tile N, landing only on tiles whose snow is shallow enough.

Hard8Binary searchSortingGreedyArrayInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

Winter has arrived at the farm, and with it snow. The path from the farmhouse to the barn is made of NN tiles, numbered 11 through NN starting at the house, and tile ii is covered in fif_i feet of snow.

The farmer keeps BB pairs of boots in the cellar, numbered 11 through BB. Some pairs are sturdier than others and some are lighter than others. Pair ii lets the farmer step in snow at most sis_i feet deep, and lets him move at most did_i tiles forward in one step.

The farmer starts on tile 11 and has to reach tile NN to wake the cows. The farmhouse roof covers tile 11 and the barn roof covers tile NN, so neither tile has snow on it.

One step moves the farmer forward by at least 11 and at most did_i tiles, and the tile he lands on must be covered by at most sis_i feet of snow. The snow on the tiles he passes over does not matter. For each pair of boots, decide whether the farmer can get from tile 11 to tile NN.

Input

The first line contains two space separated integers NN and BB (1N,B1051 \leq N, B \leq 10^5).

The second line contains NN space separated integers. The iith integer is fif_i, the depth of the snow on tile ii (0fi1090 \leq f_i \leq 10^9). It is guaranteed that f1=fN=0f_1 = f_N = 0.

Each of the next BB lines contains two space separated integers. The first integer on line i+2i+2 is sis_i, the maximum depth of snow that pair ii can step in. The second integer is did_i, the maximum number of tiles pair ii can move forward in one step (0si1090 \leq s_i \leq 10^9, 1diN11 \leq d_i \leq N-1).

Output

Print BB lines. Line ii contains 11 if the farmer can walk from tile 11 to tile NN wearing pair ii, and 00 otherwise.