ICPC 2019 Asia Danang Regional - Easy Query
Author: Benjamin Qi
Time Complexity:
The first step is to determine and for each query with a Wavelet tree. Once we have these values, we can answer the queries in decreasing order of with a segment tree.
We can do this by computing each of the 30 bits of independently. The -th bit of is equal to if there exists some value such that the following conditions hold:
- .
- The -th bit of is .
- The -th leftmost occurrence of among is less than or equal to (see
a[k] <= t[0]
in the code below.)
The indices of each segment tree correspond to the that appear in in increasing order. Each node of the -th segment tree corresponds to some -range , and stores the minimum such that is the -th occurrence of among for some .
#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!