首页 > TAG信息列表 > P2032

洛谷 P2032 扫描

题目链接: https://www.luogu.com.cn/problem/P2032 题目大意: n个整数,一个长度为k的木板,木板一开始盖住了1~k个数,木板每次右移一个单位,直到右端与第n个数重合,每次移动前输出被覆盖住的数中的最大值。 思路: 求解区间内的最大值,单调队列模板题。 队列中储存数字的下标

P2032 扫描

#include <bits/stdc++.h> #define re register using namespace std; const int N=2e6+5; int n,k; int a[N]; int head, tail; int q[N]; void monotoneMax(){ head=1, tail=0; for(re int i=1;i<=n;i++){ while(head<=tail && a[q[t

洛谷P2032题解

入门题。 仔细浏览题面,发现是滑动窗口的超级弱化版。 只需要搞一个单调队列维护最大值就可以了。 1 #include<stdio.h> 2 #define reg register 3 #define ri reg int 4 #define rep(i, x, y) for(ri i = x; i <= y; ++i) 5 #define nrep(i, x, y) for(ri i = x; i >=

洛谷 P2032 扫描 题解

题面 用一个单调递减队列来维护一个区间,单调队列的头就是该区间的最大值; 因为在该数前面进队的数如果比后进的数要小就说明了前面进队的数绝对不会影响答案。   #include <bits/stdc++.h>using namespace std;int q[2000010];int a[2000010];int b[2000010];int ans[2000010];int

P2032 扫描

原题链接 今天刚学STL 发个板子纪念一下(单调队列) #include<bits/stdc++.h>using namespace std;int n,k;struct node{ int x,y;};deque<node> dq;int main(){ cin>>n>>k; for(int i=1;i<=n;i++) { node a; cin>>a.x; a.y=i;