1056: [HAOI2008]排名系统
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 2487 Solved: 711
[Submit][Status][Discuss]
Description
Input
Output
Sample Input
Input
20
+ADAM 1000000
+BOB 1000000
+TOM 2000000
+CATHY 10000000
?TOM
?1
+DAM 100000
+BOB 1200000
+ADAM 900000
+FRANK 12340000
+LEO 9000000
+KAINE 9000000
+GRACE 8000000
+WALT 9000000
+SANDY 8000000
+MICK 9000000
+JACK 7320000
?2
?5
?KAINE
Output
2
CATHY TOM ADAM BOB
CATHY LEO KAINE WALT MICK GRACE SANDY JACK TOM BOB
WALT MICK GRACE SANDY JACK TOM BOB ADAM DAM
4
说明
+ADAM 1000000 加入ADAM的得分记录
+BOB 1000000 加入BOB的得分记录
+TOM 2000000 加入TOM的得分记录
+CATHY 10000000 加入CATHY的得分记录
?TOM 输出TOM目前排名
?1 目前有记录的玩家总数为4,因此应输出第1名到第4名。
+DAM 100000 加入DAM的得分记录
+BOB 1200000 更新BOB的得分记录
+ADAM 900000 更新ADAM的得分记录(即使比原来的差)
+FRANK 12340000 加入FRANK的得分记录
+LEO 9000000 加入LEO的得分记录
+KAINE 9000000 加入KAINE的得分记录
+GRACE 8000000 加入GRACE的得分记录
+WALT 9000000 加入WALT的得分记录
+SANDY 8000000 加入SANDY的得分记录
+MICK 9000000 加入MICK的得分记录
+JACK 7320000 加入JACK的得分记录
?2 目前有记录的玩家总数为12,因此应输出第2名到第11名。
?5 输出第5名到第13名。
?KAINE 输出KAINE的排名
[数据范围]
20%数据满足N<=100
100%数据满足N<=250000
写了5个小时的splay,硬是没跳出来(WA代码还在COGS上呆着)
后来弃疗,直接pd_ds,1A。
#include<cstdio> #include<iostream> #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #include<ext/pb_ds/hash_policy.hpp> using namespace std; using namespace __gnu_pbds; class P{ public: string name; int val,tim; P(string n="",int v=0,int t=0):name(n),val(v),tim(t){} }z; class Compare{ public: bool operator ()(const P &a,const P &b)const{ if(a.val>b.val) return 1; if(a.val<b.val) return 0; if(a.tim<b.tim) return 1; if(a.tim>b.tim) return 0; return a.name<b.name; } }; typedef cc_hash_table<string,P> hs; typedef tree<P,null_mapped_type,Compare,rb_tree_tag,tree_order_statistics_node_update> bbt; hs ys; hs::point_iterator ith; bbt T; bbt::iterator itt; inline int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } int main(){ int n;char s[20]; n=read(); for(int i=1,x;i<=n;i++){ scanf("%s",s); if(s[0]=='+'){//upload recod x=read(); ith=ys.find(s+1); if(ith!=ys.end()) T.erase(ith->second); z=P(s+1,x,i); ys[s+1]=z; T.insert(z); } else if(s[1]>='0'&&s[1]<='9'){//query by order x=atoi(s+1); itt=T.find_by_order(x-1); int lim=min(10,(int)ys.size()-x+1); for(int j=1;j<=lim;j++){ printf("%s",itt->name.c_str()); if(j!=lim) putchar(' '); itt++; } if(i!=n) putchar(' '); } else{//query by name printf("%d",T.order_of_key(ys[s+1])+1); if(i!=n) putchar(' '); } } return 0; }