Tag: Ring int margin type operation lis Body status amp
https://www.luogu.org/problemnew/show/P3919
Title, you need to maintain an array of length N , which supports the following types of operations
To modify a value on a location in a historical version
- To access a value from a location on a historical version
In addition, a new version is generated for each operation ( for Operation 2, which produces an identical version without any changes ). The version number is the number of the current operation (numbering starting at 1, and version 0 for the initial state array)
This problem test instructions wrong, very hurt ... Action 2 The new version is the historical version emmm it asks ...
and a variety of small errors, int did not return,y into X, and the brain pumped a k++.
Anyway, BZOJ3673 & BZOJ3674 & Valley 3402: It's easy to do this after you've been able to persist and check the set.
We open the Chairman Tree Record modification and inquiry is OK.
As if the puzzle is written here, there is no emmmm ...
#include <cstdio>#include<queue>#include<cctype>#include<cstring>#include<cmath>#include<vector>#include<algorithm>using namespacestd;Const intn=1e6+5; inlineintRead () {intx=0, w=0;CharCh=0; while(!isdigit (CH)) {w|=ch=='-'; ch=GetChar ();} while(IsDigit (CH)) X= (x<<3) + (x<<1) + (ch^ -), ch=GetChar (); returnw?-x:x;}structtree{intL,r,v;} Tr[n* -];intA[n],rt[n],n,m,pool;inlinevoidBuildint&x,intLintR) {x=++Pool; if(l==R) {TR[X].V=A[l]; return; } intMid= (l+r) >>1; Build (Tr[x].l,l,mid); Build (Tr[x].r,mid+1, R);} InlinevoidModifyintYint&x,intLintRintPosintv) {tr[x=++pool]=Tr[y]; if(l==R) {TR[X].V=v; return; } intMid= (l+r) >>1; if(Pos<=mid)returnModify (TR[Y].L,TR[X].L,L,MID,POS,V); ElseModify (tr[y].r,tr[x].r,mid+1, r,pos,v);} InlineintQueryintXintLintRintPOS) { if(L==R)returntr[x].v; intMid= (l+r) >>1; if(Pos<=mid)returnquery (Tr[x].l,l,mid,pos); Else returnQuery (tr[x].r,mid+1, R,pos);}intMain () {n=read (), m=read (); for(intI=1; i<=n;i++) a[i]=read (); Build (rt[0],1, N); for(intI=1; i<=m;i++) {Rt[i]=rt[i-1]; intK=read (), op=read (); if(op==1){ intPos=read (), v=read (); Modify (Rt[k],rt[i],1, n,pos,v); } if(op==2){ intpos=read (); printf ("%d\n", query (Rt[k],1, N,pos)); Rt[i]=Rt[k]; } } return 0;}
+++++++++++++++++++++++++++++++++++++++++++
+ This article luyouqi233. +
+ Welcome to visit my blog: http://www.cnblogs.com/luyouqi233/+
+++++++++++++++++++++++++++++++++++++++++++
Valley 3919: An array of persistence--a puzzle