"BZOJ-3337" Orzjry I block List

Source: Internet
Author: User

3337:orzjry I time limit:30 Sec Memory limit:512 MB
submit:190 solved:50
[Submit] [Status] [Discuss] Description

Jry recently done (slaughtered) a lot of data structure problems, so want BS you, he wants you to implement a data structure to maintain a sequence:

Input

First row N;
The second row n number;
The third line q, represents the number of inquiries;
Next Q Line, one op per line, input format see description.

Output

For the 7≤op≤11 operation, one line outputs an answer.

Sample Input6
5 2 6 3 1 4
15
7 2 4
8 1 3
9 2 4 5
10 1 6 4
11 2 5 4
6 1 4 7
8 1 4
5 3 4 5
2 1
1 2 8
3 3 5
4 1 5 2
9 2 5 4
10 3 6 4
11 1 6 100
Sample Output11
4
1
4
3
0
3
12
6HINT

n,q≤100000;
Number ≤2^31-1 at any time in a sequence.
0≤ the number ≤2^31-1 in the sequence of arbitrary moments.

A total of 3 sets of dataSource

by Orzjry

Solution

Switch (OPT)
{
Case 1: Insertion can break after direct split;
Case 2: Split immediately after splitting;
Case 3: Split gets [L,r] points the block pointing to L to point to the block that R,l points to R, then reverses the mark break for all blocks in [l,r];
Case 4: Extract [R-k,r], remove the paragraph from it, and then insert the whole paragraph into the l before break;
Case 5: Extract [L,r], hit tag tag break;
Case 6: Extract [L,r], hit del Mark break;
Case 7: Extract [L,r], scan all blocks in the interval, statistic sum break;
Case 8: Ibid., Statistics max and min, output max-min break;
  Case 9: think of or need two points, but there is no particularly exquisite idea of break;
Case 10: Extra records for each block a sorted sequence, and then find K small break;
Case 11: Extra processing of an ordered sequence of columns for each block, and then the number of two statistics break;
}

Most of these two points can be used in the STL substitution, note that split and merge time to Pushdown and update

Code
#include <iostream>#include<cstdio>#include<algorithm>#include<cmath>#include<cstring>using namespacestd;intRead () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9') {if(ch=='-') f=-1; Ch=GetChar ();}  while(ch>='0'&& ch<='9') {x=x*Ten+ch-'0'; Ch=GetChar ();} returnx*F;}namespaceblocklists{#defineBNstructblnode{intNext from, Data[],tmp[],size;intMaxx,minn,tag,sum;BOOLRev;}    B[BN]; Queue<int>Trash; InlineintNew () {if(Trash.empty ())return++sz;intTmp=trash.front (); Trash.pop ();returntmp;} InlinevoidDel (intx) {Trash.push (x); b[x].next=-1; b[x].size=b[x].maxx=b[x].minn=b[x].sum=b[x].tag=b[x].rev=0;} InlineintGETP (intRK) { for(intI=start; ~i; I=b[i].next)if(rk>b[i].size) Rk-=b[i].size;Else returni;} InlineintGETK (intRK) { for(intI=start; ~i; I=b[i].next)if(rk>b[i].size) Rk-=b[i].size;Else returnRK;} InlinevoidData (intPosintLenintData[],intSUF) {B[pos].next=suf; B[pos].size=Len; memcpy (B[pos].data,data,len);} InlinevoidPushdown (intx) {intsz=b[x].size; if(B[x].del) {intDel=b[x].del; B[x].del=0; for(intI=0; i<sz; i++) B[x].data[i]=del; B[x].sum=sz*del; b[x].maxx=b[x].minn=del;} if(B[x].rev) {Reverse (b[x].data,b[x].data+sz);} if(B[x].tag) {intTag=b[x].tag; b[x].tag=0; for(intI=0; i<sz; i++) B[x].data[i]+=tag; B[x].sum+=sz*tag; B[x].maxx+=tag; b[x].minn+=tag;} } InlinevoidUpdate (intx) {intSz=b[x].size; b[x].sum=0;  for(intI=0; i<sz; i++) b[x].sum+=B[x].data[i];        memcpy (B[X].TMP,B[X].DATA,SZ); Sort (b[x].tmp,b[x].tmp+sz); } InlinevoidSplit (intPosintRK)        {pushdown (POS); if(B[POS]==RK)return; intId=new (); Data (Id,b[pos].size-rk,b[pos].data+rk,b[pos].next); B[pos].next=id; B[pos].size=RK; Update (ID);    Update (POS); } InlinevoidMerge (intPOS) {         for(; ~pos; pos=b[pos].next) for(intSuf=b[pos].next; ~suf && b[pos].size+b[suf].size<bsize; suf=B[suf].next) Pushdown (POS), Pushdown (Suf), memcpy (B[pos].data+b[pos].size,b[suf].data,b[suf].size), b[pos].next=b[suf].next,b[pos].size+=b[suf].size, Del (Suf), Update (POS); } InlinevoidInsert (ints) {intNOW=GETP (s), pos=GETK (s);        Split (Now,pos); intId=new (); Data (ID,1, A +1, B[now].next); b[now].next=ID;    Merge (now); } InlinevoidDelete (ints) {intNOW=GETP (s), pos=GETK (s);        Split (Now,pos);        Del (B[pos].next);    Merge (now); } InlinevoidPrework (intLintRint&x,int&y) {intNOW1=GETP (l), pos1=GETK (L);        Split (NOW1,POS1); intNOW2=GETP (R), pos2=GETK (R);        Split (NOW2,POS2); X=pos1,y=Pos2; } Inlinevoidrever () {} inlinevoidChange () inlinevoidMove () inlinevoidAdd () inlinevoidModify () inlinevoidgetsum () inlinevoidGetRange () inlinevoidgetclose () inlinevoidgetkth () inlinevoidgetsmall ()}using namespaceblocklists;intMain () {intn=read ();  for(intI=1; i<=n; i++) a[0]=read (), Insert (i-1); Bsize=ceil (sqrt (N)); Q=read ();  while(q--)        {            intOpt=read ();intX,y,k,val; Switch(opt) { Case 1: X=read ()-1, Val=read (), change (X,val); Break;  Case 2: X=read ()-1; Delete (x); Break;  Case 3: X=read ()-1, Y=read ()-1; Rever (x, y); Break;  Case 4: X=read ()-1, Y=read ()-1, K=read (); Move (x, y); Break;  Case 5: X=read ()-1, Y=read ()-1; Val=read (); ADD (X,y,val); Break;  Case 6: X=read ()-1, Y=read ()-1; Val=read (); Modify (X,y,val); Break;  Case 7: X=read ()-1, Y=read ()-1; Getsum (x, y); Break;  Case 8: X=read ()-1, Y=read ()-1; GetRange (x, y); Break;  Case 9: X=read ()-1, Y=read ()-1; Getclose (x, y); Break;  Case Ten: X=read ()-1, Y=read ()-1, K=read (); Getkth (X,Y,K); Break;  Case  One: X=read ()-1, Y=read ()-1, Val=read (); Getsmall (X,y,val); Break; }        }    return 0;}
It's not done yet .

"BZOJ-3337" Orzjry I block List

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.