이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define in insert
#define er erase
#define pb push_back
#define ppb pop_back()
#define ph push
#define pp pop()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "Yes" << "\n";
#define no cout << "No" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007
using namespace std;
int main()
{
d3
ll n , d;
cin >> n >> d;
ll a[n];
for(int i = 0 ; n>i ; i++)
cin >> a[i];
if(d==1)
{
ll mx = 1;
multiset<ll> s;
for(int i = n-2 ; i>=0 ; i--)
{
while(true)
{
auto it = s.upper_bound(a[i]);
if(it==s.begin())
break;
it--;
s.erase(it);
}
s.in(a[i]);
ll e = s.size();
mx=max(mx,e);
}
ll ans = mx;
cans
return 0;
}
if(d==n)
{
vector<ll> ans;
for(int i = 0 ; n>i ; i++)
{
auto it = lower_bound(ans.begin(),ans.end(),a[i]);
if(it==ans.end())
ans.pb(a[i]);
else
*it = a[i];
}
cout << ans.size();
return 0;
}
ll ans[n];
ans[0]=1;
for(int i = 1 ; n>i ; i++)
{
ll mx = 0;
ll j = i-d;
if(j<0)
j=0;
ll h = i-1;
while(h>=j)
{
if(a[h]<a[i])
mx=max(mx,ans[h]);
if(a[h]<a[i])
j=h-d;
if(j<0)
j=0;
h--;
}
ans[i]=mx+1;
}
ll mx = 0;
for(int i = 0 ; n>i ; i++)
mx=max(mx,ans[i]);
cout << mx;
}
# | 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... |