Test Instructions:Link
Method:The line tree can be persisted.
parsing:Persistent data structure Good God, it feels so mysterious. The purpose of the first achievement is to establish a tree of weights, maintaining the number of certain weights in the l,r. Then, for 1~n each node builds a tree, and is based on the previous tree. Then for each new value we only need to update once, and connect the original tree? God Ben not to say that this structure is a bunch of line-up trees and even came out. What about the time of the query? There are some minor changes that are said to be based on two basic queries. When God Ben invented this data structure, it was discovered that all line segments in this data structure can be subtracted from this nature, so we can split the answer on the left or the right, recursion to go down the final L is the target value. Does it take time to feel like a real understanding? I think I'm just going to get a sense of it.
Code:
#include <cstdio>#include <cstring>#include <iostream>#include <algorithm>#define N 500010using namespace STD;structnode{intLson,rson,sum;} seg[n* -];intSizeintRoot[n];voidUpdateintPint&q,intLintRintV) {seg[++size]=seg[p],q=size; seg[q].sum++;if(L==R)return;intMid= (l+r) >>1;if(v<=mid) update (SEG[P].LSON,SEG[Q].LSON,L,MID,V);ElseUpdate (seg[p].rson,seg[q].rson,mid+1, r,v);}intQueintLintRintLintRintK) {if(L==R)returnLintMid= (l+r) >>1;if(seg[seg[r].lson].sum-seg[seg[l].lson].sum>k) {returnQue (seg[l].lson,seg[r].lson,l,mid,k); }if(seg[seg[r].rson].sum-seg[seg[l].rson].sum>k) {returnQue (seg[l].rson,seg[r].rson,mid+1, r,k); }return 0;}intN,m;intMain () {scanf("%d%d", &n,&m); for(intI=1; i<=n;i++) {intXscanf("%d", &x); Update (root[i-1],root[i],1, n,x); } for(intI=1; i<=m;i++) {intL,r;scanf("%d%d", &l,&r);printf("%d\n", Que (root[l-1],root[r],1, N, (r-l+1) >>1)); }}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Bzoj 3524 [poi2014]couriers can persist line tree