diff --git a/Luogu/P3572/P3572.cpp b/Luogu/P3572/P3572.cpp new file mode 100644 index 00000000..8e90152f --- /dev/null +++ b/Luogu/P3572/P3572.cpp @@ -0,0 +1,46 @@ +#include +#include +#include + +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 f(n + 1); + std::deque 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; +}