QOJ.ac

QOJ

Time Limit: 10 s Memory Limit: 1024 MB Total points: 100 Hackable ✓

#8739. 古明地枣的袜子

统计

你需要维护一个序列 $a_1,\dots,a_n$ 。

给定一个操作序列 $(x_1,y_1),\dots,(x_n,y_n)$ ,操作 $(x,y)$ 表示将 $a_1,\dots,a_x$ 的值加上 $y$ 。

共 $m$ 次查询,每次查询给出 $l,r$ ,问对初始值为 $0$ 的序列 $a$ 依次执行操作 $(x_l,y_l),\dots,(x_r,y_r)$ ,最后 $\mathop\max\limits_{i=1}^n a_i$ 的值。

Input

第一行两个整数 $n,m$ ($1\le n,m\le 5\times 10^5$);

接下来 $n$ 行每行两个整数 $x_i,y_i$($1\le x_i\le n, |y_i|\le n$);

接下来 $m$ 行,每行两个整数 $l,r$($1\le l\le r\le n$)。

Output

输出 $m$ 行,每行一个整数,表示每次查询的答案。

Example

Input

6 5
6 4
2 6
5 -5
3 6
1 2
3 6
1 6
1 6
2 6
2 6
5 6

Output

19
19
15
15
8

Discussions

About Discussions

The discussion section is only for posting: Editorials, 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 1
IDTypeStatusTitlePosted ByLast UpdatedActions
#269EditorialOpenEditorial for #8739pystraf2025-12-13 13:50:29View

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. Submitting multiple issues may cause your account to be banned.
  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.