/* VIM: let b:cf5build="clang -std=c++20 -O2 -pthread -lstdc++ -I. {SRC} -o {OUT}" VIM: let b:cf5run="{OUT}" */ #include #include #include #include #include #include #include #include /* https://app.codility.com/programmers/lessons/99-future_training/array_inversion_count/ An array A consisting of N integers is given. An inversion is a pair of indexes (P, Q) such that P < Q and A[Q] < A[P]. Write a function: int solution(vector &A); that computes the number of inversions in A, or returns −1 if it exceeds 1,000,000,000. For example, in the following array: A[0] = -1 A[1] = 6 A[2] = 3 A[3] = 4 A[4] = 7 A[5] = 4 there are four inversions: (1,2) (1,3) (1,5) (4,5) so the function should return 4. Write an efficient algorithm for the following assumptions: N is an integer within the range [0..100,000]; each element of array A is an integer within the range [−2,147,483,648..2,147,483,647]. */ int solution(const std::vector& v) { std::vector iv(v.size(),0); for (size_t i=0; i seconds = end - begin; std::cout << "Time: " << seconds.count() << std::endl; return 0; } catch ( const std::exception& e ) { std::cerr << std::endl << "std::exception(\"" << e.what() << "\")." << std::endl; return 2; } catch ( ... ) { std::cerr << std::endl << "unknown exception." << std::endl; return 1; }}