이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
Author : DeMen100ns (a.k.a Vo Khac Trieu)
School : VNU-HCM High school for the Gifted
fuck you adhoc
*/
#include <bits/stdc++.h>
using namespace std;
const int N = 3e5 + 5;
const long long INF = numeric_limits<long long>::max() / 2;
const int MAXA = 1e9;
const int B = sqrt(N) + 5;
int a[N];
struct segtree{
int seg[4 * N], lazy[4 * N];
segtree(){
fill(lazy + 1, lazy + 4 * N, -1);
}
void down(int id){
int t = lazy[id];
seg[id << 1] = seg[id << 1 | 1] = t;
lazy[id << 1] = lazy[id << 1 | 1] = t;
lazy[id] = -1;
}
void upd(int id, int l, int r, int u, int v, int val){
if (l > v || r < u) return;
if (l >= u && r <= v){
seg[id] = lazy[id] = val;
return;
}
if (lazy[id] != -1) down(id);
int mid = (l + r) >> 1;
upd(id << 1, l, mid, u, v, val);
upd(id << 1 | 1, mid + 1, r, u, v, val);
seg[id] = max(seg[id << 1], seg[id << 1 | 1]);
}
int get(int id, int l, int r, int u, int v){
if (l > v || r < u) return 0;
if (l >= u && r <= v) return seg[id];
if (lazy[id] != -1) down(id);
int mid = (l + r) >> 1;
int v1 = get(id << 1, l, mid, u, v);
int v2 = get(id << 1 | 1, mid + 1, r, u, v);
return max(v1, v2);
}
//note : day[1] <= day[2] <= ... <= day[n]
int getl(int id, int l, int r, int v){
if (l == r) return l;
if (lazy[id] != -1) down(id);
int mid = (l + r) >> 1;
if (seg[id << 1] < v){
return getl(id << 1 | 1, mid + 1, r, v);
} else {
return getl(id << 1, l, mid, v);
}
}
void dbgseg(int n){
for(int i = 1; i <= n; ++i){
cout << get(1, 1, n, i, i) << " ";
} cout << endl;
}
} day, dp, cur;
void cmp(int n){
vector <int> v;
for(int i = 1; i <= n; ++i) v.push_back(a[i]);
sort(v.begin(), v.end());
for(int i = 1; i <= n; ++i){
a[i] = lower_bound(v.begin(), v.end(), a[i]) - v.begin() + 1;
}
}
void solve()
{
int n, d; cin >> n >> d;
for(int i = 1; i <= n; ++i){
cin >> a[i];
}
cmp(n);
for(int i = 1; i <= n; ++i){
int ma = 0, k = n + 1;
k = day.getl(1, 1, n, i - d);
if (k < a[i]) ma = cur.get(1, 1, n, k, a[i] - 1);
day.upd(1, 1, n, a[i], n, i);
int val = cur.get(1, 1, n, a[i], a[i]);
val = max(val, ma + 1);
cur.upd(1, 1, n, a[i], a[i], val);
val = max(val, dp.get(1, 1, n, a[i], a[i]));
dp.upd(1, 1, n, a[i], a[i], val);
if (i - day.seg[1] >= d) k = n + 1;
else {
k = day.getl(1, 1, n, i - d + 1);
}
cur.upd(1, 1, n, 1, k - 1, 0);
/*day.dbgseg(n);
dp.dbgseg(n);
cur.dbgseg(n);
cout << "----------" << endl;*/
}
/*for(int i = 1; i <= n; ++i){
int ma = 0;
for(int j = 1; j < a[i]; ++j){
if (i - day[j] <= d){
ma = max(ma, cur[j]);
}
}
for(int j = a[i]; j <= n; ++j){
day[j] = i;
}
cur[a[i]] = max(cur[a[i]], ma + 1);
for(int j = 1; j <= n; ++j){
dp[j] = max(dp[j], cur[j]);
if (i - day[j] == d){
cur[j] = 0;
}
}
dbg(day, 1, n);
dbg(dp, 1, n);
dbg(cur, 1, n);
dbg("--------");
}*/
cout << dp.get(1, 1, n, a[n], n);
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("codeforces.inp","r",stdin);
// freopen("codeforces.out","w",stdout);
int t = 1; //cin >> t;
while (t--)
{
solve();
}
}
# | 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... |