Infer the algorithm complexity and algorithm content from the data range

Generally, the time limit for ACM or written test questions is 1 or 2 seconds.
In this case, the number of operations in the C++ code should be limited to 107107.

The following shows how to choose the time complexity of the code and the algorithm under different data ranges:

n≤30n≤30, exponential level, dfs+pruning, state compression dp
n≤100n≤100 => O(n3)O(n3), floyd, dp
n≤1000n≤1000 => O(n2)O(n2) , O(n2logn)O(n2logn), dp, bisection, naive version of Dijkstra, naive version of Prim, Bellman-Ford
n≤10000n≤10000 => O(n∗n√)O(n∗n), block linked list, Blocking , Mo team
n≤100000n≤100000 => O(nlogn)O(nlogn) => various sorts, line segment tree, tree array, set/map, heap, topological sort, dijkstra+heap, prim+heap, spfa, convex hull, half-plane intersection, bisection
n≤1000000n≤1000000 => O(n)O(n), and O(nlogn)O(nlogn) algorithm with smaller constant => hash, double pointer scan, And check the set, kmp, AC automata, the practice of O(nlogn)O(nlogn) with a small constant: sort, tree array, heap, dijkstra, spfa
n≤10000000n≤10000000 => O(n)O(n ), double pointer scanning, kmp, AC automaton, linear sieve prime
n≤109n≤109 => O(n√)O(n), judging prime
n≤1018n≤1018 => O(logn)O(logn), Greatest common divisor, fast power
n≤101000n≤101000 => O((logn)2)O((logn)2), high-precision addition, subtraction, multiplication and division
n≤10100000n≤10100000 => O(logn×loglogn)O(logn× loglogn), high-precision addition and subtraction, FFT/NTT

Author: yxc
Link: https://www.acwing.com/blog/content/32/
Source: AcWing
Copyright belongs to the author. For commercial reprints, please contact the author for authorization, and for non-commercial reprints, please indicate the source.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325951423&siteId=291194637