Submission #714415

#TimeUsernameProblemLanguageResultExecution timeMemory
714415ln_eGlobal Warming (CEOI18_glo)C++17
100 / 100
780 ms42892 KiB
#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][400005]; map<ll,ll>val; void update1(ll pos,ll val){ for(;pos<=2*n+1;pos+=pos&(-pos)){ tree[1][pos]=max(tree[1][pos],val); } } void update2(ll pos,ll val){ for(;pos<=2*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; vector<ll>v; v.pb(x); for(ll i=1;i<=n;i++) { cin>>a[i]; v.pb(a[i]); v.pb(a[i]+x-1); } 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; dp[i][1]=max(dp[i][1],query1(val[a[i]+x-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; }

Compilation message (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++)
      |            ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...