#9483. [USACO16DEC] Counting Haybales S

    ID: 9483 传统题 1000ms 125MiB 尝试: 1 已通过: 0 难度: 10 上传者: 标签>P31842016线段树二分USACO树状数组离散化排序前缀和

[USACO16DEC] Counting Haybales S

[USACO16DEC] Counting Haybales S

题目描述

Farmer John has just arranged his $N$ haybales ($1 \leq N \leq 100,000$) at various points along the one-dimensional road running across his farm. To make sure they are spaced out appropriately, please help him answer $Q$ queries ($1 \leq Q \leq 100,000$), each asking for the number of haybales within a specific interval along the road.

输入格式

The first line contains $N$ and $Q$.

The next line contains NN distinct integers, each in the range 0…1,000,000,0000 \ldots 1,000,000,000, indicating that there is a haybale at each of those locations.

Each of the next QQ lines contains two integers AA and BB(0≤A≤B≤1,000,000,0000 \leq A \leq B \leq 1,000,000,000) giving a query for the number of haybales between AA and BB, inclusive.

输出格式

You should write $Q$ lines of output. For each query, output the number of haybales in its respective interval.
4 6
3 2 7 5
2 3
2 4
2 5
2 7
4 6
8 10
2
2
3
4
1
0

提示

(暂无提示) 标签: P3184|2016|线段树|二分|USACO|树状数组|离散化|排序|前缀和

来源

P3184|[USACO16DEC] Counting Haybales S