This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define fi first
#define se second
#define ssize(x) int(x.size())
#define pn printf("\n")
#define all(x) x.begin(),x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int inf = 2e09; ll infll = 2e18;
int base = 1;
struct seg{
vector<pii> t;
void init(int n){
while(base < n) base <<= 1;
t.resize(base<<1);
}
void update(int i, int val, int time){
t[i] = pii(val, time);
}
void zero(int l, int r, int time){
for(int i = l; i <= r; ++i) if(t[i].se < time) t[i] = pii(0, inf);
}
int query(int l, int r){
int ret = 0;
for(int i = l; i <= r; ++i) ret = max(t[i].fi, ret);
return ret;
}
void change_time(int l, int r, int time){
for(int i = l; i <= r; ++i) if(t[i].se < time) t[i].se = time;
}
};
void answer(){
int n, d; scanf("%d%d", &n, &d);
set<int> sc;
vector<int> t(n+1);
for(int i = 1; i <= n; ++i) scanf("%d", &t[i]), sc.emplace(t[i]);
unordered_map<int, int> mp; int it = 0;
for(int u : sc) mp[u] = ++it;
for(int i = 1; i <= n; ++i) t[i] = mp[t[i]];
seg seg; seg.init(n);
int result = 0;
for(int i = 1; i <= n; ++i){
int mn = inf, mn_time = 0;
for(int j = i-1; j >= max(1, i-d); --j) if(t[j] <= mn) mn = t[j], mn_time = j;
if(mn != inf) seg.zero(1, mn-1, i-d), seg.change_time(mn, base, mn_time);
if(i != n) seg.update(t[i], max(seg.query(1, t[i]-1)+1, seg.query(t[i], t[i])), i);
else result = max(seg.query(1, t[i]-1)+1, seg.query(t[i], base));
//~ for(int j = 1; j <= n; ++j) printf("%d %d, ", seg.t[j].fi, seg.t[j].se);
//~ pn;
}
printf("%d\n", result);
}
int main(){
int T = 1;
for(++T; --T; ) answer();
return 0;
}
Compilation message (stderr)
Main.cpp: In function 'void answer()':
Main.cpp:34:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | int n, d; scanf("%d%d", &n, &d);
| ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:37:36: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
37 | for(int i = 1; i <= n; ++i) scanf("%d", &t[i]), sc.emplace(t[i]);
| ~~~~~^~~~~~~~~~~~~
# | 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... |