| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
优先队列188MS~~菜鸟求指点~~#include<cstdio>
#include<queue>
using namespace std;
struct cmp1
{
bool operator()(const int a,const int b)
{
return a>b;
}
};
struct cmp2
{
bool operator()(const int a,const int b)
{
return a<b;
}
};
priority_queue<int,vector<int>,cmp1>q1;
priority_queue<int,vector<int>,cmp2>q2;
int a[30000],u,i;
int main()
{
int m,n,c=0,t;
scanf("%d%d",&m,&n);
for(i=0;i<m;i++)scanf("%d",&a[i]);
for(i=0;i<n;i++){
scanf("%d",&u);
while(c<u){
q1.push(a[c]);
if(!q2.empty()&&q1.top()<q2.top()){
t=q1.top();
q1.pop();
q1.push(q2.top());
q2.pop();
q2.push(t);
}
c++;
}
printf("%d\n",q1.top());
q2.push(q1.top());
q1.pop();
}
}
Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator