Submission #150948

#TimeUsernameProblemLanguageResultExecution timeMemory
150948usernameTriple Jump (JOI19_jumps)C++14
27 / 100
226 ms17636 KiB
#pragma GCC optimize("O3") #include<ext/pb_ds/assoc_container.hpp> #include<ext/pb_ds/tree_policy.hpp> #include<ext/rope> using namespace __gnu_pbds; using namespace __gnu_cxx; #define VIS(it,con) for(auto it=con.begin();it!=con.end();++it) #define pob pop_back #define pf push_front #define pof pop_front #define MIN(x,y) (x=min(x,(y))) #define MAX(x,y) (x=max(x,(y))) #define mid (l+r>>1) #define lch (idx*2+1) #define rch (idx*2+2) /*****************************************************************************/ #include<bits/stdc++.h> //#define int int_fast64_t using namespace std; typedef pair<int,int> pii; #define REP(i,j,k) for(register int i=(j);i<(k);++i) #define RREP(i,j,k) for(register int i=int(j)-1;i>=(k);--i) #define ALL(a) a.begin(),a.end() #define pb push_back #define f first #define s second #define endl '\n' #define __debug #ifdef __debug #define IOS (void)0 #define de(...) cerr<<__VA_ARGS__ #define ar(a,s,t) {REP(__i,s,t)de(a[__i]<<' ');de(endl);} #else #define IOS cin.tie(0),cout.tie(0),ios_base::sync_with_stdio(false) #define de(...) (void)0 #define ar(...) (void)0 #endif /***********************************default***********************************/ const int maxn=5e5+9,lg=19,inf=1e9; int n,q,res=0,a[maxn],b[maxn],sp[lg][maxn]; int qr(int l,int r){ if(l==r)return -inf; int k=__lg(r-l); return max(sp[k][l],sp[k][r-(1<<k)]); } main(){ IOS; cin>>n; REP(i,0,n)cin>>a[i],b[i]=i,sp[0][i]=a[i]; cin>>q; sort(b,b+n,[](int x,int y){return a[x]>a[y];}); REP(i,1,lg)REP(j,0,n)if(j+(1<<i-1)<n)sp[i][j]=max(sp[i-1][j],sp[i-1][j+(1<<i-1)]); REP(_,0,min(n,lg)){ REP(j,0,n){ int p=b[_],q=j; if(p==q)continue; if(p>q)swap(p,q); MAX(res,a[p]+a[q]+max({qr(max(0,2*p-q),p),qr(p+1,(p+q+1)/2),qr(min(n,2*q-p),n)})); } } cout<<res<<endl; }

Compilation message (stderr)

jumps.cpp:48:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
jumps.cpp: In function 'int main()':
jumps.cpp:54:33: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
  REP(i,1,lg)REP(j,0,n)if(j+(1<<i-1)<n)sp[i][j]=max(sp[i-1][j],sp[i-1][j+(1<<i-1)]);
                                ~^~
jumps.cpp:54:78: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
  REP(i,1,lg)REP(j,0,n)if(j+(1<<i-1)<n)sp[i][j]=max(sp[i-1][j],sp[i-1][j+(1<<i-1)]);
                                                                             ~^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...