YS - Static Range Inversions Query

Author: Benjamin Qi

Table of Contents

Solution 1Solution 2

Solution 1

Naive solution as described in the linked CF Blog.

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

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int N = 1e5 + 1;
const int S = 300;

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!