标签:des style http color os strong io for
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 7177 | Accepted: 2916 |
Description
N Transaction i Black Box contents after transaction Answer (elements are arranged by non-descending) 1 ADD(3) 0 3 2 GET 1 3 3 3 ADD(1) 1 1, 3 4 GET 2 1, 3 3 5 ADD(-4) 2 -4, 1, 3 6 ADD(2) 2 -4, 1, 2, 3 7 ADD(8) 2 -4, 1, 2, 3, 8 8 ADD(-1000) 2 -1000, -4, 1, 2, 3, 8 9 GET 3 -1000, -4, 1, 2, 3, 8 1 10 GET 4 -1000, -4, 1, 2, 3, 8 2 11 ADD(2) 4 -1000, -4, 1, 2, 2, 3, 8
Input
Output
Sample Input
7 4 3 1 -4 2 8 -1000 2 1 2 6 6
Sample Output
3 3 1 2
Source
AC代码:看代码解释就行了
#include<iostream> #include<queue> #include<algorithm> #include<stdio.h> using namespace std; int a[30010]; priority_queue <int> qu1; //优先队列由大到小保存前i小的数 priority_queue <int,vector<int>,greater<int> > qu2; //优先队列由小到大保存剩下的数 int main(){ int n,m; while(scanf("%d%d",&n,&m)!=EOF){ for(int i=0;i<n;i++) scanf("%d",&a[i]); while(!qu1.empty()) qu1.pop(); while(!qu2.empty()) qu2.pop(); int t=0; for(int i=1;i<=m;i++){ int x; scanf("%d",&x); while(t<x) qu1.push(a[t++]); while(qu1.size()>i){ qu2.push(qu1.top()); qu1.pop(); } while(qu1.size()<i){ qu1.push(qu2.top()); qu2.pop(); } while(!qu2.empty() && qu1.top()>qu2.top()){ //使qu1的所有数都比qu2的数小 qu2.push(qu1.top()); qu1.pop(); qu1.push(qu2.top()); qu2.pop(); } printf("%d\n",qu1.top()); } } return 0; }
标签:des style http color os strong io for
原文地址:http://blog.csdn.net/my_acm/article/details/38225433