codeforces 85D. Sum of Medians

Posted ZlycerQan

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了codeforces 85D. Sum of Medians相关的知识,希望对你有一定的参考价值。

二次联通门 : codeforces 85D. Sum of Medians

 

 

 

 

/*
    codeforces 85D. Sum of Medians

    正解线段树或是平衡树
    
    结果用vector暴力卡过去了 
     
*/
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

void read (int &now)
{
    register char word = getchar ();
    int temp = 0;
    for (; !isdigit (word); word = getchar ())
        if (word == -)
            temp = 1;
    for (now = 0; isdigit (word); now = now * 10 + word - 0, word = getchar ());
    if (temp == 1)
        now = -now;
}

int N;

std :: vector <int> Flandre;

int main (int argc, char *argv[])
{
    read (N);
    
    static char type[10];
    register long long Answer;
    int x, L;
    for (register int i; N; -- N)
    {
        scanf ("%s", type);
        if (type[0] == a)
        {
            read (x);
            Flandre.insert (lower_bound (Flandre.begin (), Flandre.end (), x), x); 
        }
        else if (type[0] == d)
        {
            read (x);
            Flandre.erase (lower_bound (Flandre.begin (), Flandre.end (), x));
        }
        else
        {
            L = Flandre.size ();
            for (i = 2, Answer = 0; i < L; i += 5)
                Answer += Flandre[i];
            printf ("%lld\n", Answer);
        }
    }
    return 0;
}

 

以上是关于codeforces 85D. Sum of Medians的主要内容,如果未能解决你的问题,请参考以下文章

Codeforces 85D Sum of Medians(线段树)

[题解] CF85D Sum of Medians

Educational Codeforces Round 108 (Rated for Div. 2)-D. Maximum Sum of Products-题解

Codeforces Round 108(Problem - D Maximum Sum of Products)

CodeForces 489C Given Length and Sum of Digits...

Codeforces 85 DSum of Medians