Parallel Binary Search
Author: Muaath Alqarni
Answering multiple binary search queries parallelly
Prerequisites
Resources
Resources | ||||
---|---|---|---|---|
CF |
Focus Problem – try your best to solve this problem before continuing!
View Internal SolutionSolution - 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 .
Now let's use parallel binary search: Sweep through the array of edges and union them in the DSU, whenevery you find a query its median = , if the two nodes where connected, it means shrink to left, otherwise shrink to right.
You need to do the sweep times, so you know the exact time the nodes where connected. And you need to sort the queries by median before every sweep thats And for the DSU
Total Complexity:
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
Status | Source | Problem Name | Difficulty | Tags | |
---|---|---|---|---|---|
HR | Easy | Show TagsDSU, PBS | |||
AC | Easy | Show TagsDSU, PBS | |||
COCI | Normal | 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!