이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 3e5 + 2;
const int OFF = 1 << 20;
int n, d, a[MAXN], ans;
int tour[OFF];
priority_queue<int, vector<int>, greater<int> > pq;
multiset<int> ms;
vector<int> cmp;
map<int, int> um;
int f(int x, int l, int r, int ql, int qr){
if(ql <= l && r <= qr) return tour[x];
if(ql > r || l > qr) return 0;
int mid = (l + r) >> 1;
return max(f(x * 2 + 1, l, mid, ql, qr), f(x * 2 + 2, mid + 1, r, ql, qr));
}
void upd(int x, int l, int r, int i, int val){
if(l > i || r < i) return ;
if(l == r){
tour[x] = val;
return ;
}
int mid = (l + r) >> 1;
upd(x * 2 + 1, l, mid, i, val);
upd(x * 2 + 2, mid + 1, r, i, val);
tour[x] = max(tour[x * 2 + 1], tour[x * 2 + 2]);
}
int main(){
cin >> n >> d;
for(int i = 0; i < n; ++i){
cin >> a[i];
cmp.push_back(a[i]);
}
sort(cmp.begin(), cmp.end());
cmp.erase(unique(cmp.begin(), cmp.end()), cmp.end());
for(int i = 0; i < (int)cmp.size(); ++i) um[cmp[i]] = i;
for(int i = 0; i < n; ++i) a[i] = um[a[i]];
if(d == 1){
set<int> s;
for(int i = n - 1; i >= 0; --i){
while(!s.empty() && *s.begin() <= a[i]){
s.erase(s.begin());
}
s.insert(a[i]);
ans = max(ans, (int)s.size());
}
cout << ans << "\n";
return 0;
}
for(int i = 0; i < n; ++i){
int x = 0;
if(a[i]) x = f(0, 0, n - 1, 0, a[i] - 1);
upd(0, 0, n - 1, a[i], x + 1);
ans = max(ans, tour[0]);
ms.insert(a[i]);
pq.push(a[i]);
if(i >= d){
ms.erase(ms.find(a[i - d]));
int mini = *ms.begin();
while(pq.top() < mini){
int x = pq.top();
upd(0, 0, n - 1, x, 0);
pq.pop();
}
}
}
cout << ans;
return 0;
}
# | 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... |