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