This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
/*
// is short or still long ???
hollwo_pelw's template(short)
// Note : -Dhollwo_pelw_local
*/
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/trie_policy.hpp>
// #include <ext/rope>
using namespace std;
// using namespace __gnu_pbds;
// using namespace __gnu_cxx;
void FAST_IO(string filein = "", string fileout = "", string fileerr = ""){
if (fopen(filein.c_str(), "r")){
freopen(filein.c_str(), "r", stdin);
freopen(fileout.c_str(), "w", stdout);
#ifdef hollwo_pelw_local
freopen(fileerr.c_str(), "w", stderr);
#endif
}
cin.tie(0), cout.tie(0) -> sync_with_stdio(0);
}
void Hollwo_Pelw();
signed main(){
#ifdef hollwo_pelw_local
FAST_IO("input.inp", "output.out", "error.err");
auto start = chrono::steady_clock::now();
#else
FAST_IO("JOI21_financial.inp", "JOI21_financial.out");
#endif
int testcases = 1;
// cin >> testcases;
for (int test = 1; test <= testcases; test++){
// cout << "Case #" << test << ": ";
Hollwo_Pelw();
}
#ifdef hollwo_pelw_local
auto end = chrono::steady_clock::now();
cout << "\nExcution time : " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl;
#endif
return 0;
}
const int N = 3e5 + 5;
int n, d, a[N], ord[N], st[N << 2], sz = 1;
set<pair<int, int>> ranges; // >= d
inline void del_pos(int p) {
auto it = ranges.upper_bound({p, n});
if (it == ranges.begin()) return ;
if ((--it) -> second < p) return ;
ranges.erase(it);
int l = it -> first, r = it -> second;
if (p - l >= d) ranges.emplace(l, p - 1);
if (r - p >= d) ranges.emplace(p + 1, r);
}
inline int get_pos(int p) {
auto it = ranges.upper_bound({p, p});
if (it == ranges.begin())
return 0;
return (-- it) -> second + 1;
}
inline void update(int p, int v) {
for (st[p += sz] = v; p >>= 1; )
st[p] = max(st[p << 1], st[p << 1 | 1]);
}
inline int query(int l, int r) {
int res = 0;
for (l += sz, r += sz; l < r; l >>= 1, r >>= 1) {
if (l & 1) res = max(res, st[l ++]);
if (r & 1) res = max(res, st[-- r]);
}
return res;
}
void Hollwo_Pelw() {
cin >> n >> d;
for (int i = 1; i <= n; i++)
cin >> a[i];
ranges.emplace(1, n);
while (sz <= n) sz <<= 1;
iota(ord + 1, ord + n + 1, 1);
sort(ord + 1, ord + n + 1, [](const int &x, const int &y) {
return a[x] == a[y] ? x > y : a[x] < a[y];
});
for (int _ = 1; _ <= n; _++) {
int p = ord[_];
del_pos(p);
int val = query(get_pos(p), p) + 1;
update(p, val);
}
cout << st[1];
}
Compilation message (stderr)
Main.cpp: In function 'void FAST_IO(std::string, std::string, std::string)':
Main.cpp:18:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | freopen(filein.c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
19 | freopen(fileout.c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |