Bzoj 4605: Laoshan white flower snake grass water

Source: Internet
Author: User

Description God Ben Aleph in Sdoi Round2 before a flag: If into the provincial team, live live drink Laoshan white snake grass water. With the power of God Ben Aleph, he easily entered the Shandong provincial team, now is the time for him to fulfill his promise. Konjac Konjac Bob Specially prepared for him 999,999,999,999,999,999 bottles of Laoshan white flower snake grass water, want to pour god Ben Aleph. God Ben Aleph Beg (on his knees) Konjac Konjac Bob do not fill him, because God Ben Aleph is God Ben, Konjac Konjac Bob finally agreed to his request, but Konjac Konjac Bob decided went ahead, also let God Ben Aleph answer some questions. Specifically, Konjac Konjac Bob will place some Laoshan on a spacious square (which can be regarded as some point on the two-dimensional plane) and then ask God Ben Aleph in the rectangular area (x1, y1), (x2, y2) (X1≤X2 and y1≤y2, including boundaries), Laoshan White Snake grass Aquarius number k is how much. In order to avoid trouble, Konjac Konjac Bob will not place two or two more Laoshan in the same place, but Konjac Konjac Bob wants to embarrass God Ben Aleph, hoping that he can answer the question at once every time he asks. God Ben Aleph To do such a problem, so I gave it to you.

The first behavior of input inputs is two positive integers n, Q, which represents the range of the horizontal ordinate and the number of Konjac Konjac Bob's operations (including number of placements and number of queries). Next to Q, each row represents an operation for Konjac Konjac Bob, with the following format: First the first number type, which indicates the type of operation. Type=1 indicates placement, type=2 is asking. If type=1, then there will be three positive integers x, y, V, indicating the coordinates on the hour (x, y) place the V bottle Laoshan white flower snake grass water. (1≤x, Y≤n, 1≤v≤10^9) if type=2, next there will be five positive integers x1, y1, x2, y2, K, indicating the question of the rectangular area (x1, y1), (x2, y2), Laoshan white snake grass water bottle number k is how much. (1≤X1≤X2≤N,1≤Y1≤Y2≤N,1≤K≤Q) to reflect the online nature of the program, you need to vary the data you read (except for the type value) or Lastans, where Lastans represents the answer to the last query. If the answer to the last question is "naive! Orzzyz. " (see sample output), Lastans is set to 0. The initial Lastans is 0. There is no Laoshan on the initial plane of the white flower snake grass water. There are 12 sets of test data. For all the data, n≤500,000. The range of Q is shown in the table below: test pilot 1-2 q=1,000 testing point 3-7 q=50,000 test point 8-12 q=100,000

Output for each inquiry (type=2 operation), answer Laoshan white snake grass water bottle number k is how much. If there are no more than k bottles, please output "naive! Orzzyz. " (The output does not contain double quotes).

