이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
using namespace std;
int n,x,b[200001],pod=1,a[200001];
int drze[1000001][2];
unordered_map<int,int>skal;
void aktu(int gdzie,int kd,int naile)
{
while(gdzie)
{
drze[gdzie][kd]=max(drze[gdzie][kd],naile);
gdzie>>=1;
}
}
int maxnapref(int ter,int pocz,int kon,int dokad,int kd)
{
if(a[kon]<=dokad)
{
return drze[ter][kd];
}
if(a[(pocz+kon)/2+1]<=dokad)
return max(drze[ter<<1][kd],maxnapref((ter<<1)^1,(pocz+kon)/2+1,kon,dokad,kd));
else if(a[pocz]<=dokad)
return maxnapref(ter<<1,pocz,(pocz+kon)>>1,dokad,kd);
return 0;
}
int main()
{
scanf("%d%d",&n,&x);
while(pod<n)
pod<<=1;
for(int i=0;i<n;++i)
{
scanf("%d",&a[i]);
b[i]=a[i];
}
sort(a,a+n);
for(int i=0;i<n;++i)
skal[a[i]]=i;
for(int i=n;i<pod;++i)
a[i]=INT_MAX;
int w1,w2;
for(int i=0;i<n;++i)
{
w1=maxnapref(1,0,pod-1,b[i]-1,0)+1;
w2=max(maxnapref(1,0,pod-1,b[i]-1,1),maxnapref(1,0,pod-1,b[i]+x-1,0))+1;
aktu(skal[b[i]]+pod,0,w1);
aktu(skal[b[i]]+pod,1,w2);
}
printf("%d",max(drze[1][0],drze[1][1]));
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int main()':
glo.cpp:28:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
28 | scanf("%d%d",&n,&x);
| ~~~~~^~~~~~~~~~~~~~
glo.cpp:33:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%d",&a[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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |