# POJ (line tree) who Gets the most candies?

Source: Internet
Author: User

This problem is very strong, but also involved in number theory, but also a line tree.

The line tree maintains information about how many people in the interval did not jump out, and then calculates that the next person is the first of the remainder.

I am in this tune program for a long time, is that mold to die to make me dizzy.

But the question is really a good question, to praise.

`1#include <cstdio>2#include <iostream>3#include <cmath>4#include <string>5#include <algorithm>6#include <vector>7 using namespacestd;8 9 Const intMAXN =500000+Ten;Ten intN, K; One intSUM[MAXN <<2]; A  - voidBuildintOintLintR) - { the     if(L = = R) {Sum[o] =1;return; } -     intM = (L + R)/2; -Build (o*2, L, M); -Build (o*2+1, m+1, R); +Sum[o] = sum[o*2] + sum[o*2+1]; - } +  A intUpdateintOintLintRintp) at { -     if(L = = R) {Sum[o] =0;returnL;} -     intM = (L + R)/2; -     intans; -     if(sum[o*2] >= p) ans = update (o*2, L, M, p); -     ElseAns = Update (o*2+1, m+1, R, p-sum[o*2]); inSum[o] = sum[o*2] + sum[o*2+1]; -     returnans; to } +  - Const intMAXP = -; the intPRIME[MAXP], pcnt =0; * BOOLVIS[MAXP]; \$ Panax Notoginseng voidprime_table () - { the     intm =sqrt (MAXP); +      for(inti =2; I <= m; i++)if(!Vis[i]) A          for(intj = i * I; J < Maxp; J + = i) vis[j] =true; the      for(inti =2; i < MAXP; i++)if(!vis[i]) prime[pcnt++] =i; + } -  \$ intFintN) \$ { -     intAns =1; -      for(inti =0; I < pcnt && n >1; i++)if(n% prime[i] = =0) the     { -         intc =0;Wuyi          while(n% prime[i] = =0) {n/= prime[i]; C + +; } theAns *= C +1; -     } Wu     if(N >1) Ans <<=1; -     returnans; About } \$  - intNEXT[MAXN]; - Charstu[maxn][ One]; -  A intMain () + { the     //freopen ("In.txt", "R", stdin); -  \$ prime_table (); the  the      while(SCANF ("%d%d", &n, &k) = =2) the     { theBuild1,0N1); -         int_max =0, id; in          for(inti =0; I < n; i++) {scanf ("%s%d", Stu[i], &Next[i]); } the  the         intpos = k-1; About          for(inti =1; I <= N; i++) the         { the             intt = Update (1,0N1, POS +1); the             intf =F (i); +             if(F >_max) -             { the_max =F;BayiID =T; the             } the             if(i = = N) Break; -             intMOD = N-i; -             if(Next[t] <0) next[t]++;//negative situation also have a little change, in this pit for a long time thepos = ((pos + next[t]-1)% (MoD) + MoD)%MOD; the         } theprintf"%s%d\n", Stu[id], _max); the     } -  the     return 0; the}`
code June

POJ (line tree) who Gets the most candies?

Related Keywords:

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.