Bzoj 1862: [Zjoi2006]gamez Game ranking system [treap Hash]

Source: Internet
Author: User
Tags new set

1862: [Zjoi2006]gamez Game ranking system time limit:5 Sec Memory limit:64 MB
submit:1318 solved:498
[Submit] [Status] [Discuss] Description

Gamez launched a website for their newest game. Players from all over the world can upload their game scores to the website. This way you can see your ranking in the world. The higher the score, the more forward the ranking. When the rank of two players is the same, uploading the record first is preferred. Due to the popularity of new games, Web servers have been overwhelmed by embarrassment. For this Gamez hired you to help them re-develop a new set of core. Ranking systems typically deal with three requests: uploading a new score record, querying the current position of a player, and returning the rank record in a segment. When a player uploads his or her latest scoring record, his original scoring record is deleted. To reduce the burden on the server, return up to 10 records when returning rank records in a segment.

Input

The first line is an integer n (n>=10) that represents the total number of requests. The next n rows contain one request per line. The exact format of the request is as follows: +name score upload the latest score record. Name indicates the player's name, consisting of uppercase English letters, no more than 10 characters. Score is a positive integer of up to 8 bits.? Name queries the player rankings. The player's score record must have been uploaded in front. Index returns a maximum of 10 player names starting from index. Index must be legal, that is, not less than 1, or the total number of players currently logged. The total size of the input file does not exceed 2M. Note: using C + + FStream to read large-scale data is less efficient

Output

For each query request, output the corresponding result. For? The name format of the request should output an integer representing the current rank of the player. For? In the index format, the name of up to 10 players starting with the index name should be output in one row, separated by a space.

Sample Input20
+adam 1000000 join ADAM's scoring record
+bob 1000000 add BOB's scoring record
+tom 2000000 join TOM's scoring record
+cathy 10000000 add to CATHY score record
? Tom output Tom Current ranking
1 The total number of players currently logged is 4, so the 1th to 4th place should be exported.
+dam 100000 scoring record for DAM entry
+bob 1200000 update BOB's scoring record
+adam 900000 update ADAM's score record (even worse than the original)
+frank 12340000 join FRANK's scoring record
+leo 9000000 joins LEO's scoring record
+kaine 9000000 add to KAINE score record
+grace 8000000 join GRACE's scoring record
+walt 9000000 add to WALT score record
+sandy 8000000 added SANDY's scoring record
+mick 9000000 add to MICK score record
+jack 7320000 join JACK's scoring record
2 The total number of players currently logged is 12, so the 2nd to 11th place should be exported.
? 5 output 5th to 13th place.
? KAINE Ranking of output KAINE

