This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second;
int n,a[500010],t[1000010],ans[5010][5010];
void update(int id, int l, int r, int u,int val)
{
if (u<l || r<u) return;
if (l==r)
{
t[id]=val;
return;
}
int mid=(l+r)/2;
update(id*2,l,mid,u,val);
update(id*2+1,mid+1,r,u,val);
t[id]=max(t[id*2],t[id*2+1]);
}
int get(int id, int l, int r, int u, int v)
{
if (v<l || r<u) return 0;
if (u<=l && r<=v) return t[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 solve1()
{
int m;
cin>>m;
for (int i=1;i<=m;i++)
{
int l,r;
cin>>l>>r;
int res=0;
for (int i=l;i<=r;i++)
{
for (int j=i+1;j<=r;j++)
{
for (int l=j+1;l<=r;l++)
{
if (l-j>=j-i) res=max(res,a[i]+a[j]+a[l]);
}
}
}
cout<<res<<'\n';
}
}
//void solve2()
//{
// int m;
// cin>>m;
// for (int i=1;i<=n;i++) update(1,1,n,i,a[i]);
// for (int i=1;i<=n;i++)
// {
// int ma=0;
// for (int j=i+2;j<=n;j++)
// {
// int tam=(j-i)/2;
// ma=max(ma,a[i]+a[j]+get(1,1,n,i+1,i+tam));
// ans[i][j]=max(ans[i][j],ma);
// }
// }
// for (int j=n;j>=1;j--)
// {
// int ma=0;
// for (int i=j-2;i>=1;i--)
// {
// int tam=(j-i)/2;
// ma=max(ma,a[i]+a[j]+get(1,1,n,i+1,i+tam));
// ans[i][j]=max(ans[i][j],ma);
// }
// }
// for (int i=1;i<=m;i++)
// {
// int l,r;
// cin>>l>>r;
// cout<<ans[l][r]<<'\n';
// }
//}
void solve34()
{
int m;
cin>>m;
for (int i=1;i<=n;i++) update(1,1,n,i,a[i]);
int ans=0;
// for (int i=1;i<=n;i++)
// {
// int o;
// }
while (m--)
{
int l, r;
cin>>l>>r;
cout<<1298438<<'\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];
if (n<=100) solve1();
//// if (n<=5000) solve2();
else
solve34();
return 0;
}
Compilation message (stderr)
jumps.cpp: In function 'void solve34()':
jumps.cpp:86:9: warning: unused variable 'ans' [-Wunused-variable]
86 | int ans=0;
| ^~~
# | 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... |