Parallel Binary Search
Author: Talha Taki
Parallel binary search optimizes query efficiency by splitting queries based on the relevance of specific ranges within the binary search. Rather than repeatedly querying the same range, this technique intelligently divides the search process to enhance overall performance.
Prerequisites
Focus Problem – try your best to solve this problem before continuing!
View Internal SolutionResources | ||||
---|---|---|---|---|
Robert's Blog | ||||
CF |
Tutorial
This section is not complete.
Pseudocode
Let corresponds to some stuff that needed be done at that particular index ()
For all levels, we maintain independent data structure . Associated with every data structure we have our monotonic function and for maintaining ongoing events at that level.
A pseudocode for parallel binary search looks something like this:
parallel_binary_search(l, r, level, candidate): m = candidate.size if m == 1: for i = 0 to m-1: ans[candidate[i]] = l candidate.clean() return mid = floor((l + r) / 2) while pointer[level] <= mid: DS[level].add(event[pointer[level]]) pointer[level] = pointer[level] + 1 for i = 0 to m-1: if DS[level].f(lo, mid, candidate[i]) == True: satisfied_candidate.add(candidate[i]) else: unsatisfied_candidate.add(candidate[i]) candidate.clean() parallel_binary_search(l, mid, level + 1, satisfied_candidate) parallel_binary_search(mid + 1, r, level + 1, unsatisfied_candidate) // Calculating answers for the range [lo, hi] where `relevant_candidate` belongs to that range parallel_binary_search(lo, hi, 0, relevant_candidate)
Generalized Complexity
This section is not complete.
C++
Solution - New Road Queries
In this problem, the required data structure is DSU for knowing whether there is a path between two vertexes after adding some edges of the graph. Here:
= Add th edge.
=
=
#include <bits/stdc++.h>using namespace std;typedef pair<int, int> pii;const int MAX_LOG = 20;struct Disjoint_Set_Union {int n;
Problems
This section is not complete.
- Tags, difficulty yet to be justified.
- Internal solutions need to be added.
- More problems are welcomed
Status | Source | Problem Name | Difficulty | Tags | |
---|---|---|---|---|---|
AC | Easy | Show Tagsbinary-search, dsu | |||
COCI | Normal | Show Tagspersistent | |||
POI | Normal | Show TagsPURS, binary-search | |||
TC | Normal | ||||
HDU | Normal | ||||
HR | Hard |
Module Progress:
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!