这题做网络赛的时候连看都没看,就听队友说了一下题意,算了一下暴力的复杂度超了,之前做过一道类似的题是用树状数组做的,因为树状数组不太熟悉而且感觉写网络流题更有把握一些,我们学校也只有一支队出了这道题,所以就没有管这道题。赛后找题解看到正解是线段树题,不过我又发现有人直接就用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);
}
}
}
}