Submission #1096265

#TimeUsernameProblemLanguageResultExecution timeMemory
1096265trinhvtuanTriple Jump (JOI19_jumps)C++17
5 / 100
4041 ms7708 KiB
#include <bits/stdc++.h> using namespace std; long long c,d,x,y,z,n,q,l,r,kq; int i,j,k; long long st[2000005],a[1000001]; void buildtree(int id,int l,int r) { if (l==r) { st[id]=a[l]; return; } int mid=(l+r)/2; buildtree(id*2,l,mid); buildtree(id*2+1,mid+1,r); st[id]=max(st[id*2],st[id*2+1]); } long long get(int id,int l,int r,int u,int v) { if (v<l || r<u) return 0; if (u<=l && r<=v) return st[id]; int mid=(l+r)/2; return max(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v)); } void sub1() { buildtree(1,1,n); for (int i=1;i<=q;i++) { cin>>l>>r; kq=0; for (int j=l+1;j<r;j++) { for (int k=l;k<j;k++) { z=j-k+j; if (z<=r) { c=a[k]+a[j]+get(1,1,n,z,r); kq=max(kq,c); } } } cout<<kq<<"\n"; } } int main() { //freopen("chonqua.inp", "r" ,stdin); //freopen("chonqua.out", "w" ,stdout); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin>>n; for (int i=1;i<=n;i++) { cin>>a[i]; } cin>>q; sub1(); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...