Description
There are n positions, m operations. There are two types of operations, each of which is a 1 a B C in the form of a position in the first place to the B position, and each position is joined by a number C
In the case of a 2 a B C, it is asked to ask from position A to position B, and the number of C large.
Input
First line N,m
Next m line, each line shaped like 1 a b C or 2 a B C
Output
Output the results of each query
Sample Input
2 5
1 1 2 1
1 1 2 2
2 1 1 2
2 1 1 1
2 1 2 3
Sample Output
1
2
1
HINT
"Sample description"
The number of positions 1 after the first operation is only 1, and the number of positions 2 is only 1. Second post-operation position 1
The number is 1, 2, the number of positions 2 also has 1, 2. The third query position 1 to position 1 The 2nd largest number is
1. The fourth time asked position 1 to position 1 The 1th largest number is 2. Fifth time ask position 1 to position 2 Section 3
The big number is 1.?
N,m ≤ 50000
A ≤ B ≤ N
1 Operation ABS (c) N
2 operating ABS (c) ≤ maxlongint
Naked question.
Tree Set tree/Chairman Tree/whole two points
It's better than 233 to practice the whole dichotomy.
//ac Code by Creationaugust#include <iostream>#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#define MAXN 50010#define MAXINT 0x7fffffff#define Lchild Rt<<1,l,mid#define Rchild Rt<<1|1,mid+1,r#define LN rt<<1#define RN Rt<<1|1using namespace STD;intOp,a,b,c;intN,m;structquery{intXintOp,a,b,c;intFin//Whether the operation has been resolved BOOL operator< (Constquery& a)Const{if(Fin!=a.fin)returnfin<a.fin;returnx<a.x; }}QUES[MAXN];//Inquiry sequenceintANS[MAXN];//answer sequence, if the corresponding inquiry is inserted, ans is-maxintstructseg{intL,r;intMem//Clear Mark intFlag//Operation Mark intAdd//dosing Mark intsum;} tree[maxn<<4];BOOLComp (query A,query b) {if(A.fin<b.fin)return 1;if(A.fin==b.fin) a.x<b.x;return 0;}voidBuildintrt=1,intL=1,intR=n) {intMid= (l+r) >>1; Tree[rt].l=l;tree[rt].r=r;if(L==R)return; Build (Lchild); build (rchild);}voidPUSH_UP (intRT) {Tree[rt].sum=tree[ln].sum+tree[rn].sum;}voidPush_down (intRT) {if(TREE[RT].MEM) {tree[ln].add=tree[rn].add=tree[ln].sum=tree[rn].sum=0; tree[ln].mem=tree[rn].mem=1; tree[rt].mem=0; }if(Tree[rt].add) {tree[ln].add+=tree[rt].add;tree[rn].add+=tree[rt].add; tree[ln].sum+= (tree[ln].r-tree[ln].l+1) *tree[rt].add; tree[rn].sum+= (tree[rn].r-tree[rn].l+1) *tree[rt].add; Tree[rt].add=0; }}voidModifyintRtintLintR) {Push_down (RT);intL=TREE[RT].L,R=TREE[RT].R;if(L==L&&R==R) {tree[rt].add++; tree[rt].sum+= (r-l+1);return; }intMid= (l+r) >>1;if(r<=mid) modify (LN,L,R);Else if(l>mid) modify (RN,L,R);ElseModify (Ln,l,mid), modify (rn,mid+1, R); PUSH_UP (RT);}intQueryintRtintLintR) {Push_down (RT);intL=TREE[RT].L,R=TREE[RT].R;if(L==L&&R==R)returnTree[rt].sum;intMid= (l+r) >>1;if(R<=mid)returnQuery (LN,L,R);Else if(L>mid)returnQuery (RN,L,R);Else returnQuery (Ln,l,mid) +query (rn,mid+1, r);}voidSolveintLintRintLintR//l,r is the data sequence, L,r is the inquiry sequence{if(L>r)return;if(L==R)//Answer get{ for(inti=l;i<=r;i++)if(ques[i].op==2) Ans[ques[i].x]=l;return; } tree[1].add=tree[1].sum=0; tree[1].mem=1;intmid=l-1;//used to determine the endpoint of the next division of the Ask interval intMid= (l+r) >>1; for(inti=l;i<=r;i++) {if(ques[i].op==1) {if(Ques[i].c>mid) Modify (1, ques[i].a,ques[i].b), ques[i].fin=1;Elseques[i].fin=0, mid++; }Else{intTemp=query (1, ques[i].a,ques[i].b);if(ques[i].c<=temp) ques[i].fin=1;Elseques[i].fin=0, Mid++,ques[i].c-=temp; }} sort (ques+l,ques+r+1); Solve (L,mid,l,mid); Solve (mid+1, r,mid+1, r);}intMain () {scanf("%d%d", &n,&m); Build (); for(intI=1; i<=maxn;i++) Ans[i]=-maxint; for(intI=1; i<=m;i++) {scanf("%d%d%d%d", &op,&a,&b,&c); Ques[i].x=i;ques[i].op=op;ques[i].a=a;ques[i].b=b;ques[i].c=c; } Solve (0N1, m); for(intI=1; i<=m;i++)if(Ans[i]!=-maxint)printf("%d\n", Ans[i]);}
"ZJOI2013" "BZOJ3110" K large number query