254 字
1 分钟
YZZX 集训笔记 Day4
模拟赛
植物收集
最美子序列
子序列问题 怎么样不记重复?
字符序列
网络攻防
杂题选讲
极大子矩形问题。
算法 & 数据结构
单调队列 - OI Wiki | P1886 滑动窗口 /【模板】单调队列
const int N = 1e6+5;int n, k;int a[N];deque<int> q;signed main(){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> k; for(int i = 1; i <= n; i++){ cin >> a[i]; } for(int i = 1; i <= n; i++){ while(!q.empty() && a[q.back()] >= a[i]) q.pop_back(); q.push_back(i); if(i >= k){ while(q.front() <= i - k) q.pop_front(); cout << a[q.front()] << " "; } } cout << endl; while(!q.empty()) q.pop_front(); for(int i = 1; i <= n; i++){ while(!q.empty() && a[q.back()] <= a[i]) q.pop_back(); q.push_back(i); if(i >= k){ while(q.front() <= i - k) q.pop_front(); cout << a[q.front()] << " "; } } return 0;} YZZX 集训笔记 Day4
https://darkmodest.github.io/posts/yzzxjixun/day4/