mixed.hpp

BigInt

See BigInt for detail.

Complexity

  • add, sub:
  • mul, div:

where is the length of number in decimal.

GospersHack

void GospersHack(int n, int k)

brute-force all case: choose , 1 stand for choosen

you should implement it to meet to feed your needs

Complexity

twoSumCount

int twoSumCount(int n, int d)

return

KnuthShuffle

template<typename T>
void KnuthShuffle(std::vector<T>& a)

Knuth Shuffle Algorithm

Complexity

uniformChoose

std::vector<int> uniformChoose(int n, int m)

Choose distinct elements from with equal probability using the ideal of Knuth Shuffle Algorithm

Complexity

Constraints

Fib

int Fib(int n, int M)

return -th Fibonacci number mod .

Complexity

floorSum

LL floorSum(int n, int m, int a, int b)

Complexity

sumNum

int sumNum(const std::vector<int>& c, int m, int M)

Complexity

decInc

int decInc(int n, int m)

count min time: every time --n or ++m s.t.

Complexity

Example

FirstInRange

int FirstInRange(int a, int m, int l, int r)

finds min s.t. (or -1 if it does not exist)

Constraints

Complexity

RecSeq

template<typename T> // use ModInt, MInt, ModLL
class RecSeq : public std::vector<T>;

It is used to avoid use matrix multiplication in dp

Gauss

std::vector<double> Gauss(std::vector<std::vector<double>> A, std::vector<double> b)

Gauss-Jordan Elimination , float version, Inspire by spookywooky

Complexity

GaussModp

std::vector<valT> GaussModp(std::vector<std::vector<valT>> A, std::vector<valT> b)

Gauss-Jordan Elimination , mod version

Complexity

GaussXor

std::vector<valT> GaussXor(std::vector<std::vector<valT>> A, std::vector<valT> b)

Gauss-Jordan Elimination , xor version

Complexity

simplex

using VD = std::vector<double>
VD simplex(VD c, std::vector<VD> Aq, VD bq, std::vector<VD> Alq, VD blq)

Simplex algorithm for linear programming: compute max

with constraints: and

Karatsuba

using VL = std::vector<LL>
VL Karatsuba(VL a, VL b, LL p)

Polynomial multiplication with arbitrary modulus

Complexity

There is a parallel version of Karatsuba(you may need -lpthread to complier): KaratsubaParallel

quadrangleItvDp

std::vector<std::vector<T>> quadrangleItvDp(std::vector<std::vector<T>> w, int n)

It is a common tech for Segment DP optim: to

Complexity

quadrangleRollDp

std::vector<std::vector<T>> quadrangleRollDp(std::vector<std::vector<T>> w, int n, int m)

It is a common tech for oll DP optim: to

Complexity

PalindromeNumber

It is a singleton class. Recall that is a Palindrome Number if it's digits representation is a palindrome, for example 1, 121, 33, 23532 are Palindrome Number which 132, 112 are not.

LL nthPalindrome(int k)

return -th Palindrome Number.

Constraints

Complexity

Example

int Palindrome(LL n)

return numbers of Palindrome less that

Constraints

Complexity

Example

LL solve(LL n, int k) { return nthPalindrome(k + Palindrome(n)); }

return -th Palindrome Number greater than or equal to

fast powMod

unsigned fastPowMod998244353(unsigned x, unsigned n);  // 40% faster
unsigned fastPowMod1000000007(unsigned x, unsigned n); // 18% faster
unsigned fastPowMod1000000009(unsigned x, unsigned n); // 18% faster
Node* copyRandomList(Node* head)