SPOJ 4491-moTest instructionsGiven a, B, the number of gcd (x, y) =prime, wherein: 1 Limit:1 Ideas:Consider the problem first, then the problem becomes the number of gcd (x, y) =k.Set F (k) to the number of gcd (x, y) =k,Set F (k) to GCD (x, y) as a multiple of K, obviously F (k) =floor (a/k) *floor (b/k).The Möbius was reversed by:F (k) =mu[1]*f[k]+mu[2]*f[2*k]+ ...So:Ans=f (Prime[1]) +f (prime[2]) + ... 1----After the "1-type" expansion, it was found that for each f (k), and it multiplied by t
Topic: Given a tree, each point has a non-negative point, support the following operations1. Modify the point right of a point2. Query the MEX on a chainConsider the link without the modified version, we can use MO Team + sub-block to engage (link stamp here)Now to the tree with modified, decisive Candy ParkWould have been holding a tease than the mentality of writing a result 1.4s overIt's not exactly proportional to the 80s in the Candy Park. 0.0#in
The functions of Echo and print in PHP are basically the same, but there are subtle differences between the two. In PHP code, print can be used as a normal function, for example, after executing the following code, the value of the variable $res will be 1.
$ret = print \ "Hello world\";
This means that print can be used in some complex expressions, while Echo is not. Similarly, the Echo statement runs slightly faster than the print statement in the code, because the Echo statement does not requ
Test instructions The use sequence of the card given by the M card is required to be drawn from the top of the Kari each time to match the sequencing output of the initial card heap and then output each time the card is inserted back into the card heap, there are several cards on the cardThe initial sort is easy to get out of the way, but it's important to note that if I have three cards and I only use the first one in the output card heap, I still need to output 2 and 3.It can be thought that s
single of these pairs are suitable for the second query. In the second, the sample XOR equals 1 for any subarrays of an odd length.Test instructions: Find out how many pairs of xor and the logarithm of k are in the interval;Idea: Mo team algorithm, mainly how O (1) update, a[l]^a[l+1].....^a[r]=pre[r]^pre[l-1]=k;pre[i] means a[1]^a[2]^....^a[i];Pos[r]^pre[l-1]=k; pre[r]=pre[l-1]^k; update the pre;#include using namespacestd;#definell Long Lo
any subarrays of an odd length.Test instructions Give you a sequence of length nM inquiries, every time you ask how many pairs of l,r between the sub-range are equal to KExercisesGodless, a team of Mo.#include using namespacestd;Const intN = 1e6+Ten, M = 5e6+Ten, INF = 1e9+7, mod = 1e9+7;intH[m];intSum[n],n,m,k,a[n],pos[n];Long LongAn[n],ans;structss{intL,r,id;} Q[n];intCMP (ss S1,ss S2) {if(POS[S1.L]==POS[S2.L])returns1.rElse returns1.lS2.L;}intCmp
The magic of the MO team algorithm, to solve the problem can be offline without modification of the interval query:
First, the original sequence is divided into blocks, √n block each block √n;
Then the interval [l,r] of all queries is sorted, first by the block ordinal in which L is in ascending order, if the same as in ascending order by R;
Finally, in order to find out the results of each query: Know [L,r] answer, and on this basis
The key to solving the Problem: MO team most important is the interval between the $o (1) $ complexity of the conversion, due to computer reasons, follow-up formula Deduction.1#include 2#include 3#include 4#include 5#include 6#include 7 using namespacestd;8typedefLong Longll;9 ll n,m,ans;Ten structnode{ one ll l,r,id; a}b[50002]; - structnd{ - ll a, b; the} as[50002]; -ll a[50002],pos[50002],s[50002]; - - BOOLCMP1 (ConstNode a,ConstNode B) { + re
are n,m≤5000;60% of the data are n,m≤25000;100% of the data in n,m≤50000,1≤l HINT SourceCopyright Owner: Mo TaoMo Team algorithm, to kneel;#include using namespacestd;#definell Long Long#definePi (4*atan (1.0))Const intn=1e5+Ten, m=1e6+Ten, inf=1e9+Ten;Constll inf=1e18+Ten;intsi[n];struct is{ intl,r,pos; BOOL operatorConst isa)Const { if(si[l]==Si[a.l])returnra.r; returnsi[l]si[a.l]; }}a[n];intn,m,co[n],k;intl,r;ll ans,flag[n];structAn
Y (or root and an apple). Next there are m lines, each line containing four integers u, V, A and B, which means that the person wants to count the number of Apple U to Apple V, and this person thinks color A is color B. If a=b=0, it means that the person does not suffer from color blindness. OutputThe output is a total of M lines, each line contains only one integer, representing the number of colors the person should count.Sample INPUT5 31 1 3) 3 20 11 21 32 43 51 4 0 01 4 1 31 4 1 2Sample Out
, fm/g); } } return 0;}This section of code space is too large to be AC, but very useful, and universal. If you do not want to see a direct look at the next article, more important and effective.This problem is not already used online algorithm a over, how to again?Don't forget! The range additive was used before!This time the algorithm does not use the interval to be additive, also does not have the interval to reduce the sex, how does it do?From one endpoint to the interval of each point
Test instructions: Chinese question.Analysis: The very famous MO team algorithm, the first expression of this probability, should be the molecule: C (x1, 2) + C (x2, 2) + C (X3, 2) + ... + c (xn, 2) Denominator: C (n, 2), and then the expression of fractions, [X1 (x1-1) +x2 (x2-1) +...+XN (xn-1)]/(n (n-1)) then the simplification is obtained (Sigma (XI*XI)-N)/(n (n-1)), then the operation of each interval, offline, so that the sequence is divided into
Title Link hh NecklaceThis problem can be directly on the chairman of the tree template#include Of course, you can do it with the MO team algorithm.#include Bzoj 1878 [Sdoi2009]hh's Necklace (Chairman tree or MO team algorithm)
Facet links/*code correctness is not guaranteed. in the DFS sequence do mo teamwhen a point is not another point of the LCA, it is necessary to add their LCA contribution*/#include #include #include #include #define GC () GetChar ()Const intn=4e5+5, m=1e5+5;intn,m,size,enum,h[n],nxt[n1],to[n1],dep[n],fa[n],top[n],son[n],sz[n];intnow,ans[m],seq[n1],in[n],out[n],id,a[n],tm[n];BOOLVis[n];structques{intL,r,lca,id,x,y;BOOL operatorConstQues a)Const{returnl
Topic Link Tree and QueriesThe title gives the color of a tree and each node. Every time you ask VJ, KJYou need to answer the number of colors that meet the conditions in a subtree rooted in VJ,Condition: The number of nodes with this color is at least KJ.(Mo team can actually live)Turn the DFS sequence first, and this becomes the interval query.Then apply the team directly, find the t[],t[k in each query state] to indicate the number of colors that h
)) \\=\sum\limits_{x} (s_x (1,r_1) · S_x (1,r_2)-s_x (1,l_1-1) · S_x (1,r_2)--s_x (1,r_1) · S_x (1,l_2-1) +s_x (1,l_1-1) · S_x (1,l_2-1)) \\=q (r_1,r_2)-Q (l_1-1,r_2)-Q (r_1,l_2-1) +q (l_1-1,l_2-1) $which$Q (A, B) =\sum\limits_{x}s_x (1,a) · S_x (1,B) $You can then split each query into 4, using the MO team algorithm to calculate the contribution to each answer separately.Note that when one of the $a$ or $b$ is 0 o'clock, it needs to be filtered out,
HDU-6333Test instructions: There are n different apples, you can use up to M, ask how many kinds of ways, multiple sets of data, groups and n,m are 1e5, so the table can not play.Idea: This problem to use the combination of the properties of the number of S (n,m) from N to the maximum number of M-method total, is obviously C (n,0), C (n,1) ... C (N,m) and.Obviously s (n,m+1) = S (n, m) + C (n,m+1);Another equation is less obvious, s (n+1,m) = 2 * S (n,m)-C (N,M);I also understand under the guida
DescribeGiven a sequence of n (n≤50000), M (m≤50000) asks for the minimum number of times the sequence does not fall by the adjacent element 22 interchange in the [L, R] interval.Analysis
The first conversion to a reverse order of the problem, the minimum number of exchanges is the number of reverse pairs. The latter proves to be not rigorous or even wrong, but it can be used as an inspiration and reference: for an element x in a sequence, there is a C for the element that is smaller than it
Mo Team Classics. The number of times the number of open arrays maintained a[i] occurred.1#include 2#include 3#include 4 using namespacestd;5 intnum,ch[ A],f,c;6InlinevoidRintx) {7C=0; f=1;8 for(;c'0'|| C>'9'; C=getchar ())if(c=='-') f=-1;9 for(x=0; c>='0'c'9'; C=getchar ()) (x*=Ten) + = (c'0');Tenx*=F; One } AInlinevoidPintx) { - if(xTen) Putchar (x+'0'); - Else{P (x/Ten);p Utchar (xTen+'0');} the } - intans,anss[50001]; - intn,m,k,
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.