이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho
using ll=long long;
using ld=long double;
int const INF=1000000005;
ll const LINF=1000000000000000005;
ll const mod=1000000007;
ld const PI=3.14159265359;
ll const MAX_N=3e5+5;
ld const EPS=0.00000001;
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define sz(a) (int)a.size()
#define CODE_START ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,a[2000005],dp[2000005][3],x,tree[3][200005];
map<ll,ll>val;
void update1(ll pos,ll val){
for(;pos<=n+1;pos+=pos&(-pos)){
tree[1][pos]=max(tree[1][pos],val);
}
}
void update2(ll pos,ll val){
for(;pos<=n+1;pos+=pos&(-pos)){
tree[2][pos]=max(tree[2][pos],val);
}
}
ll query1(ll pos){
ll res=0;
for(;pos;pos-=pos&(-pos)){
res=max(res,tree[1][pos]);
}
return res;
}
ll query2(ll pos){
ll res=0;
for(;pos;pos-=pos&(-pos)){
res=max(res,tree[2][pos]);
}
return res;
}
int32_t main(){
CODE_START;
#ifdef LOCAL
ifstream cin("input.txt");
#endif
cin>>n>>x;
if(x==1e9){
vector<ll>v;
v.pb(x);
for(ll i=1;i<=n;i++)
{
cin>>a[i];
v.pb(a[i]);
}
sort(v.begin(),v.end());
ll vl=0;
for(ll i=0;i<v.size();i++)
{
if(i==0||v[i]!=v[i-1]){
val[v[i]]=++vl;
}
}
for(ll i=1;i<=n;i++)
{
dp[i][0]=query1(val[a[i]]-1)+1;
dp[i][1]=max(query1(val[a[i]]-1)+1,query2(val[a[i]]-1)+1);
dp[i][1]=max(dp[i][1],query1(n+1)+1);
update1(val[a[i]],dp[i][0]);
update2(val[a[i]],dp[i][1]);
}
ll ans=0;
for(ll i=1;i<=n;i++)
{
ans=max(ans,dp[i][0]);
ans=max(ans,dp[i][1]);
}
cout<<ans<<endl;
}else if(x==0){
vector<ll>v;
v.pb(x);
for(ll i=1;i<=n;i++)
{
cin>>a[i];
v.pb(a[i]);
}
sort(v.begin(),v.end());
ll vl=0;
for(ll i=0;i<v.size();i++)
{
if(i==0||v[i]!=v[i-1]){
val[v[i]]=++vl;
}
}
for(ll i=1;i<=n;i++)
{
dp[i][0]=query1(val[a[i]]-1)+1;
dp[i][1]=max(query1(val[a[i]]-1)+1,query2(val[a[i]]-1)+1);
update1(val[a[i]],dp[i][0]);
update2(val[a[i]],dp[i][1]);
}
ll ans=0;
for(ll i=1;i<=n;i++)
{
ans=max(ans,dp[i][0]);
ans=max(ans,dp[i][1]);
}
cout<<ans<<endl;
}else {
vector<ll>v;
v.pb(x);
for(ll i=1;i<=n;i++)
{
cin>>a[i];
v.pb(a[i]);
}
sort(v.begin(),v.end());
ll vl=0;
for(ll i=0;i<v.size();i++)
{
if(i==0||v[i]!=v[i-1]){
val[v[i]]=++vl;
}
}
for(ll i=1;i<=n;i++)
{
dp[i][0]=query1(val[a[i]]-1)+1;
dp[i][1]=query2(val[a[i]]-1)+1;
for(ll j=1;j<i;j++)
{
if(a[j]>a[i]&&a[j]-x<a[i]){
dp[i][1]=max(dp[i][1],dp[j][0]+1);
}
}
update1(val[a[i]],dp[i][0]);
update2(val[a[i]],dp[i][1]);
}
ll ans=0;
for(ll i=1;i<=n;i++)
{
ans=max(ans,dp[i][0]);
ans=max(ans,dp[i][1]);
}
cout<<ans<<endl;
}
}
컴파일 시 표준 에러 (stderr) 메시지
glo.cpp: In function 'int32_t main()':
glo.cpp:62:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(ll i=0;i<v.size();i++)
| ~^~~~~~~~~
glo.cpp:93:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
93 | for(ll i=0;i<v.size();i++)
| ~^~~~~~~~~
glo.cpp:123:13: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
123 | for(ll i=0;i<v.size();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... |