BZOJ 磁暴

Description

给定M及一列数,每个数在0到100,000之间。

(为了方便描述,设共N个数,1< N < = 2500000) 输出每M个数中的最大数,即1~M中的最大数,

2~M+1中的最大数……N-M+1~N中的最大数,共N-M+1个。

Format

Input

第一行是一个数M,接下来是N个数,每个数一行,以-1作为结尾

Output

输出N-M+1个最大数,每个数一行。

Samples

输入数据 1

3
10
11
10
0
0
0
1
2
3
2
-1

Copy

输出数据 1

11
11
10
0
1
2
3
3

#include<bits/stdc++.h>
using namespace std;
int n,lk,m,f[2432588];
struct op{
    int a,b;
};
bool operator<(op a,op b){
    return a.a<b.a;
}
priority_queue<op> q;
int main(){
    cin>>m;
    for(int i=1;i<=m;i++){
        cin>>lk;
        q.push({lk,i});
    }
    cout<<q.top().a<<endl;
    for(int i=m+1;;i++){
        cin>>lk;
        if(lk==-1){
            break;
        }
        q.push({lk,i}); 
        f[i-m]=1;
        while(1){
            if(f[q.top().b]==1){
                f[q.top().b]=0;
                q.pop();
            }
            else break;
        }
        cout<<q.top().a<<endl;
    }
    return 0;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值