이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 300'010;
const int S = 4096;
multiset<int> fen[N];
int dp[N], a[N];
int ql[N];
int n;
__attribute__((optimize("O3,unroll-loops"),target("avx")))
int get_mx(int l, int r, int x)
{
int ans = 0;
Loop (i,l,r)
ans = ans < dp[i] && a[i] < x? dp[i]: ans;
return ans;
}
int main()
{
cin.tie(0) -> sync_with_stdio(false);
int d;
cin >> n >> d;
Loop (i,0,n)
cin >> a[i];
vector<int> st;
Loop (i,0,n) {
while (st.size() && a[st.back()] < a[i])
st.pop_back();
ql[i] = st.size()? max(0, st.back()-d+1): 0;
st.push_back(i);
}
for (int l = 0; l < n; l += S) {
int r = min(l + S, n);
Loop (i,l,r) {
dp[i] = max(dp[i], get_mx(max(ql[i], l), i, a[i]));
dp[i] += 1;
}
Loop (i,r,n)
dp[i] = max(dp[i], get_mx(max(ql[i], l), r, a[i]));
}
int ans = 0;
Loop (i,0,n)
ans = max(ans, dp[i]);
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |