0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-23 20:48:48 +00:00

P3572 [POI2014]PTA-Little Bird

https://www.luogu.com.cn/record/77644318
This commit is contained in:
Baoshuo Ren 2022-06-19 21:16:29 +08:00
parent e86a425687
commit 2375fdcf82
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A

46
Luogu/P3572/P3572.cpp Normal file
View File

@ -0,0 +1,46 @@
#include <iostream>
#include <deque>
#include <vector>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 1000005;
int n, q, k, d[N];
int main() {
std::ios::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> d[i];
}
cin >> q;
while (q--) {
cin >> k;
std::vector<int> f(n + 1);
std::deque<int> q;
q.push_back(1);
for (int i = 2; i <= n; i++) {
while (!q.empty() && q.front() < i - k) q.pop_front();
f[i] = f[q.front()] + (d[q.front()] <= d[i]);
while (!q.empty()
&& (f[q.back()] > f[i]
|| f[q.back()] == f[i] && d[q.back()] <= d[i]))
q.pop_back();
q.push_back(i);
}
cout << f[n] << endl;
}
return 0;
}