QOJ.ac

QOJ

Time Limit: 0.75 s Memory Limit: 512 MB Total points: 100

#11266. Yuno loves sqrt technology I

Statistics

You are given a permutation of length $n$ and $m$ queries. Each query asks for the number of inversions in a given range. The problem must be solved online.

Input

The first line contains two integers $n$ and $m$.

The second line contains $n$ positive integers representing the permutation.

The following $m$ lines each contain two integers representing the query range.

This problem requires an online solution. For each query, the input numbers must be XORed with $lastans$. For the first query, $lastans = 0$.

Output

Output $m$ lines, each containing the answer to the corresponding query.

Constraints

$1\leq n,m\leq 10^5$.

We already have online algorithms with complexity better than $n^{1.5}$.

Examples

Input 1

4 1
1 4 2 3
2 4

Output 1

2

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.