Sample Input10 7
1 1 1 1
1 2 2 3
1 4 1 2
1 3 4 4
2 1 1 4 1 3
2 2 2 3 5 4
2 2 1 4 4 2Sample Outputnaive! Orzzyz.
naive! Orzzyz.
3 the name ... segment Tree Set k-d tree, reconstruction words will take out all the achievements and put back.
#include <cstdio>#include<algorithm>#defineMN 1400010#defineM 2000using namespacestd;intn,m,x,ro[mn],l[mn],r[mn],x,y,num=0, nm=0, x1,x2,y1,y2,root=0, xx,o,mmh=0, Mmh[mn],st[mn],l,r;structtr{intx, y; FriendBOOL operator<(tr a,tr b) {ifXreturna.x<b.x;Else returna.y<b.y; }}A[MN],A[MN];structtree{intXa,xi,ya,yi,l,r,si;} T[MN],T[MN];CharCs;inlineintRead () {CS=getchar (); xx=0;  while(cs<'0'|| Cs>'9') cs=GetChar ();  while(cs>='0'&&cs<='9') xx=xx*Ten+cs- -, cs=GetChar (); returnxx;} Inlinevoid inch(int&p,BOOLb) {    if(!p) {P=num; T[P].L=t[p].r=0; T[p].xa=t[p].xi=a[num].x; T[p].ya=t[p].yi=a[num].y; T[p].si=1; return; } X=b;t[p].si++; if(A[num]<a[p])inch(t[p].l,b^1);Else inch(t[p].r,b^1); T[p].xa=Max (t[p].xa,a[num].x); T[p].xi=min (t[p].xi,a[num].x); T[p].ya=Max (T[P].YA,A[NUM].Y); T[p].yi=min (t[p].yi,a[num].y);} InlineintBuildintLintRintNow ) {X=Now ; intMid= (l+r) >>1; Nth_element (A+l,a+mid,a+r+1); T[mid].si=r-l+1; T[mid].xa=t[mid].xi=a[mid].x; T[mid].ya=t[mid].yi=a[mid].y; if(L<mid) T[mid].l=build (l,mid-1, now^1), T[mid].xa=Max (T[T[MID].L].XA,T[MID].XA), T[mid].xi=min (t[t[mid].l].xi,t[mid].xi), T[mid].ya=Max (T[t[mid].l].ya,t[mid].ya), T[mid].yi=min (T[t[mid].l].yi,t[mid].yi);ElseT[mid].l=0; if(Mid<r) T[mid].r=build (mid+1, r,now^1), T[mid].xa=Max (T[T[MID].R].XA,T[MID].XA), T[mid].xi=min (t[t[mid].r].xi,t[mid].xi), T[mid].ya=Max (T[t[mid].r].ya,t[mid].ya), T[mid].yi=min (T[t[mid].r].yi,t[mid].yi);ElseT[mid].r=0; returnMid;} InlineintWout (intp) {St[l=r=1]=p;  while(l<=R) {A[l]=A[st[l]]; if(T[ST[L]].L) st[++r]=T[ST[L]].L; if(T[ST[L]].R) st[++r]=T[ST[L]].R; L++; } l=build (1R0);  for(RegisterintI=1; i<=r;i++) t[st[i]]=t[i],a[st[i]]=a[i],t[st[i]].l=st[t[st[i]].l],t[st[i]].r=ST[T[ST[I]].R]; returnSt[l]; returnp;} InlinevoidInsertint&p,intLintRintVBOOLb) {    if(!p) p=++nm,mmh[p]=l; if(b) {a[++num].x=x;a[num].y=y;inch(Ro[p],0); if(T[ro[p]].si==mmh[p]) mmh[p]+=m,ro[p]=Wout (ro[p]); }    if(L==R)return; intMid=l+r>>1; if(v<=mid) Insert (L[P],L,MID,V,0);ElseInsert (r[p],mid+1, R,v,1);} InlineintAskintp) {    if(t[p].xa<=x2&&t[p].xi>=x1&&t[p].ya<=y2&&t[p].yi>=y1)return 1; if(t[p].xi>x2| | t[p].xa<x1| | t[p].yi>y2| | T[P].YA&LT;Y1)return 0; return 2;} InlineBOOLInlintp) {    if(A[p].x>=x1&&a[p].x<=x2&&a[p].y>=y1&&a[p].y<=y2)return 1; return 0;} InlineintQUE (intp) {    intMmh=ask (P); if(!MMH)return 0; if(mmh==1)returnt[p].si;Else{        if(INL (p)) mmh=1;ElseMmh=0; if(T[P].L) mmh+=QUE (T[P].L); if(T[P].R) mmh+=QUE (T[P].R); }    returnMmh;} InlineintQueintPintLintRintk) {    if(L==R)returnl; intu=0;if(R[p]) u=QUE (ro[r[p]); intMid=l+r>>1; if(u<k)returnQue (l[p],l,mid,k-u);Else returnQue (r[p],mid+1, r,k);}intMain () {registerinti,k; N=read (); m=read ();  for(i=1; i<=m;i++) {o=read (); if(o==1) X=mmh^read (), Y=mmh^read (), insert (root,1, 1e9,mmh^read (),1);Else{x1=mmh^read (); Y1=mmh^read (); X2=mmh^read (); Y2=mmh^read (); k=mmh^read (); if(QUE (Ro[root]) <k) printf ("naive! orzzyz.\n", mmh=0);Elseprintf ("%d\n", Mmh=que (Root,1, 1e9,k)); }    }}
126604 kb 24240 ms C++/edit 3738 B

Bzoj 4605: Laoshan white flower snake grass water

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.