POJ 2886 Segment Tree Single point update

Source: Internet
Author: User

Reprinted from: http://blog.csdn.net/sdj222555/article/details/6878651

Inverse Prime Expansion Reference: http://blog.csdn.net/ACdreamers/article/details/25049767

The main problem is a group of bear children to play games, the first team out of the people are numbered K. The person who was out of the squad was followed by a number in the previous hand. If it is a positive number, +m is the person on the left. If it is negative-m, it is the person's right-hand person. As the man is out of the team. To the next person has influence, so +m time, is k+m-1. -M is k+m. Because it was the man behind him, so there was no effect. Because of the possibility of negative numbers and 0, there is the following processing when modulo. Each node of the segment tree holds the number of positions in this interval. So every time the update, if left child node empty enough, search left child, otherwise search right child. Can build a reference to the sample simulation.

Still do not know how to hit the Counter-prime list. So it's Cooy.

Attached code:

1#include <stdio.h>2#include <string.h>3#include <iostream>4 using namespacestd;5 6 #defineLson L, M, rt<<17 #defineRson m+1, R, rt<<1|18 #defineN 5000109 Ten inttree[n<<2]; One  A Const intAntiprime[] = {//Counter-Prime table -     1,2,4,6, A, -, $, -, -, -, the, -, the,720,840, -     1260,1680,2520,5040,7560,10080,15120,20160,25200, the     27720,45360,50400,55440,83160,110880,166320,221760, -     277200,332640,498960,554400,665280 - }; -  + Const intFactornum[] = {//approximate number of corresponding -     1,2,3,4,6,8,9,Ten, A, -, -, -, -, -, +, $, +, -, -, +      -, the, the, -, -, the, -,108, -, -,144, the,168, the, A     192, $,216,224 at }; -  - structchild{//node information when you save the input -     Charname[ the]; -     intVal; - }c[n]; in  - voidBuild (intLintRintRT) {//Achievements toTREE[RT] = r-l+1; +    if(L = =R) -    return; the    intm = (l+r) >>1; * Build (Lson); $ Build (Rson);Panax Notoginseng } -  the intUpdate (intPintLintRintRT) {//p individuals go out. The update function can be understood.  +tree[rt]--; A     if(L = =R) the     returnR; +     intm = (l+r) >>1; -     if(p<=tree[rt<<1]) $     returnUpdate (P, Lson); $     Else returnUpdate (p-tree[rt<<1], Rson); - } -  the intMain () { -    intI, N, &mod = tree[1];Wuyi    //The MoD saved is how many individuals, the    intK; -  Wu     while(~SCANF ("%d%d", &n, &k)) { -      //Input Achievements About       for(i=1; i<=n; ++i) { $scanf"%s%d", C[i].name, &c[i].val); -      } -Build (1N1); -  A      //The maximum number of inverse primes that are less than or equal to N.  +      intCNT =0; the       while(CNT < *&& antiprime[cnt] <=N) { -cnt++; $      } thecnt--; the      //find the maximum number of constraints in the 1-n range first.  the  the      //POS is the ID of the person who is recording the current position of the team -      intpos =0; inC[pos].val =0; the  the      //Find antiprime[cnt] The name of the person who is out of the team, About       for(i=0; i<antiprime[cnt]; ++i) {//the number of cycles is until the person is out of the team.  the  the         //These two if are based on the number of hand cards to calculate the next out of the queue of the person's current position, the         if(C[pos].val >0) +K = ((k+c[pos].val-2)%mod+mod)%mod+1; -         ElseK= ((k+c[pos].val-1)%mod+mod)%mod+1; the Bayi        //POS records the location of the person who is currently looping out of the queue, thepos = Update (k,1N1); thecout << POS <<"====\n"; -      } -printf"%s%d\n", C[pos].name, factornum[cnt]); the    } the    return 0; the}
View Code

POJ 2886 Segment Tree Single point update

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.