[Persistent array] [Rope] bzoj3673 bzoj3674 persistent and query set by zky

Source: Internet
Author: User

Rope Tutorial: http://blog.csdn.net/iamzky/article/details/38348653

Code (bzoj3673 ):

1 # include <cstdio> 2 # include <EXT/rope> 3 using namespace STD; 4 using namespace _ gnu_cxx; 5 rope <int> * Fa [20001]; 6 int A, B, n, m, a [20001], OP; 7 int root (INT num, int X) 8 {9 If (Fa [num]-> at (x) = x) 10 return X; 11 int RT = root (Num, fa [num]-> at (x); 12 // If (RT = Fa [num]-> at (x) without adding the two rows, bzoj3674 will blow up the memory. 13 14 // return RT; 15 Fa [num]-> Replace (x, RT); 16 return RT; 17} 18 void Union (INT num, int X, int y) 19 {20 int u = root (Num, x), V = root (Num, Y); 21 Fa [num]-> Replace (v, U ); 22} 23 int main () 24 {25 scanf ("% d", & N, & M); 26 for (INT I = 1; I <= N; I ++) 27 A [I] = I; 28 Fa [0] = new rope <int> (A, A + n + 1 ); 29 for (INT I = 1; I <= m; I ++) 30 {31 Fa [I] = new rope <int> (* Fa [I-1]); 32 scanf ("% d", & OP); 33 If (OP = 1) {scanf ("% d", & A, & B ); union (I, a, B);} 34 else if (OP = 2) {scanf ("% d", & ); fa [I] = Fa [a];} 35 else {scanf ("% d", & A, & B); printf ("% d \ n ", root (I, A) = root (I, B);} 36} 37 return 0; 38}

 

[Persistent array] [Rope] bzoj3673 bzoj3674 persistent and query set by zky

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.