이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define LL long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
int main()
{
LL n,x;
scanf("%lld %lld",&n,&x);
LL arr[n+5];
for(LL a=1;a<=n;a++)
{
scanf("%lld",&arr[a]);
}
vector<LL>lis,lds;
LL pref[n+5],suff[n+5];
for(LL a=1;a<=n;a++)
{
// printf("a=%lld\n",a);
if(lower_bound(lis.begin(),lis.end(),arr[a])!=lis.end())
{
lis[lower_bound(lis.begin(),lis.end(),arr[a])-lis.begin()]=arr[a];
}
else
{
lis.push_back(arr[a]);
}
pref[a]=lower_bound(lis.begin(),lis.end(),arr[a])-lis.begin()+1;
// printf("pref[%lld]=%lld\n",a,pref[a]);
}
// printf("DOR\n");
for(LL a=n;a>=1;a--)
{
// printf("a=%lld\n",a);
if(lower_bound(lds.begin(),lds.end(),-arr[a])!=lds.end())
{
lds[lower_bound(lds.begin(),lds.end(),-arr[a])-lds.begin()]=-arr[a];
}
else
{
lds.push_back(-arr[a]);
}
suff[a]=lower_bound(lds.begin(),lds.end(),-arr[a])-lds.begin()+1;
//printf("suff[%lld]=%lld\n",a,suff[a]);
}
// for(LL a=1;a<=n;a++)printf("%lld ",pref[a]);
// printf("\n");
// for(LL a=n;a>=1;a--)printf("%lld ",suff[a]);
// printf("\n");
LL maks=pref[n];
set<pair<LL,LL>>s;
// t dan lds nya
s.insert(mp(arr[n],suff[n]));
for(LL a=n-1;a>=1;a--)
{
// jika t nya lebih besar maka hasilnya semakin kecil
auto ambil = s.lower_bound(mp(arr[a]-x+1,0));
if(ambil==s.end())maks=max(maks,pref[a]);
else
{
pair<LL,LL>x=*ambil;
maks=max(maks,pref[a]+x.se);
}
while(s.lower_bound(mp(arr[a],1e9))!=s.begin())
{
auto koko=--s.lower_bound(mp(arr[a],1e9));
pair<LL,LL>jeje=*koko;
if(jeje.second<=suff[a])
{
s.erase(jeje);
}else break;
}
auto jeje=*s.lower_bound(mp(arr[a]-1,1e9));
if(!s.empty() && jeje.second>=suff[a])
{
}else s.insert(mp(arr[a],suff[a]));
}
printf("%lld\n",maks);
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | scanf("%lld %lld",&n,&x);
| ~~~~~^~~~~~~~~~~~~~~~~~~
glo.cpp:14:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | scanf("%lld",&arr[a]);
| ~~~~~^~~~~~~~~~~~~~~~
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |