Codeforces 474f-ant colony

Source: Internet
Author: User

Note that the length of the ant that survive in each interval is equal to the GCD of the interval.

Therefore, you can pre-process The GCD in the interval first.

Then you can perform binary search.

Preprocessing gcd I use the multiplication method here

Total time complexity O (nlogn)

/* Cf 271f multiplier evaluate the complexity of the interval GCD for the subscript binary time O (nlogn) */# include # include # include # include using namespace STD; const int maxn = 100009; int st [maxn] [20]; int N, T; Map Pos; vector F [maxn]; inline int gcd (int x, int y) {return y = 0? X: gcd (Y, X % Y);} inline void ST () {for (INT I = n-1; I> 0; -- I) for (Int J = 1; I + (1 N; int Tol = 0; For (INT I = 1; I <= N; I ++) {CIN> st [I] [0]; If (POS. find (ST [I] [0]) = POS. end () tol ++, POS [st [I] [0] = tol; F [POS [st [I] [0]. push_back (I);} ST (); CIN> T; For (INT I = 1, L, R; I <= T; I ++) {CIN> L> r; int key = getgcd (L, R), k = POS [Key]; int d = upper_bound (F [K]. begin (), f [K]. end (), R)-lower_bound (F [K]. begin (), f [K]. end (), L); cout
View code

Codeforces 474f-ant colony

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.