超时求助!!!
查看原帖
超时求助!!!
359492
BZHZS楼主2021/7/21 23:55
#include <bits/stdc++.h>
#define ll long long
#define yes {puts("Yes");return 0;}
#define no {puts("No");return 0;}
#define BZHZS puts("BZH is a handsome boy.");
using namespace std;

struct node {
    int sum, id;
};

node a[2000006];
deque <node> q, w;
int n, k;
int ans1[2000006], ans2[2000006];

void ts (int a, string tt) {
    cout << tt << ":: " << a << endl;
    system ("pause");
    return;
}

int main() {
    ios:: sync_with_stdio (0);
    cin.tie(0), cout.tie(0);
    //freopen ("BZHZS.in" , "r" , stdin);
    //freopen ("BZHZS.out " , "w" , stdout);

    cin >> n >> k;
    for (int i=1; i<=n; i++) {
        cin >> a[i].sum;
        a[i].id = i;
    }

    cout << 0 << endl;
    for (int i=1; i<n; i++) {
        while (!w.empty() && w.back().sum>=a[i].sum) {
            w.pop_back();
        }
        w.push_back (a[i]);
        if (w.front().id == i-k) {
            w.pop_front();
        }
        cout << w.front().sum << endl;
    }

    return 0;
}


2021/7/21 23:55
加载中...