Solution Of P11015 Inversion Pair
Solution
我们注意到对于任意长度为
证明显然。
因此我们对于每一次
AC-Code
以下是 Drifty 给出的实现。
#include <bits/stdc++.h>
using namespace std;
constexpr int N = 3e5 + 7;
int a[N], n, q, s[N];
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
cin >> n >> q;
for (int i=1; i<=n; i++)
cin >> a[i], s[i] = s[i - 1] + (a[i] < a[i - 1]);
for (int x, y; q--; ) {
cin >> x >> y;
if (x > y) swap(x, y);
cout << s[y] - s[x] << '\n';
}
return 0;
}