2012ICPC-成都-1001-Coder.HDU 4288【vector】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4288

【list】【vector】今天都是现学现用- -。结果还是差一点点才AC,。太囧了- -。

他们都用线段树,几百行的高端代码,看不懂,我也肿么都看不出来是用线段树搞,然后就想到STL。开始用了list,TLE了,后来打定vector。但没想到add的时候也要用二分,RE到哭呀,- -。

代码:

View Code
 1 #include<cstdio>
 2 #include<cstring>
 3 #include<vector>
 4 #include<algorithm>
 5 
 6 using namespace std;
 7 vector<int>dq;
 8 int main(){
 9     int n,x,i,d;
10     char st[5];
11     vector<int>::iterator it;
12     while(~scanf("%d",&n)){
13         dq.clear();
14         while(n--){
15             scanf("%s",st);
16             if(!strcmp(st,"add")){
17                 scanf("%d",&x);//加入的时候也不是递增 
18                 it = lower_bound(dq.begin(),dq.end(),x);//二分 
19                 dq.insert(it,x);
20             }else if(!strcmp(st,"del")){
21                 scanf("%d",&x);
22                 it = lower_bound(dq.begin(),dq.end(),x);
23                 dq.erase(it);
24             }else{
25                 __int64 sum=0;
26                 for(i=2;i<dq.size();i+=5) sum+=dq[i];
27                 printf("%I64d\n",sum);
28             }
29         }
30     }
31     return 0;
32 }

 

 

posted @ 2012-09-16 23:28  舞步い嫣语逝爱醉灵魂  阅读(177)  评论(0)    收藏  举报