Submission #137258

#TimeUsernameProblemLanguageResultExecution timeMemory
137258KLPPTriple Jump (JOI19_jumps)C++14
0 / 100
4016 ms45140 KiB
#include<bits/stdc++.h> using namespace std; typedef long long int lld; #define rep(i,a,b) for(int i=a;i<b;i++) #define trav(a,v) for(auto a:v) class ST{ lld tree[4000000]; public: void build(int a, int b, int node){ if(a==b){ tree[node]=0; return; } int mid=(a+b)/2; build(a,mid,2*node); build(mid+1,b,2*node+1); tree[node]=max(tree[node*2],tree[node*2+1]); } void update(int a, int b, int node, int pos, lld val){ if(pos<a || b<pos)return; if(a==b){ tree[node]=val; return; } int mid=(a+b)/2; update(a,mid,2*node,pos,val); update(mid+1,b,2*node+1,pos,val); tree[node]=max(tree[node*2],tree[node*2+1]); } lld query(int a, int b, int node, int x, int y){ if(x>y)return -100000000000; if(b<x || y<a)return -100000000000; if(x<=a && b<=y)return tree[node]; int mid=(a+b)/2; return max(query(a,mid,2*node,x,y),query(mid+1,b,2*node+1,x,y)); } }; int main(){ srand(time(NULL)); int n,q; scanf("%d",&n); lld arr[n]; rep(i,0,n){ scanf("%lld",&arr[i]); //arr[i]=rand()%100; } //scanf("%d",&q); ST *S=new ST(); S->build(0,n-1,1); rep(i,0,n)S->update(0,n-1,1,i,arr[i]); set<int> candidates; vector<int> V[n]; for(int i=n-1;i>-1;i--){ for(set<int>::iterator it=candidates.begin();it!=candidates.end();it++){ //cout<<a<<" "<<i<<" "<<S->query(0,n-1,1,i+1,a-1)<<endl; int a=*it; if(S->query(0,n-1,1,i+1,a-1)<min(arr[i],arr[a])){ V[i].push_back(a); } if(S->query(0,n-1,1,i+1,a-1)>arr[i]){ it=candidates.end(); it--; } } trav(a,candidates){ //cout<<a<<" "<<i<<" "<<S->query(0,n-1,1,i+1,a-1)<<endl; if(S->query(0,n-1,1,i+1,a-1)>=arr[a]){ candidates.erase(a); } } candidates.insert(i); } lld ans=0; rep(i,0,n){ trav(a,V[i]){ //cout<<a<<" "; ans=max(ans,arr[i]+arr[a]+S->query(0,n-1,1,2*a-i,n-1)); }//cout<<endl; } cout<<ans<<endl; /*lld ans2=0; rep(i,0,n){ rep(j,i+1,n){ rep(k,2*j-i,n){ ans2=max(ans2,arr[i]+arr[j]+arr[k]); } } } rep(i,0,n){ rep(j,i+1,n){ rep(k,2*j-i,n){ if(arr[i]+arr[j]+arr[k]==ans2)cout<<i<<" "<<j<<" "<<k<<endl; } } } cout<<ans2<<endl; if(ans!=ans2){ rep(i,0,n)cout<<arr[i]<<" "; cout<<endl; }*/ return 0; }

Compilation message (stderr)

jumps.cpp: In function 'int main()':
jumps.cpp:42:9: warning: unused variable 'q' [-Wunused-variable]
   int n,q;
         ^
jumps.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",&n);
   ~~~~~^~~~~~~~~
jumps.cpp:47:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&arr[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...