标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 170 Accepted Submission(s): 59
Mean:
略
analyse:
vector直接水过。
Time complexity: O(n)
Source code:
/* * this code is made by crazyacking * Verdict: Accepted * Submission Date: 2015-05-30-22.26 * Time: 0MS * Memory: 137KB */ #include <queue> #include <cstdio> #include <set> #include <string> #include <Stack> #include <cmath> #include <climits> #include <map> #include <cstdlib> #include <iostream> #include <vector> #include <algorithm> #include <cstring> #define LL long long #define ULL unsigned long long using namespace std; vector<int> V; int n; char ord[10]; int num; int Stack[10010]; int l,r; int siz; inline void solve() { V.clear(); V.reserve(n+10); r=0; l=1; siz=0; for (int i=1;i<=n;i++) { scanf("%s",ord); if (ord[0]==‘i‘) scanf("%d",&Stack[++r]); if (ord[0]==‘i‘) { siz++; V.insert(upper_bound(V.begin(),V.end(),Stack[r]),Stack[r]); }else if (ord[0]==‘o‘) { V.erase(lower_bound(V.begin(),V.end(),Stack[l])); l++; siz--; }else{ printf("%d\n",V[siz/2]); } } } int T; int main(){ while(scanf("%d",&n)!=EOF) { T++; printf("Case #%d:\n",T); solve(); } return 0; }
标签:
原文地址:http://www.cnblogs.com/crazyacking/p/4541190.html