text
stringlengths
2
104M
meta
dict
#pragma once #include <bits/stdc++.h> using namespace std; // Binary search a boolean function over a floating point range // Template Arguments: // T: the type of the range to search over, must be a floating point type // F: the type of the function that is being searched over // Function Arguments: // lo: the ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../datastructures/trees/fenwicktrees/FenwickTree1D.h" using namespace std; // Computes a longest increasing subsequence in an array // Template Arguments: // T: the type of each element in the array // Function Arguments: // A: a vector of type T // Return Value: a v...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Sum over subsets (or supersets) (similar to FST) // Transforms an array a into an array a' such that a'[i] is equal to the // aggregate of all a[j] such that i | j == i if TYPE == SUBSET // or i & j == i if TYPE == SUPERSET // Template Arguments: // T...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Solves the 0-1 knapsack problem (each item can appear either 0 or 1 times) // Template Arguments: // V: the value type // Function Arguments: // A: a vetor of pairs, with the first element of each pair being the weight // of type int, and the second...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Solves the multisubset sum problem with the occurrence of each sum (elements // can be chosen multiple times) // Template Arguments: // U: the type of the count // T: the type of each element in the array // Function Arguments: // A: a vector of typ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Solves the subset sum problem with the occurrence of each sum (elements // can be chosen 0 or 1 times) // Template Arguments: // U: the type of the count // T: the type of each element in the array // Function Arguments: // A: a vector of type T // ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the maximum sum of a non empty, non consecutive subsequence // Template Arguments: // T: the type of each element in the array // Function Arguments: // A: a vector of type T // NEG_INF: a value for negative infinity // Return Value: the maxi...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Solves the bounded knapsack problem (each item can appear up to a specified // number of times) // Template Arguments: // V: the value type // Function Arguments: // A: a vector of tuples, with the first element of each tuple being the // weight o...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the longest common subsequence between 2 arrays // Template Arguments: // T: the type of the elements in the arrays // Function Arguments: // A: the first array // B: the second array // Return Value: the length of the longest common subseque...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Knuth's Dynamic Programming Optimization // Must satisfy dp[l][r] = max(dp[l][m] + dp[m][r] + cost(l, m, r)) // for l <= m <= r and // max(l + 1, opt[l][r - 1]) <= opt[l][r] <= min(opt[l + 1][r], r - 1), // where opt[l][r] is the optimal value of m fo...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Solves the unbounded knapsack problem (each item can appear any number // of times) // Template Arguments: // V: the value type // Function Arguments: // A: a vetor of pairs, with the first element of each pair being the weight // of type int, and...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes a longest increasing subsequence in an array // Template Arguments: // T: the type of each element in the array // Function Arguments: // A: the array // Return Value: a vector of indices of the element in a longest increasing // subsequence ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Divide and Conquer Dynamic Programming Optimization // Must satisfy dp[k][i] = max(dp[k - 1][j] + cost(k, j, i)) // for 0 <= j <= i <= N and opt[k][i] <= opt[k][i + 1] where opt[k][i] is // the optimal value of j for dp[k][i] // Template Arguments: // ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the maximum sum of a non empty subarray // Template Arguments: // T: the type of each element in the array // Function Arguments: // A: a vector of type T // NEG_INF: a value for negative infinity // Return Value: a tuple with the maximum sum...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the minimum edit distance between 2 arrays, allowing for custom // penalties for copying, replacement, insertion, and deletion // Template Arguments: // T: the type of each element in the arrays // U: the type of the penalties // Function Arg...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../datastructures/trees/fenwicktrees/FenwickTree1D.h" using namespace std; // Counts inversions and sorts an array using a Fenwick Tree with a comparator // Template Arguments: // It: the type of the iterator // Cmp: the comparator to compare two values // Requir...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Sorts an array using shell sort with a comparator // Shell sort is not stable // Template Arguments: // It: the type of the iterator // Cmp: the comparator to compare two values // Required Functions: // operator (a, b): returns true if and on...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Helper function for inversion counting template <class InIt, class OutIt, class Cmp> long long countInversions(InIt st1, OutIt st2, int N, Cmp cmp, int len) { long long ret = 0; for (int lo = 0; lo < N; lo += len + len) { int mid = min(lo + len, N), h...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Mo's algorithm to answer offline ranges queries over // a static array A of length N where elements can be only added to a // multiset-like object // Template Arguments: // S: struct to maintain a multiset of elements // Required Fields: // T: t...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../datastructures/WaveletMatrix.h" using namespace std; // Supports online queries for the number of distinct elements in the // range [l, r] for a static array A of length N // Indices are 0-indexed and ranges are inclusive // Template Arguments: // T: the type of e...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Mo's algorithm to answer offline ranges queries over // a static array A of length N where elements can be added to and removed // from a multiset-like object // Template Arguments: // S: struct to maintain a multiset of the elements in the subarray [...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Uses divide and conquer to answer offline ranges queries over // a multiset where elements can be added or removed at anytime, but the // underlying data structure is only able to add and delete elements in LIFO // order, as well as save and restore i...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../datastructures/trees/fenwicktrees/BitFenwickTree.h" #include "../datastructures/WaveletMatrixAggregationOfflineUpdates.h" using namespace std; // Supports online queries for the number of distinct elements in the // range [l, r] for an array A of length N where the ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../datastructures/trees/fenwicktrees/BitFenwickTree.h" using namespace std; // Supports offline queries for the number of distinct elements in the // range [l, r] for a static array A of length N // Indices are 0-indexed and ranges are inclusive // Template Arguments: ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../datastructures/trees/fenwicktrees/SparseFenwickTrees2D.h" using namespace std; // Supports online queries for the number of distinct elements in the // range [l, r] for an array A of length N with point updates // Indices are 0-indexed and ranges are inclusive // Te...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Fast Subset Transform (similar to SumOverSubsets) // Template Arguments: // TYPE: the type of susbet transform (OR, AND, or XOR) // T: the type of each element // Function Arguments: // a: a reference to the vector of type T to transform // inv: a b...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "BinaryExponentiation.h" #include "ModularArithmetic.h" using namespace std; // Computes n! // Template Arguments: // T: the type of n // Function Arguments: // n: the value to find the factorial of, must be non negative // Return Value: n! // In practice has a very s...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "GCD.h" using namespace std; // Data structure representing a fraction // Template Arguments: // T: the type of the numerator and denominator, must be integral // Constructor Arguments: // num: the numerator // den: the denominator, should be non negative // Fields:...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Karatsuba Multiplication // Template Arguments: // T: the type of each element // ItA: the type of the iterator pointing to the first multiplyPolynomial // ItB: the type of the iterator pointing to the second polynomial // ItRes: the type of the ite...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the floor of the sqrt of an integer // Template Arguments: // T: the type of x, must be integral // Function Arguments: // x: the value to compute the sqrt of, must be non-negative // Return Value: returns the floor of the sqrt of x // In pract...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "ModularArithmetic.h" #include "GCD.h" #include "Primes.h" using namespace std; // Computes the nth tetration of a modulo mod // Assumes 0^0 = 1 // Template Arguments: // T: the type of base and mod // U: the type of the number of iterations // Function Arguments: // ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Given a set of N points, P[i] = (X[i], Y[i]), compute a polynomial Q of // degree N - 1, such that Q passes through them: // Q(x) = A[0] * x^0 + ... + A[N - 1] * x^(N - 1). // For real numbers, pick X[i] = C * cos(i / (N - 1) * PI) for a // large cons...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "GCD.h" using namespace std; // Computes the non negative remainder of a by mod // Template Arguments: // T: the type of a and mod // Function Arguments: // a: the value to find the non negative remainder // mod: the modulo // Return Value: the non negative remainde...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "FFT.h" using namespace std; // Big Integer // Constructor Arguments: // s: a string of digits // v: a long long // Functions: // read(s): reads a BigInt from a string // write(s): write a BigInt to a string // >>, <<: input and output operators // <, <=, >, ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Type templated greatest common divisor function // Always returns a non negative integer // Template Arguments: // T: the type of a and b // Function Arguments: // a: the first value // b: the second value // Return Value: the greatest common divisor ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "BinaryExponentiation.h" using namespace std; // Struct representing integers modulo MOD where MOD can change during runtime // Template Arguments: // T: the type of the integer, must be integral // Constructor Arguments: // x: the value to initialize the struct with ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the Kth term of a linear recurrence of length N // A[i] = sum (C[j] * A[i - 1 - j]) for 0 <= j < N // Template Arguments: // T: the type of the elements in the sequence // U: the type of K // Function Arguments: // A: a vector of the first ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Adds two nimbers a and b // Template Arguments: // T: the type of a, b, must be an unsigned integral type // Function Arguments: // a: the first value // b: the second value // Return Value: a + b with nimber addition // In practice, has a very small ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Helper functions template <class F, class T> T S(F &f, T a, T b) { return (f(a) + 4 * f((a + b) / 2) + f(b)) * (b - a) / 6; } template <class F, class T> T rec(F &f, T a, T b, T eps, T s) { T c = (a + b) / 2, S1 = S(f, a, c), S2 = S(f, c, b), SS = S1 +...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Given a sequence A of length N, compute a sequence C of minimum length M, // such that A[i] = sum (C[j] * A[i - 1 - j]) for 0 <= j < M // Template Arguments: // T: the type of the elements in the sequence // Function Arguments: // A: the sequence to f...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../datastructures/unionfind/UnionFindUndo.h" using namespace std; // Graphic Matroid for spanning forests // Constructor Arguments: // V: the number of vertices in the simple graph // edges: a vector of pairs in the form (v, w) representing // an undirected edge ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "BinaryExponentiation.h" #include "Primes.h" using namespace std; // Struct representing integers modulo MOD // Template Arguments: // T: the type of the integer, must be integral // MOD: the value to mod by, must be non negative // PRIME_MOD: a boolean indicating w...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Finds a candidate for the majority element with constant space // A second pass is required to ensure the candidate is actually a // majority element // Template Arguments: // F: the type of the function generating the elements // Function Arguments: //...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "ModularArithmetic.h" #include "Primes.h" using namespace std; // Helper function to find a primitive root for the mod p template <class T> T primitiveRoot(T p) { T phi = p - 1, n = phi; vector<T> pf; for (T i = 2; i * i <= n; i++) { if (n % i == 0) pf.push_back(i);...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "ModularArithmetic.h" #include "GCD.h" #include "../utils/Random.h" using namespace std; // constexpr function (in C++14 and above) to determine if x is prime // Template Arguments: // T: the type of x // Function Arguments: // x: the value to check if prime // Return...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes base to the power of pow // Template Arguments: // T: the type of base // U: the type of pow // Function Arguments: // base: the base // pow: the power, must be non negative and integral // Return Value: returns base to the power of pow // ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Solve the equation Ax = b for a matrix A of size M x N, and vectors b of // size M, and vector x of size N // Template Arguments: // T: the type of each element // Constructor Arguments: // A: a M x N matrix // b: a vector, with dimension M // EP...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Solve the xor boolean satisfiability problem for a boolean matrix A of // size M x N, and vectors b of size M, and vector x of size N, so that // b_i = xor(A[i][j] & x[j]) for 0 <= j < N; equivalent to solving the // equation Ax = b mod 2 for a matrix...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the basis of vectors in base 2 // Template Arguments: // BITS: the number of bits // Fields: // basis: a vector of bitsets of length BITS, with the ith element being the // reduced vector with the most significant bit of i, or empty if ther...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Fast Fourier Transform // Template Arguments: // F: the floating point type of the complex number components // Function Arguments: // a: a reference to the vector of complex numbers (of type complex<F>) // to convolute // In practice, has a moderat...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Two Phase Simplex to solve a linear programming problem with N variables // and M equations in canonical form: // max c^T x // subject to Ax <= b and x >= 0 // where A is an M x N matrix; b is a vector with dimension M; // c, x are vectors...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; template <class T> using Matrix = vector<vector<T>>; // Returns the size of the first dimension of a matrix // Template Arguments: // T: the type of each element in the matrix // Function Arguments: // A: the matrix // Return Value: the size of the first ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the maximum axis aligned rectangular area of a histogram where // all bars have width 1 // Template Arguments: // T: the type of the heights // Function Arguments: // A: a vector of the heights of each bar // Return Value: the maximum axis al...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "MaxRectAreaHistogram.h" using namespace std; // Computes the maximum submatrix of a boolean matrix where // all elements are true // Function Arguments: // A: a vector of vectors of booleans // Return Value: the maximum submatrix of the boolean matrix where // all ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes an array z, where z[i] is the length of the longest subarray // starting at S[i], which is also a prefix of S (maximum k such // that S[i + j] == S[j] for all 0 <= j < k) // Indices are 0-indexed and ranges are inclusive // T: the type of eac...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // KMP array searching // Indices are 0-indexed and ranges are inclusive // Template Arguments: // T: the type of each element in the array // Constructor Arguments: // pat: the pattern array // Fields: // N: the length of the pattern // fail: a vector...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Palindromic Tree Node backed by a map // Template Arguments: // _T: the type of the element in the string/array for the Palindromic Tree // Constructor Arguments: // len: the length of the longest palindromic substring represented // by this node //...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Modified from https://github.com/cheran-senthil/PyRival/blob/master/pyrival/strings/suffix_array.py, // which has an Apache 2.0 license // Suffix Array Induced Sort to sort suffixes of an array in // lexicographical order // Indices are 0-indexed and ra...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Factorizes a array S into Lyndon words w1w2w3... where w1, w2, w3, ... are // in non-increasing order // Guaranteed to exist and is unique // A Lyndon word is lexicographically smaller than all of its nontrivial // suffixes // Template Arguments: // T...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../datastructures/FischerHeunStructure.h" using namespace std; // Computes the longest common prefix of two suffixes of an array // be using the Fischer Heun Structure over the LCP array generated by the // Suffix Array // Indices are 0-indexed and ranges are inclusi...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Suffix Array using Sadakane's algorithm to sort suffixes of an array in // lexicographical order // Indices are 0-indexed and ranges are inclusive // Template Arguments: // _T: the type of each element in the array // Constructor Arguments: // S: a ve...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Finds the longest common subarray of two arrays // Indices are 0-indexed // Template Arguments: // SuffixArray: a generic suffix array to be used (should be either // SuffixArray or SAISSuffixArray) // Required Fields: // N: the length of ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../math/ModularArithmetic.h" #include "../utils/Random.h" using namespace std; // Computes the hash of a 2D array to allow for easy computation of // submatrix hashes // Indices are 0-indexed and ranges are inclusive // Template Arguments: // T: the type of each elem...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Trie Node backed by a map // Template Arguments: // _T: the type of the element in the string/array for the Trie // Fields: // T: the data type of each element in the string/array // link: a link to the parent in the trie // Functions: // hasEdge(a)...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Suffix Automaton Node backed by a map // Template Arguments: // _T: the type of the element in the string/array for the Suffix Automaton // Constructor Arguments: // len: the length of the longest substring represented by this node // Fields: // T: th...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Finds the minimum lexicographical rotation of an array // Template Arguments: // T: the type of each element in the array // Function Arguments: // S: a vector of type T // Return Value: the index of the first element of the minimum // lexicographical...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../math/ModularArithmetic.h" #include "../utils/Random.h" using namespace std; // Computes the hash of an array to allow for easy computation of // subarray hashes // Indices are 0-indexed and ranges are inclusive // Template Arguments: // T: the type of each element...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Finds the longest common subarray of multiple arrays // Indices are 0-indexed // Template Arguments: // SuffixArray: a generic suffix array to be used (should be either // SuffixArray or SAISSuffixArray) // Required Fields: // N: the lengt...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Computes the longest palindromic subarray centered at each half index // Indices are 0-indexed and ranges are inclusive // Template Arguments: // T: the type of each element in the array // Constructor Arguments: // S: a vector of type T // Fields: // ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Two players alternate taking coins from either end of a row. If both players // play optimally, what is the value of player 1's total minus // player 2's total? // The standard dp recurrence is // dp[l][r] = l > r ? 0 : max(A[l] - dp[l + 1][r], A[r] -...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Solves the maximum disjoint intervals problem // Given a set of intervals in the form [L, R], find the maximum number of // disjoint intervals // Maximum number of disjoint intervals is equivalent to the minimum number of // points to cover each interva...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Solves the minimum interval cover problem // Given a set of intervals in the form [L, R], find the minimum number of // intervals to cover a target interval // Range is modified in-place // Template Arguments // T: the type of the endpoints of the inter...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> // Unsyncs the C++ and C std output streams and unties cin to // speed up standard input void unSyncUntie() { std::ios::sync_with_stdio(0); std::cin.tie(0); } // Functions for fast IO namespace IO { #define INTERACTIVE_INPUT 0 template <class T> struct is_iterator { tem...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // With C++ 11 not having std::make_unique defined, a simple implementation // of make_unique is provided // Template Arguments: // T: the type of the object to construct // ...Args: variadic arguments of the types of the arguments being passed to // ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Functions for __int128_t __int128_t abs(__int128_t a) { return a >= 0 ? a : -a; } #define FUN(name) \ long double name(__int128_t a) { return name((long double)(a)); } FUN(sqrt) FUN(sin) FUN(cos) FUN(tan) FUN(asin) FUN(acos) FUN(atan) #undef FUN long doub...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Static allocator to improve the speed of memory access // Tested: // https://dmoj.ca/problem/ioi12p3 constexpr const int MB = 200; char buf[MB << 20]; size_t buf_ind = sizeof(buf); // Overloading new and delete operators void *operator new (size_t n) { r...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Functions for epsilon comparison of floating points using T = long double; constexpr const T EPS = 1e-9; bool lt(T a, T b) { return a + EPS < b; } bool le(T a, T b) { return !lt(b, a); } bool gt(T a, T b) { return lt(b, a); } bool ge(T a, T b) { return !lt(...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #if __cplusplus < 201402L #include "MakeUnique.h" #endif using namespace std; // 32-bit and 64-bit random number generators using a time-based seed sequence // Tested: // https://dmoj.ca/problem/set // https://atcoder.jp/contests/agc026/tasks/agc026_c // https://dmoj.ca/prob...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Combine struct used for maximum non empty subarray // for Segment Trees, Dynamic Range Operations, Link Cut Trees, etc // Template Arguments: // T: the type of the element // Functions: // makeData(v): returns a MaxSubarraySumCombine<T>::Data initiali...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Maintains the aggregate value of a sequence of elements over an associative // operation where elements can be pushed to the back and popped from the // front of the queue // Template Arguments: // T: the type of each element // Op: a struct with th...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/priority_queue.hpp> #include <ext/pb_ds/tree_policy.hpp> #include "RandomizedHash.h" using namespace std; using namespace __gnu_pbds; // Policy-based data structures for ordered and unordered sets and maps, // as well ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Maintains the difference between adjacent elements in a sorted multiset // Template Arguments: // T: the type of the elements being stored // Fields: // vals: a mapping from the values in the multiset to its frequency // diffs: a mapping from the diff...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Sparse Table supporting associative and idempotent range queries on // a static array // Indices are 0-indexed and ranges are inclusive // Template Arguments: // T: the type of each element // Op: a struct with the operation (can also be of type // ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Helper struct to compare two pairs template <class Cmp> struct PairCmp { Cmp cmp; PairCmp(Cmp cmp = Cmp()) : cmp(cmp) {} template <class T> bool operator () (const pair<T, T> &a, const pair<T, T> &b) const { if (cmp(a.first, b.first)) return true;...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "FischerHeunStructure.h" using namespace std; // Fischer Heun Structure in 2 dimensions supporting range maximum queries on // a static 2D array // Indices are 0-indexed and ranges are inclusive // Template Arguments: // T: the type of each element // Cmp: the compa...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // A map that supports insertions of a key value pair (k, v) and // queries for the maximum value (based on VCmp) of v for // all keys less than or equal to (based on KCmp) k // Template Arguments: // K: the type of the key // V: the type of the value ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "BitPrefixSumArray.h" using namespace std; // Wavelet Matrix supporting rank and select operations for a subarray // Indices are 0-indexed and ranges are inclusive // Template Arguments: // T: the type of the element of the array // Cmp: the comparator to compare two ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // 2D Sparse Table supporting associative and idempotent range queries on // a static 2D array // Indices are 0-indexed and ranges are inclusive // Template Arguments: // T: the type of each element // Op: a struct with the operation (can also be of type...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Disjoint Sparse Table supporting associative range queries on a static array // Indices are 0-indexed and ranges are inclusive // Template Arguments: // T: the type of each element // Op: a struct with the operation (can also be of type // std::fu...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Prefix Sum Array supporting range sum queries where all values are 0 or 1, // and all values are set before all queries // Indices are 0-indexed and ranges are inclusive // Constructor Arguments: // N: the size of the array // Functions: // set(i, v):...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Supports online queries and FIFO operations on a multiset of elements, // where the underlying data structure only supports LIFO operations // Template Arguments: // S: struct to maintain a multiset of elements // Required Fields: // T: the type o...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../utils/Random.h" using namespace std; const size_t RANDOM = uniform_int_distribution<size_t>( 0, numeric_limits<size_t>::max())(rng64); // Randomized hash for types with std::hash defined and for pairs // Tested: // https://dmoj.ca/problem/set // https://atcod...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Fischer Heun Structure supporting range maximum queries on a static array // Indices are 0-indexed and ranges are inclusive // Template Arguments: // T: the type of each element // Cmp: the comparator to compare two values, // convention is same a...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "WaveletMatrixAggregation.h" using namespace std; // Wavelet Matrix supporting 2D aggregation queries where the data can change, // and the indices and the keys that are updated are known beforehand // Indices are 0-indexed and ranges are inclusive // Queries bounded by...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // A collections of functions for 2D prefix sum and difference arrays // Creates a prefix sum array pre from the 2D array A of size N x M // pre[i][j] is the sum of all elements in the subarray A[0..i][0..j] // Indices are 0-indexed // In practice, has a smal...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "BitPrefixSumArray.h" using namespace std; // Wavelet Matrix supporting 2D aggregation queries where the data can change, // but not the keys // Indices are 0-indexed and ranges are inclusive // Queries bounded by 3 indices require a commutative operation, while queries...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Maintains the rank of an element in a multiset // Indices are 0-indexed and ranges are inclusive // Template Arguments: // T: the type of the values being stored // Cmp: the comparator to compare two f(x) values, // Required Functions: // oper...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Decomposes the array recursively into N ^ (1 / R) containers of // size N ^ ((R - 1) / R) multiplied by a scale factor // Indices are 0-indexed and ranges are inclusive // Template Arguments: // R: the number of recursive levels // T: the type of data...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> using namespace std; // Maintains the rank of an element in a multiset, allowing for multiple // insertions of the same element at the same time (including negative) // Note that elements with a count of 0 or negative are still in the multiset // as elements cannot be removed ...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }
#pragma once #include <bits/stdc++.h> #include "../trees/PersistentArray.h" using namespace std; // Persistent Union Find by size where copy assignment/constructor creates // a new version of the data structure // Indices are 0-indexed // Constructor Arguments: // N: the number of elements in the set // Fields: //...
{ "repo_name": "wesley-a-leung/Resources", "stars": "34", "repo_language": "C++", "file_name": "SkewHeapIncremental.h", "mime_type": "text/x-c++" }