"Bzoj" 3673: Can be persisted and checked by Zky & 3674: Can be persisted and checked with the enhanced version (can persist line tree)

Source: Internet
Author: User

http://www.lydsy.com/JudgeOnline/problem.php?id=3674

http://www.lydsy.com/JudgeOnline/problem.php?id=3673

Double experience La La La.

To the chairman of the tree changed a name really tall on ...

The first thing to do is to persist and check the set is actually a persistent array ...

So since the form of the array is such a $p[x]$, then we use a data structure to find X to return to the corresponding $p[x]$.

And then I learned to be sustainable now only the chairman of the tree Qaq one day to write fhqtreap ...

So use the Chairman tree to find the subscript x and then maintain the father in the leaves.

And then it's done.

#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream > #include <algorithm> #include <queue> #include <set> #include <map> #include <ext/rope >using namespace Std;typedef long long ll; #define REP (i, n) for (int i=0; i< (n); ++i) #define FOR1 (i,a,n) for (int i= (a ); i<= (n); ++i) #define FOR2 (i,a,n) for (int i= (a);i< (n), ++i) #define FOR3 (i,a,n) for (int i= (a); i>= (n);-i) # Define FOR4 (I,a,n) for (int i= (a);i> (n); i) #define CC (i,a) memset (i,a,sizeof (i)) #define READ (a) a=getint () #define Print (a) printf ("%d", a) #define DBG (x) cout << (#x) << "=" << (x) << endl#define error (x) (!) ( x) puts ("error"): 0) #define RDM (x, i) for (int i=ihead[x]; i; i=e[i].next) inline const int Getint () {int r=0, k=1; Char c=g Etchar (); for (; c< ' 0 ' | | C> ' 9 '; C=getchar ()) if (c== '-') k=-1; for (; c>= ' 0 ' &&c<= ' 9 '; C=getchar ()) r=r*10+c-' 0 '; return k*r; }const int n=2*1e5+10;struct Node {int L, R, F; }t[n*100];int CNT, Root[n], n;void update (int l, int r, int &x, int pos, int f) {t[++cnt]=t[x]; X=cnt;if (l==r) {t[x]. F=f; Return }int mid= (l+r) >>1;if (pos<=mid) Update (L, Mid, T[X].L, POS, f); Else update (mid+1, R, T[X].R, POS, f);} int ask (int l, int r, int x, int pos) {if (l==r) return t[x].f;int mid= (l+r) >>1;if (Pos<=mid) return Ask (L, Mid, t[ X].L, POS), else return Ask (Mid+1, R, T[X].R, POS);} int P (int x, int y) {return ask (1, n, x, y);} int un (int &x, int a, int b) {update (1, n, X, A, b); return b;}//Union P (a) =yint find (int &x, int y) {int f=p (x, y); return F==y?y:un (x, Y, find (x, f)); }int Main () {read (n); int m=getint (), La=0;for1 (i, 1, N) update (1, N, root[0], I, I); For1 (i, 1, m) {int c=getint (); Root[i] =root[i-1];if (c==1) {int x=getint (), Y=getint (); x^=la; Y^=la;int Fx=find (Root[i], x), Fy=find (Root[i], y); if (fx!=fy) UN (Root[i], FX, FY);} else if (c==2) Root[i]=root[getint () ^la];else {int x=getint (), Y=getint (); x^=la; Y^=la;int Fx=find (ROot[i], X), Fy=find (Root[i], y);p rintf ("%d\n", La= (Fx==fy));}} return 0;}

  

Description

Description:
Since the ZKYSB has been made durable and has been checked ...
Hzwer: Write can AC, violence stamped on the standard range
KURIBOHG: I do not path compression is over!
NDSF: Violence can be easily abused!
Zky: ...

n Sets of M operations
Operation:
1 A B merges the set of A and a
2 k back to status after K-operation (query counts as action)
3 A B asks if a, a, or not belongs to the same set, is output 1 otherwise output 0
Please note that the subject is forced online, the given a,b,k are encrypted, the encryption method is X = x XOR Lastans,lastans initial value is 0
0<n,m<=2*10^5


Input Output Sample INPUT5 6
1 1 2
3 1 2
2 1
3 0 3
2 1
3 1 2
Sample OUTPUT1
0
1
HINT Source

The sb++ of the NPC

"Bzoj" 3673: Can be persisted and checked by Zky & 3674: Can be persisted and checked with the enhanced version (can persist line 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.