codeforces 85D. Sum of Medians
阿新 • • 發佈:2017-08-08
namespace clu amp ins iostream log getchar dia word
二次聯通門 : 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 charword = 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; intmain (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