QOJ.ac

QOJ

Time Limit: 2 s Memory Limit: 256 MB Total points: 100

#21189. 數乾草捆

Statistics

Farmer John 剛把他的 $N$ 捆乾草($1 \leq N \leq 100,000$)放在貫穿農場的一維道路上的不同位置。為了確保它們間距合適,請幫助他回答 $Q$ 個詢問($1 \leq Q \leq 100,000$),每個詢問要求計算道路上某個指定區間內的乾草捆數量。

輸入格式

第一行包含 $N$ 和 $Q$。

下一行包含 $N$ 個互不相同的整數,每個整數都在 $0 \ldots 1,000,000,000$ 範圍內,表示這些位置各有一捆乾草。

接下來 $Q$ 行,每行包含兩個整數 $A$ 和 $B$($0 \leq A \leq B \leq 1,000,000,000$),表示詢問 $A$ 到 $B$ 之間(含兩端)的乾草捆數量。

輸出格式

你應輸出 $Q$ 行。對於每個詢問,輸出其對應區間內的乾草捆數量。

範例

輸入格式 1

4 6
3 2 7 5
2 3
2 4
2 5
2 7
4 6
8 10

輸出格式 1

2
2
3
4
1
0

題目作者:Nick Wu

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.