赞
踩
思路:单调队列
就是一个板子题,直接上代码:
- #include<iostream>
- #include<stdio.h>
- #include<cstring>
- #include<cstdlib>
- #include<cmath>
- #include<vector>
- #include<algorithm>
- #include<stack>
- #include<queue>
- #include<deque>
- #include <iomanip>
- #include<sstream>
- #include<numeric>
- #include<map>
- #include<limits.h>
- #include<unordered_map>
- #include<set>
- #define int long long
- #define MAX 2000200
- #define inf 0x3f3f3f3f
- #define _for(i,a,b) for(int i=a;i<(b);i++)
- #define ALL(x) x.begin(),x.end()
- using namespace std;
- typedef pair<int, int> PII;
- int n, m, k;
- int counts=inf;
- int dx[] = { 0,1,0,-1};
- int dy[] = { 1,0,-1,0 };
- int q[MAX];
- int arr[MAX];
- int b[MAX];
- void get_max(int a[], int b[], int n, int qujian) {
- int front = 0;
- int rear = -1;
- for (int i = 0; i < n; i++) {
- if (front <= rear && q[front] + qujian <= i)front++;
- while (front <= rear && a[q[rear]] <= a[i])rear--;
- q[++rear] = i;
- if (i >= qujian - 1)
- b[i] = a[q[front]];
- }
- }
- signed main() {
- ios::sync_with_stdio(false);
- cin.tie(NULL); cout.tie(NULL);
- cin >> n >> k;
- for (int i = 0; i < n; i++) {
- cin >> arr[i];
- }
- get_max(arr, b, n, k);
- _for(i, k - 1, n)
- cout << b[i] << endl;
- return 0;
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。