YS - Static Range Inversions Query

Author: Benjamin Qi

Solution 1

Naive solution as described in the linked CF Blog.

Time Complexity: O(QNlogN)\mathcal{O}(Q\sqrt N\log N)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!
using pi = pair<int,int>;
using pl = pair<ll,ll>;

Solution 2

"sweepline mo"

Time Complexity: O(QN)\mathcal{O}(Q\sqrt N)

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using db = double;
using str = string; // yay python!
using pi = pair<int,int>;
using pl = pair<ll,ll>;

Join the USACO Forum!

Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!