QOJ.ac

QOJ

時間限制: 10 s 記憶體限制: 1024 MB 總分: 100 可 Hack ✓

#8739. Koishi's Socks

统计

You need to maintain a sequence $a_1, \dots, a_n$.

Given a sequence of operations $(x_1, y_1), \dots, (x_n, y_n)$, an operation $(x, y)$ adds $y$ to the values of $a_1, \dots, a_x$.

There are $m$ queries. Each query provides $l$ and $r$, and asks for the value of $\mathop\max\limits_{i=1}^n a_i$ after performing the operations $(x_l, y_l), \dots, (x_r, y_r)$ sequentially on a sequence $a$ initialized to $0$.

Input

The first line contains two integers $n$ and $m$ ($1\le n, m\le 5\times 10^5$).

The next $n$ lines each contain two integers $x_i$ and $y_i$ ($1\le x_i\le n, |y_i|\le n$).

The next $m$ lines each contain two integers $l$ and $r$ ($1\le l\le r\le n$).

Output

Output $m$ lines, each containing an integer representing the answer to each query.

Examples

Input 1

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 1

19
19
15
15
8

Editorials

IDTypeStatusTitlePosted ByLast UpdatedActions
#269EditorialOpenEditorial for #8739pystraf2026-03-12 17:00:33View

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.