#P4269. [USACO18FEB] Snow Boots G

    ID: 3200 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>2018线段树USACO单调队列排序队列整体二分

[USACO18FEB] Snow Boots G

题目描述

It's winter on the farm, and that means snow! There are NN tiles on the path from the farmhouse to the barn, conveniently numbered 1N1 \dots N, and tile ii is covered in fif_i feet of snow. In his farmhouse cellar, Farmer John has BB pairs of boots, numbered 1B1 \dots B. Some pairs are more heavy-duty than others, and some pairs are more agile than others. In particular, pair ii lets FJ step in snow at most sis_i feet deep, and lets FJ move at most did_i forward in each step.

Farmer John starts off on tile 11 and must reach tile NN to wake up the cows. Tile 11 is sheltered by the farmhouse roof, and tile NN is sheltered by the barn roof, so neither of these tiles has any snow. Help Farmer John determine which pairs of snow boots will allow him to make the trek.

输入格式

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 snow on tile ii (0fi1090 \leq f_i \leq 10^9). It's guaranteed that f1=fN=0f_1 = f_N = 0.

The next BB lines contain two space-separated integers each. The first integer on line i+2i+2 is sis_i, the maximum depth of snow in which pair ii can step. The second integer on line i+2i+2 is did_i, the maximum step size for pair ii. It's guaranteed that 0si1090 \leq s_i \leq 10^9 and 1diN11 \leq d_i \leq N-1.

输出格式

The output should consist of BB lines. Line ii should contain a single integer: 11 if Farmer John can trek from tile 11 to tile NN wearing the iith pair of boots, and 00 otherwise.

题目大意

到冬天了,这意味着下雪了!从农舍到牛棚的路上有 NN 块地砖,方便起见编号为 1N1 \dots N,第 ii 块地砖上积了 fif_i 英尺的雪。 在 Farmer John 的农舍的地窖中,总共有 BB 双靴子,编号为 1B1 \dots B。其中某些比另一些结实,某些比另一些轻便。具体地说,第 ii 双靴子能够让 FJ 在至多 sis_i 英尺深的积雪中行走,能够让 FJ 每步至多前进 did_i

Farmer John 从 11 号地砖出发,他必须到达 NN 号地砖才能叫醒奶牛们。11 号地砖在农舍的屋檐下,NN 号地砖在牛棚的屋檐下,所以这两块地砖都没有积雪。帮助 Farmer John 求出哪些靴子可以帮助他走完这段艰辛的路程。

【输入格式】

第一行包含两个空格分隔的整数 NNBB1N,B1051 \leq N,B \leq 10^5)。
第二行包含NN个空格分隔的整数;第 ii 个整数为 fif_i,即 ii 号地砖的积雪深度(0fi1090 \leq f_i \leq 10^9)。输入保证 f1=fN=0f_1 = f_N = 0

下面 BB 行,每行包含两个空格分隔的整数。第 i+2i+2 行的第一个数为 sis_i,表示第 ii 双靴子能够承受的最大积雪深度。第 i+2i+2 行的第二个数为 did_i,表示第 ii 双靴子的最大步长。输入保证 0si1090 \leq s_i \leq 10^9 以及 1diN11 \leq d_i \leq N-1

【输出格式】

输出包含 BB 行。第 ii 行包含一个整数:如果 Farmer John 能够穿着第 ii 双靴子从 11 号地砖走到 NN 号地砖,为 11,否则为 00

8 7
0 3 8 5 6 9 0 0
0 5
0 6
6 2
8 1
10 1
5 3
150 7
0
1
1
0
1
1
1

提示

Problem credits: Dhruv Rohatgi