HDU 4288 Coder(线段树或者暴力vector)#by zh

这题做网络赛的时候连看都没看,就听队友说了一下题意,算了一下暴力的复杂度超了,之前做过一道类似的题是用树状数组做的,因为树状数组不太熟悉而且感觉写网络流题更有把握一些,我们学校也只有一支队出了这道题,所以就没有管这道题。赛后找题解看到正解是线段树题,不过我又发现有人直接就用vector水过了,瞬间又给这题跪了,伤不起啊,下面贴一个STL水过的代码,线段树神马的,一会再研究……
#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;
int n;
char str[5];
vector<int> num;
vector<int>::iterator it;
int main()
{
    while(scanf("%d",&n)!=EOF)
    {
        num.clear();
        for(int i=0;i<n;i++)
        {
            scanf("%s",str);
            if(str[0]=='a')
            {
                int temp;
                scanf("%d",&temp);
                it=lower_bound(num.begin(),num.end(),temp);
                num.insert(it,temp);
            }
            else if(str[0]=='d')
            {
                int temp;
                scanf("%d",&temp);
                it=lower_bound(num.begin(),num.end(),temp);
                num.erase(it);
            }
            else
            {
                long long ans=0;
                for(int i=2;i<num.size();i+=5)
                {
                    ans+=num[i];
                }
                printf("%I64d\n",ans);
            }
        }
    }
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值