[第1章 1.2t1] 求m区间内的最小值
51 字
1 分钟
[第1章 1.2t1] 求m区间内的最小值
//注意密集使用到endl,就需要像以下这样加速#include <bits/stdc++.h>using namespace std;typedef long long ll;int main(){ ios::sync_with_stdio(false);cin.tie(0); ll n,m; cin>>n>>m; vector<ll> a(n+1); deque<ll> dq; cout<<0<<'\n'; for(ll i=1;i<=n;i++)cin>>a[i]; for(ll i=1;i<n;i++){ while(!dq.empty()&&a[dq.back()]>a[i])dq.pop_back(); dq.push_back(i); while(!dq.empty()&&i-dq.front()>=m)dq.pop_front(); cout<<a[dq.front()]<<'\n'; } return 0;}支持与分享
如果这篇文章对你有帮助,欢迎分享给更多人或打赏支持!




