PrevNext
Has Not Appeared
 0/3

Parallel Binary Search

Author: Muaath Alqarni

Answering multiple binary search queries parallelly

Edit This Page

Resources

StatusSourceProblem NameDifficultyTags
CSESEasy
Show TagsDSU, PBS

Solution - New Roads Queries

Let's think how to binary search a single query. It's clear that we can use DSU with linear search, but also we can do binary search with DSU in O(Nlog2N)O(N \cdot \log_2{N}).

Now let's use parallel binary search: Sweep through the array, whenevery you find a query its median = ii, you will shrink it either to left or right. You need to do the sweep O(log2N)O(\log_2{N}) times, so every query is processed. Total Complexity: O((N+Q)log2N)O((N + Q) \cdot \log_2{N})

Implementation - New Roads Queries

C++

#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
using namespace std;
const int N = 2e5 + 1;
int n, m, q;
vector<pii> edges;

Problems

StatusSourceProblem NameDifficultyTags
ACEasy
Show TagsDSU, PBS
COCINormal
Show TagsPBS, Segtree

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!

PrevNext