이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int n, d, aint[1200002];
void update(int nod, int st, int dr, int poz, int val)
{
if(st == dr)
{
aint[nod] = val;
return;
}
int mid = (st + dr) / 2;
if(poz <= mid)
update(nod << 1, st, mid, poz, val);
else
update(nod << 1|1, mid+1, dr, poz, val);
aint[nod] = max(aint[nod << 1], aint[nod << 1|1]);
}
int query(int nod, int st, int dr, int L, int R)
{
if(dr < L || st > R)
return 0;
if(L <= st && dr <= R)
return aint[nod];
int mid = (st + dr) / 2;
return max(query(nod << 1, st, mid, L, R), query(nod << 1|1, mid+1, dr, L, R));
}
int lz[1200002], aint2[1200002];
void lazy(int nod, int st, int dr)
{
aint2[nod] -= lz[nod];
if(st != dr)
{
lz[nod << 1] += lz[nod];
lz[nod << 1|1] += lz[nod];
}
lz[nod] = 0;
}
void build(int nod, int st, int dr)
{
if(st == dr)
{
aint2[nod] = n - st + 1;
return;
}
int mid = (st + dr) / 2;
build(nod << 1, st, mid);
build(nod << 1|1, mid+1, dr);
aint2[nod] = max(aint2[nod << 1], aint2[nod << 1|1]);
}
void update2(int nod, int st, int dr, int L, int R, int val)
{
lazy(nod, st, dr);
if(dr < L || st > R)
return;
if(L <= st && dr <= R)
{
lz[nod] += val;
lazy(nod, st, dr);
return;
}
int mid = (st + dr) / 2;
update2(nod << 1, st, mid, L, R, val);
update2(nod << 1|1, mid+1, dr, L, R, val);
aint2[nod] = max(aint2[nod << 1], aint2[nod << 1|1]);
}
int query2(int nod, int st, int dr, int L, int R)
{
lazy(nod, st, dr);
if(dr < L || st > R)
return -1;
if(L <= st && dr <= R)
return aint2[nod];
int mid = (st + dr) / 2;
return max(query2(nod << 1, st, mid, L, R), query2(nod << 1|1, mid+1, dr, L, R));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> d;
vector<pair<int, int> > v(n+1);
for(int i = 1; i <= n; i++)
{
cin >> v[i].first;
v[i].second = i;
}
// sort(v.begin() + 1, v.begin() + n + 1);
int ans = 0;
vector<int> dp(n+1);
vector<int> updates;
build(1, 1, n);
/*
for(int i = 1; i <= n; i++)
{
if(i != 1 && v[i].first > v[i-1].first)
{
for(auto x : updates)
{
update(1, 1, n, x, dp[x]);
}
updates.clear();
}
// binsearch
int stx = 1;
int drx = max(1, v[i].second - d);
int L = drx;
int R = v[i].second - 1;
// cout << L << " " << R << " " << v[i].second << '\n';
while(stx <= drx)
{
int mid = (stx + drx) / 2;
if(query2(1, 1, n, mid, max(1, v[i].second - d)) <= d)
{
L = mid;
drx = mid - 1;
}
else
stx = mid + 1;
}
dp[v[i].second] = 1;
if(R > 0)
dp[v[i].second] += query(1, 1, n, L, R);
cout << i << " " << v[i].second << " " << dp[v[i].second] << '\n';
updates.push_back(v[i].second);
int xx = query2(1, 1, n, v[i].second, v[i].second);
update2(1, 1, n, 1, v[i].second, xx);
ans = max(ans, dp[v[i].second]);
}
cout << ans << '\n';
*/
for(int i = 1; i <= n; i++)
{
int cnt = 0;
dp[i] = 1;
for(int j = i-1; j >= 1; j--)
{
if(v[i].first > v[j].first)
dp[i] = max(dp[i], dp[j] + 1);
if(v[j].first > v[i].first)
cnt++;
else
cnt = 0;
if(cnt >= d)
break;
}
ans = max(ans, dp[i]);
// cout << dp[i] << " ";
}
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... |