1057 Stack (分块思想)
Input Specification: Push key Pop PeekMedian key 1. Output Specification: Push key Pop PeekMedian Invalid Sample Input: 17 Pop PeekMedian Push 3 PeekMedian Push 2 PeekMedian Push 1 PeekMedian Pop Pop Push 5 Push 4 PeekMedian Pop Pop Pop Pop Sample Output: Invalid Invalid 3 2 2 1 2 4 4 5 3 Invalid 由于N<=10^5,暴力算法肯定超时,我一开始思考用multiset容器可以自动排序,只要找到中值即可 #include<cstdio> #include<set> #include<cstring> #include<stack> using namespace std; stack<int> st; multiset<int> se; int tot=0; int main(){ int n,m; char s[20]; scanf("%d",&n); for(int i=1;i<=n;i++){ scanf("%s",s); if(strcmp(s,"Pop")==0){ if(tot