Sample Output2
CATHY TOM ADAM BOB
CATHY LEO KAINE WALT MICK GRACE SANDY JACK TOM BOB
WALT MICK GRACE SANDY JACK TOM BOB ADAM DAM
Review the Treap, please .because the same v commits first, it needs to record the timev Small to large, TM large to smallTreap The change of operation is the V-phase to discuss the timeInsert a person first in the hash table to find him, and then delete it in the insert newNote that in this case, the rankings are inverted.Note:1. Rotate don't write wrong2. Copy String memcpy (Tar,s,strlen (s)) is not sizeof (s) .....
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;#defineLC T[X].L#defineRC T[X].RConst intn=250005, mod=985003;intRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; C=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; C=GetChar ();} returnx*F;}intV,tm;Chars[ the];structnode{intL,r,v,t,size,rnd; Chars[ the];} T[n];intSz,root;inlinevoidUpdateintx) {t[x].size=t[lc].size+t[rc].size+1;} InlinevoidRturn (int&x) {    intC=lc;lc=t[c].r;t[c].r=x; T[c].size=t[x].size;update (x); x=C;} InlinevoidLturn (int&x) {    intC=rc;rc=t[c].l;t[c].l=x; T[c].size=t[x].size;update (x); x=C;} InlinevoidInsint&x,intVintTmChars[]) {    if(x==0) {sz++;x=sz; T[X].L=t[x].r=0; t[x].size=1; T[X].V=v;t[x].rnd=rand (); t[x].t=TM;        memcpy (T[x].s,s,strlen (s)); return; } t[x].size++; if(v<=t[x].v)        {ins (lc,v,tm,s); if(t[lc].rnd<t[x].rnd) Rturn (x); }Else{ins (rc,v,tm,s); if(t[rc].rnd<t[x].rnd) Lturn (x); }}inlinevoidDelint&x,intVintTM) {    if(x==0)return; if(t[x].v==v) {        if(t[x].t==TM) {            if(lc*rc==0) x=lc+RC; Else if(t[lc].rnd<t[rc].rnd) Rturn (x), Del (X,V,TM); ElseLturn (x), Del (X,V,TM); }Else{t[x].size--; if(tm>t[x].t) del (LC,V,TM); Elsedel (RC,V,TM); }    }Else{t[x].size--; if(v<t[x].v) del (LC,V,TM); Elsedel (RC,V,TM); }}intRnkintXintVintTM) {    if(x==0)return 0; if(t[x].v==v) {        if(tm==t[x].t)returnT[lc].size+1; Else if(tm>t[x].t)returnrnk (LC,V,TM); Else returnT[lc].size+1+rnk (RC,V,TM); }    Else if(V&LT;T[X].V)returnrnk (LC,V,TM); Else returnT[lc].size+1+rnk (RC,V,TM);}intKthintXintk) {    if(x==0)return 0; if(k<=t[lc].size)returnkth (lc,k); Else if(k>t[lc].size+1)returnKTH (rc,k-t[lc].size-1); Else returnx;}structdata{intV,tm,ne; Chars[ the];} Mp[mod+5];intH[mod+5],cnt;intHshChars[]) {    intx=0, Len=strlen (s+1);  for(intI=1; i<=len;i++) x= (x* -+s[i]-'A'+1)%MOD; returnx;} InlineBOOLEquCharS1[],Chars2[]) {    intL1=strlen (S1), l2=strlen (S2); if(L1!=L2)return false;  for(intI=1; i<=l1;i++)if(S1[i]!=s2[i])return false; return true;}voidInsert (CharS[],intVintTM) {    intk=HSH (s);  for(intI=h[k];i;i=mp[i].ne) {        if(Equ (S,MP[I].S)) {del (ROOT,MP[I].V,MP[I].TM); MP[I].V=v;mp[i].tm=TM;            Ins (root,v,tm,s); return; }} CNT++; MP[CNT].V=v;mp[cnt].tm=TM;    memcpy (Mp[cnt].s,s,strlen (s)); Mp[cnt].ne=h[k];h[k]=CNT; Ins (root,v,tm,s);}voidRank (Chars[]) {    intk=HSH (s), I;  for(i=h[k];i;i=mp[i].ne)if(Equ (S,MP[I].S)) Break; printf ("%d\n", cnt+1-rnk (ROOT,MP[I].V,MP[I].TM));}voidKth (Chars[]) {    intk=0, Len=strlen (s+1);  for(intI=1; i<=len;i++) k=k*Ten+s[i]-'0'; //printf ("Kth%d%s%d\n", K,s,len);     for(inti=k;i<=cnt&&i<=k+9; i++) {printf ("%s", T[kth (root,cnt+1-I.)].s+1); if(i<cnt&&i<k+9) Putchar (' '); } Putchar ('\ n');}intMain () {intt=read ();  for(intI=1; i<=t;i++) {scanf ("%s", s); if(s[0]=='+') {v=read ();        Insert (S,v,i); }Else{            if(s[1]>='0'&&s[1]<='9') Kth (s); ElseRank (s); }    }}

Bzoj 1862: [Zjoi2006]gamez Game ranking system [treap Hash]

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.