WZJ data structure (minus 33) |
Difficulty level: E; operating time limit: 7000ms; operating space limit: 262144KB; code length limit: 2000000B |
Question Description |
Please design a data structure to complete the following functions: Given an integer group A of size n, you are asked to perform n operations. There are two types of operations: Operation 1: Each operation gives you l,r,v three parameters, to find the number of Al to Ar value <=v. Action 2: Each operation gives you l,r,v three parameters, the value of all the AL to AR values is set to V. |
Input |
The first behavior is a positive integer n. The second behavior is n integers of AI. The next n rows are 4 positive integers per line t,l,r,v. If t=2 indicates operation 1,t=1 represents action 2. |
Output |
1 output results for each operation. |
Input example |
6 1 2 2 1 2 3 2 1 4 2 2 1 4 1 1 2 4 1 2 1 4 1 1 3 5 2 2 2 5 2 |
Output example |
4 2 4 4
|
Other Notes |
1<=n<=200000 1<=ai,v<=10^9 |
Puzzle: The standard course is definitely what line of the tree division of what strange Things, Wo will not write Ah,,, just write the sub-block it, so the abuse of the standard process Oh, excited!
1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <queue>6#include <cstring>7 #definePAU Putchar (")8 #defineENT Putchar (' \ n ')9 using namespacestd;Ten Const intmaxn=200000+Ten, maxb= -, inf=-1u>>1; One intZ[MAXN],ST[MAXB],EN[MAXB],SIZE,N,A[MAXN],B[MAXN],Set[MAXB],SIZ[MAXB]; AInlineintRead () { - intx=0, sig=1;CharCh=GetChar (); - for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') sig=0; the for(; isdigit (ch); Ch=getchar ()) x=Ten*x+ch-'0'; - returnsig?x:-x; - } -InlinevoidWriteintx) { + if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; - intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; + for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; A } at voidBuildintb) { - for(inti=st[b];i<=en[b];i++) B[i]=a[i];sort (b+st[b],b+en[b]+1);return; - } - voidDownintb) { - if(Set[B]!=inf) { for(inti=st[b];i<=en[b];i++) a[i]=b[i]=Set[b];Set[B]=inf;}return; - } in voidSett (intLintRintCV) { -Down (Z[l]); for(inti=l;i<=r;i++) A[i]=cv;build (Z[l]);return; to } + voidSETB (intLintRintCV) { - for(intb=l;b<=r;b++)Set[B]=CV;return; the } * voidSetointQlintQrintCV) { $ if(z[ql]==Z[QR]) sett (QL,QR,CV);Panax Notoginseng ElseSett (QL,EN[Z[QL]],CV), Setb (z[ql]+1, z[qr]-1, CV), sett (ST[Z[QR]],QR,CV);return; - } the intQueryb (intLintRintCV) { + intans=0; A for(intb=l;b<=r;b++){ the if(Set[b]!=inf) { + if(Set[B]<=CV] ans+=Siz[b]; -}ElseAns+=upper_bound (b+st[b],b+en[b]+1, CV)-b-St[b]; $}returnans; $ } - intQueryt (intLintRintCV) { - intans=0; the if(Set[z[l]]!=inf) { - if(Set[Z[L]]<=CV] ans+= (r-l+1);Wuyi}Else for(inti=l;i<=r;i++)if(A[I]<=CV) ans++; the returnans; - } Wu intQueryo (intQlintQrintCV) { - if(Z[QL]==Z[QR])returnQueryt (QL,QR,CV); About Else returnQueryt (QL,EN[Z[QL]],CV) +queryb (z[ql]+1, z[qr]-1, CV) +Queryt (ST[Z[QR]],QR,CV); $ } - voidinit () { -N=read (); Size=sqrt ((Double) n0.9);intTP,QL,QR,CV; - for(intI=1; i<=n;i++){ Aa[i]=b[i]=read (); +z[i]= (I-1)/size+1; the if(!st[z[i]]) st[z[i]]=i; -en[z[i]]=i; $ } the for(intb=1; b<=z[n];b++) build (b),Set[b]=inf,siz[b]=en[b]-st[b]+1; the for(intI=1; i<=n;i++){ theTp=read (); Ql=read (); Qr=read (); cv=read (); the if(tp==2) Write (Queryo (QL,QR,CV)), ENT; - ElseSeto (QL,QR,CV); in } the return; the } About voidWork () { the return; the } the voidprint () { + return; - } the intMain () {init (); work ();p rint ();return 0;}
Summing up the tip:queryt of WA is to be violent when the nest Meng .....
There is a beginning did not write B array Oh ...
COJ 0967 WZJ data structure (negative 33)