이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma GCC optimization "O2"
#pragma GCC optimization "unroll-loop"
#pragma GCC target ("avx2")
#include <bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
using namespace std;
const ll N = 3e3 + 9;
const ll inf = 1e9 + 7;
typedef pair<ll,ll> LL;
vector<ll> v,g[N];
ll n,D,a[N],dp[N];
ll Find(ll x){
return lower_bound(v.begin(),v.end(),x) - v.begin() + 1;
}
void compress(){
sort(v.begin(),v.end()); v.resize(unique(v.begin(),v.end()) - v.begin());
for (ll i = 1;i <= n;i++) a[i] = Find(a[i]),g[a[i]].push_back(i);
for (ll i = 1;i <= n;i++) g[i].push_back(inf);
}
ll st[4*N];
void upd(ll id,ll l,ll r,ll u,ll val){
if (u < l||r < u) return;
if (l == r){
st[id] = val; return;
}
ll mid = (l + r)/2;
upd(id*2,l,mid,u,val); upd(id*2 + 1,mid + 1,r,u,val);
st[id] = max(st[id*2],st[id*2 + 1]);
}
ll Get(ll id,ll l,ll r,ll u,ll v){
if (v < l||r < u) return 0;
if (u <= l&&r <= v) return st[id];
ll mid = (l + r)/2;
return max(Get(id*2,l,mid,u,v),Get(id*2 + 1,mid + 1,r,u,v));
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
#define task "tst"
if (fopen(task".inp", "r")){
freopen(task".inp", "r", stdin);
//freopen(task".out", "w", stdout);
}
cin>>n>>D;
for (ll i = 1;i <= n;i++) cin>>a[i],v.push_back(a[i]);
memset(dp,1,sizeof(dp)); compress();
ll ans = 1; upd(1,1,n,a[1],1);
for (ll i = 2;i <= n;i++){
ll L = i - D - 1,now;
if (L > 0){
now = a[L];
ll nxt = *lower_bound(g[now].begin(),g[now].end(),L + 1);
if (nxt > i) upd(1,1,n,a[L],0);
}
dp[i] = Get(1,1,n,1,a[i] - 1) + 1; upd(1,1,n,a[i],dp[i]);
//cout<<i<<" "<<Get(1,1,n,1,a[i] - 1)<<"\n";
ans = max(ans,dp[i]);
}
cout<<ans;
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp:1: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
1 | #pragma GCC optimization "O2"
|
Main.cpp:2: warning: ignoring '#pragma GCC optimization' [-Wunknown-pragmas]
2 | #pragma GCC optimization "unroll-loop"
|
Main.cpp: In function 'int main()':
Main.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |