luogu#P5047. [Ynoi2019 模拟赛] Yuno loves sqrt technology II

[Ynoi2019 模拟赛] Yuno loves sqrt technology II

Background

Problem Description

You are given a sequence aa of length nn and mm queries. For each query, you need to find the number of inversion pairs in a given interval.

Input Format

The first line contains two integers n,mn, m.

The second line contains nn integers representing the sequence.

Then follow mm lines, each containing two integers representing the query interval.

Output Format

Output mm lines, each with one integer representing the answer to the query.

4 1
1 4 2 3
2 4
2

Hint

1n,m1051 \leq n, m \leq 10^5, 0ai1090 \leq a_i \leq 10^9.

We already have an algorithm faster than n1.5n^{1.5}.

Source
By nzhtl1477

Translated by ChatGPT 5