BZOJ1503 [NOI2004] Depressed Teller

Source: Internet
Author: User

AC Channel: http://www.lydsy.com/JudgeOnline/problem.php?id=1503

"My feelings."

This problem was depressed for a long time, because the problem discussed in discuss and I are not a problem ...

Discuss of course is a big pit point, is the initial salary is not counted in the final kick out of the number.

But this is the first thing I've ever called. But I've been out of time.

Finally came the data ... Well, the original is the nature of the balance tree is not how to use ... Did not turn a few times ah, and then the data on the special card this, continuous increase in wages of people [into the chain]

Then I randomly turn a turn, and then do not know why not Srand (time (0)), anyway this will re, so simply do not add random seeds, finally took care of ...

Analysis

Here's my idea about this:

1. Because whether it is processing capital or wage reduction or membership or k, it is related to the numerical value of the data and is independent of the order, thus establishing a two-tree according to the numerical size

2. There is only one difference between this question and the usual +tag, that is, the deletion and the reduction of wages are carried out together. So we need to be deleted from the personnel first to find out, that is, wages < minimum wage + deduction of wages, which is of course a sub-tree, delete is good.

3. Other operations are the same as before, because each increase in wages and wages are for all people, so the relative size will not change, the next time if the interval value ... That would be a lot of trouble. [How to do it? I naturally can't think of ...]

#include <cstdio>#include<ctime>#include<cstring>#include<cstdlib>#include<algorithm>using namespaceStd;inlineint inch(){    intx=0;CharCh=GetChar ();  while(ch>'9'|| ch<'0') ch=GetChar ();  while(ch>='0'&& ch<='9') x=x*Ten+ch-'0', ch=GetChar (); returnx;}Const intmaxn=100010;structnode{intf,ch[2]; intsz,ct; intdt,pt;} S[MAXN];intM,min,n,rt;voidPush_down (intx) {    if(!s[x].pt)return; if(s[x].ch[0]) s[s[x].ch[0]].dt+=s[x].pt,s[s[x].ch[0]].pt+=s[x].pt; if(s[x].ch[1]) s[s[x].ch[1]].dt+=s[x].pt,s[s[x].ch[1]].pt+=s[x].pt; s[x].pt=0;}voidUpdateintx) {S[X].SZ=s[s[x].ch[0]].sz+s[s[x].ch[1]].sz+S[x].ct;}intFind (intk) {    intp=RT; if(S[rt].sz<k | | k<=0)return-1;  while(P) {Push_down (P); if(k<=s[s[p].ch[0]].SZ) p=s[p].ch[0]; Else{k-=s[s[p].ch[0]].sz; if(K&LT;=S[P].CT)returnp; K-=s[p].ct;p=s[p].ch[1]; }    }}voidRotate (intXintk) {    inty=s[x].f;s[x].f=s[y].f; if(S[Y].F) {if(s[s[y].f].ch[0]==y) s[s[y].f].ch[0]=x;Elses[s[y].f].ch[1]=x;} S[Y].CH[K]=s[x].ch[k^1]; if(s[x].ch[k^1]) s[s[x].ch[k^1]].f=y; S[Y].F=x,s[x].ch[k^1]=y; Update (y), update (x);}voidSplay (intXintgf) {    inty;  while(s[x].f!=gf) {y=s[x].f; if(s[y].f==gf) {            if(x==s[y].ch[0]) Rotate (x,0);ElseRotate (x,1);} Else{            intz=s[y].f; if(y==s[z].ch[0]){                if(x==s[y].ch[0]) Rotate (Y,0), Rotate (x,0);ElseRotate (x,1), Rotate (x,0);} Else{                if(x==s[y].ch[1]) Rotate (Y,1), Rotate (x,1);ElseRotate (x,0), Rotate (x,1);} }    }    if(!GF) rt=x;}voidInsert (intx) {    if(x<min)return; if(!RT) {s[++n].dt=x;s[n].sz=1; rt=n,s[n].ct=1;return;} intp=RT;  while(p) {S[p].sz++;        Push_down (P); if(s[p].dt<x) {            if(s[p].ch[1]) p=s[p].ch[1]; Else{s[p].ch[1]=++n,s[n].dt=x,s[n].sz=1, s[n].f=p,s[n].ct=1; Break; }        }        Else if(s[p].dt>x) {            if(s[p].ch[0]) p=s[p].ch[0]; Else{s[p].ch[0]=++n,s[n].dt=x,s[n].sz=1, s[n].f=p,s[n].ct=1; Break; }        }        Else{n++;s[p].ct++;return; }    }    if(rand ()% -> the) splay (N,0);}voidAddition (intx) {S[rt].dt+=x,s[rt].pt+=x;}voidShorten (intx) {    intp=rt,bye=min+x,rec=-1;  while(P) {Push_down (P); if(s[p].dt<bye) rec=p,p=s[p].ch[1]; ElseP=s[p].ch[0]; }    if(rec!=-1) {splay (REC,0); RT=s[rec].ch[1],s[rt].f=0; if(RT) update (RT); }    if(RT) s[rt].dt-=x,s[rt].pt-=x;}intGet_kth (intk) {    intX=find (s[rt].sz-k+1); if(x<0)return-1; if(rand ()% -> the) splay (x,0); returnS[x].dt;}intMain () {#ifndef Online_judge freopen ("1503.in","R", stdin); Freopen ("1503.out","W", stdout);#endif        intK; Charord[2]; scanf ("%d%d",&m,&Min);  while(m--) {scanf ("%s", ord); k=inch(); if(ord[0]=='I') Insert (k); Else if(ord[0]=='A') addition (k); Else if(ord[0]=='S') Shorten (k); Else if(ord[0]=='F') printf ("%d\n", get_kth (k)); } printf ("%d", N-S[RT].SZ); return 0;}
View Code

BZOJ1503 [NOI2004] Depressed Teller

Related Keywords:

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.