BZOJ3673 durable array implementations can be persisted and checked (very long) by the persistence of the segment tree

Source: Internet
Author: User

Segment tree only with leaf nodes feel inexplicable waste,,,

It feels good to write (someone who just escaped from a future program)

1#include <cstdio>2 #defineMid ((l+r) >>1)3 intn,m,time,n=0, Ca,x,y;4 introot[500000],ls[4000000],rs[4000000],a[4000000];5 intChangeintXinty)6 {7     intL=1, r=n,now=++n,past=Root[time];8root[++time]=N;9      while(l!=R)Ten         if(X<=mid) rs[now]=rs[past],ls[now]=++n,r=mid,now=ls[now],past=Ls[past]; One         ElseLs[now]=ls[past],rs[now]=++n,l=mid+1, now=rs[now],past=Rs[past]; Aa[now]=y; - } - intQueintx) the { -     intL=1, r=n,now=Root[time]; -      while(l!=R) -         if(X<=mid) r=mid,now=Ls[now]; +         ElseL=mid+1, now=Rs[now]; -     returnA[now]; + } A int Get(intp) at { -      for(intT=que (P); T!=p;t=que (p)) p=T; -     returnp; - } - intMain () - { inscanf"%d%d",&n,&m); -Root[time=0]=1; to      for(intI=1; i<=n;i++) + Change (i,i); -     intstart=Time ; the      for(intI=1; i<=m;i++) *     { $scanf"%d%d",&ca,&x);Panax Notoginseng         if(ca==2) root[++time]=root[x+start]; -         Else thescanf"%d", &y), (ca==1)? Change (Get(y),Get(x)):( root[time+1]=root[time++],printf ("%d\n",Get(x) = =Get(y))); +     } A     return 0; the}

BZOJ3673 durable array implementations can be persisted and checked (very long) by the persistence of the segment tree

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.