Uvalive 7325Book Borders

Source: Internet
Author: User

Title Link: Https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&page=show_problem &problem=5347

-------------------------------------------------------------------------------------------------------------

We can preprocess the number of words from the first word that can be stored in intervals of length L.

Then the enumeration interval length jumps from a to B each time from the end of the last word in one interval to the end of the last word in the other interval.

So the total length of the adjacent two hops is at least one interval length

Set the word length to $len$ the total number of hops for the interval length of $x$ is not super $len \/\ x * 2$

So the complexity of the whole problem is based on harmonic progression analysis found to be $O (Lenlog{len}) $

1#include <cstdio>2#include <cstring>3#include <cmath>4#include <algorithm>5 using namespacestd;6 Const intN =500010;7 intA[n], pre[n], sum[n];8 CharS[n];9 intLen, N;Ten intMain () One { A      while(Gets (s)! =NULL) -     { -n =0; theLen = strlen (s) +1; -          for(inti =0; i < Len; ++i) -         { -             if(S[i] <'a'|| S[i] >'Z') +             { -++N; +A[n] = i +1-Sum[n-1]; ASum[n] = sum[n-1] +A[n]; at             } -Pre[i +1] =N; -         } -         intL, R, ans, now; -scanf"%d%d", &l, &R); - GetChar (); in++L; -++R; to          for(inti = L; I <= R; ++i) +         { -Ans =-1; thenow =0; *              while(Now! =len) $             {Panax NotoginsengAns + = A[pre[now] +1]; -now = Sum[pre[min (now +I, Len)]; the             } +printf"%d\n", ans); A         } the     } +     return 0; -}

Uvalive 7325Book Borders

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.