This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// Cu code roi se AC
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠠⡄⢠⡄⣠⠤⢤⡀⣤⠀⢠⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⡏⠀⣿⠀⢨⡇⣿⠀⢸⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠁⠀⠈⠉⠉⠀⠈⠉⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⢠⠤⣄⢠⡄⠀⣤⢀⣠⢤⡀⢠⡄⠀⡄⢠⡀⠀⢠⣤⣤⡀⠀⠀⠀⠀
// ⠀⠀⠀⠀⣙⠲⢦⢸⡗⠒⣿⢸⡁⠀⣿⢸⡇⠀⡇⢸⡇⠀⢸⡇⠀⡷⠀⠀⠀⠀
// ⠀⠀⠀⠀⠈⠛⠋⠈⠃⠀⠋⠀⠙⠛⠁⠀⠙⠛⠁⠘⠛⠛⠘⠛⠋⠁⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⢀⡀⢀⠀⡀⠀⠀⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⡷⣯⠀⢸⠀⡇⠀⠀⣿⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠃⠈⠓⠘⠀⠛⠒⠂⠛⠒⠂⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⣀⠀⢀⡀⢀⣀⡀⠀⡀⠀⣀⢀⣀⣀⡀⢀⣀⣀⠀⣀⣀⡀⣀⠀⠀⢀⣀⣀⠀
// ⠀⠘⢷⠏⢰⡏⠀⢹⠄⡇⠀⣿⢸⣧⢤⡇⠘⠦⣬⡀⡧⠤⠄⣿⠀⠀⢸⠤⠄⠀
// ⠀⠀⠘⠀⠀⠛⠒⠋⠀⠛⠒⠋⠘⠃⠀⠓⠘⠲⠚⠁⠓⠒⠂⠛⠒⠒⠘⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⡀⠀⢀⠀⢀⣀⠀⢀⠀⢀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⡿⢆⣸⢠⡏⠉⢹⡈⣇⡼⣇⣼⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⠀⠀⠀⠀⠀⠀⠀⠀⠀⠇⠈⠿⠀⠳⠶⠞⠀⠹⠇⠸⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⠏⠄⠄⠄⠄⠄⠄⠄⠄⠙⢿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⠄⠄⢀⣀⣀⣀⡀⠄⢀⣠⡔⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣰⢿⣿⣿⣿⣿⣿⣿⣷⡆⢠⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⡏⣻⣟⣿⣿⡿⣟⣛⣿⡃⢸⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣧⣿⣾⣿⣷⣿⣷⣿⣿⣿⣷⣽⣹⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⡟⣟⣿⣿⠺⣟⣻⣿⣿⣿⡏⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⢿⡝⠻⠵⠿⠿⢿⣿⣿⢳⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣯⣧⠈⣛⣛⣿⣿⡿⣡⣞⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡧⠄⠙⠛⠛⢁⣴⣿⣿⣷⣿⢿⣿⣿⣿⣿⣿⣿⣿
// ⣿⣿⣿⣿⣿⣿⡿⠟⠉⠄⠄⢠⠄⣀⣠⣾⣿⣿⡿⠟⠁⠄⠈⠛⢿⣿⣿⣿⣿
// ⣿⣿⣿⣿⡟⠉⠄⠄⢀⠠⠐⠒⠐⠾⠿⢟⠋⠁⠄⢀⣀⠠⠐⠄⠂⠈⠻⢿⣿
// ⣿⣿⣿⠋⠁⠄⢀⡈⠄⠄⠄⠄⠄⠄⠄⠄⠁⠒⠉⠄⢠⣶⠄⠄⠄⠄⠄⠈⠫
// ⣿⣿⡟⠄⢔⠆⡀⠄⠈⢀⠄⠄⠄⠄⠄⠄⠄⢄⡀⠄⠈⡐⢠⠒⠄⠄⠄⠄⢀
// ⣿⣿⠁⡀⠄⠄⢇⠄⠄⢈⠆⠄⠄⢀⠔⠉⠁⠉⠉⠣⣖⠉⡂⡔⠂⠄⢀⠔⠁
// ⣿⡿⠄⠄⠄⠄⢰⠹⣗⣺⠤⠄⠰⡎⠄⠄⠄⠄⠄⠄⠘⢯⡶⢟⡠⠰⠄⠄
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
using type=ll;
#define taskname "table"
// for Orac
#define tasknamein "table"
#define tasknameout "table"
#define fi first
#define se second
#define sz(v) ((type)(v).size())
#define all(v) (v).begin(), (v).end()
typedef pair<type, type> ii;
typedef vector<ii> vii;
typedef vector<type> vi;
typedef vector<vector<type>> vvi;
//for FFT
using cd = complex<double>;
const double PI = acos(-1);
const type MN=3e5+10;
const type oo=1e18;
const type llmax=0x3f3f3f3f3f3f;
const type INF=1e9;
type n, a[MN], dp[MN], d;
vi lis;
void read() {
cin >> n >> d;
for(int i=0; i<n; i++) {
cin >> a[i];
}
}
void sol(){
//sub5
if(d==n) {
for (int i=0; i<n; ++i) {
type itr = lower_bound(all(lis), a[i]) - lis.begin();
if (itr == lis.size()) {
lis.push_back(a[i]);
}
else {
lis[itr] = a[i];
}
}
cout << lis.size() << endl;
}
//sub4
else if(d==1) {
type Max=0;
stack<type> st;
st.push(a[n-1]);
for(int i=n-2; i>=0; i--) {
while(st.size()>1 && st.top()<=a[i]) {
st.pop();
}
if(st.top()<=a[i]) {
st.pop();
}
st.push(a[i]);
Max=max(Max, (type) st.size());
}
cout << Max;
}
else {
for(int i=0; i<n; i++) {
dp[i]=1;
}
//cout << endl;
for(int i=n-2; i>=0; i--) {
type pos=min(i+d, n-1);
for(int j=i+1; j<=pos; j++) {
if(a[j]>a[i]) {
dp[i]=max(dp[i], dp[j]+1);
}
else {
pos=min(j+d, n-1);
}
}
}
type Max=0;
for(int i=0; i<n; i++) {
Max=max(dp[i], Max);
}
cout << Max;
}
}
signed main() {
//freopen(taskname".inp", "r", stdin);
//freopen(taskname".out", "w", stdout);
//for Orac
/*
ifstream in("tasknamein.txt");
ofstream out("tasknameout.txt");
*/
ios_base::sync_with_stdio(false);
cin.tie(NULL);
type t;
// cin >> t;
t=1;
while(t--) {
read();
sol();
}
}
Compilation message (stderr)
Main.cpp: In function 'void sol()':
Main.cpp:73:18: warning: comparison of integer expressions of different signedness: 'type' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
73 | if (itr == lis.size()) {
| ~~~~^~~~~~~~~~~~~
# | 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... |