#include <bits/stdc++.h>
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
const int INF = 1e9;
const int mod = 998244353;
const int N = 200005;
int sp[N][20];
int get(int l, int r){
int lg = __lg(r - l + 1);
return max(sp[l][lg], sp[r - (1ll << lg) + 1][lg]);
}
void solve(){
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < n; i++){
sp[i][0] = a[i];
}
for(int i = 1; i < 20; i++){
for(int j = 0; j < n; j++){
sp[j][i] = max(sp[j][i - 1], sp[min(n - 1, j + (1ll << (i - 1)))][i - 1]);
}
}
int q;
cin >> q;
while(q--){
int l, r;
cin >> l >> r;
l--;
r--;
int mx = get(l, r), pos = l;
for(int i = r; i >= l; i--){
if(a[i] == mx){
pos = i;
break;
}
}
int ans = 0;
for(int i = l; i < pos; i++){
if(i != l) ans = max(ans, a[pos] + a[i] + get(max(l, i - (pos - i)), i - 1));
if(pos + (pos - i) <= r) ans = max(ans, a[pos] + a[i] + get(pos + (pos - i), r));
}
for(int i = pos + 1; i < r; i++){
if(i + (i - pos) <= r) ans = max(ans, a[pos] + a[i] + get(i + (i - pos), r));
else break;#include <bits/stdc++.h>
#define int long long
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
const int INF = 1e9;
const int mod = 998244353;
const int N = 200005;
int sp[N][20];
int get(int l, int r){
int lg = __lg(r - l + 1);
return max(sp[l][lg], sp[r - (1ll << lg) + 1][lg]);
}
void solve(){
int n;
cin >> n;
vector<int> a(n);
for(int i = 0; i < n; i++){
cin >> a[i];
}
for(int i = 0; i < n; i++){
sp[i][0] = a[i];
}
for(int i = 1; i < 20; i++){
for(int j = 0; j < n; j++){
sp[j][i] = max(sp[j][i - 1], sp[min(n - 1, j + (1ll << (i - 1)))][i - 1]);
}
}
int q;
cin >> q;
while(q--){
int l, r;
cin >> l >> r;
l--;
r--;
int mx = get(l, r), pos = l;
for(int i = r; i >= l; i--){
if(a[i] == mx){
pos = i;
break;
}
}
int ans = 0;
for(int i = l; i < pos; i++){
if(i != l) ans = max(ans, a[pos] + a[i] + get(max(l, i - (pos - i)), i - 1));
if(pos + (pos - i) <= r) ans = max(ans, a[pos] + a[i] + get(pos + (pos - i), r));
}
for(int i = pos + 1; i < r; i++){
if(i + (i - pos) <= r) ans = max(ans, a[pos] + a[i] + get(i + (i - pos), r));
else break;
}
for(int i = l; i <= r; i++){
if(a[i] == mx){
pos = i;
break;
}
}
for(int i = l; i < pos; i++){
if(i != l) ans = max(ans, a[pos] + a[i] + get(max(l, i - (pos - i)), i - 1));
if(pos + (pos - i) <= r) ans = max(ans, a[pos] + a[i] + get(pos + (pos - i), r));
}
for(int i = pos + 1; i < r; i++){
if(i + (i - pos) <= r) ans = max(ans, a[pos] + a[i] + get(i + (i - pos), r));
else break;
}
cout << ans << '\n';
}
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
}
for(int i = l; i <= r; i++){
if(a[i] == mx){
pos = i;
break;
}
}
for(int i = l; i < pos; i++){
if(i != l) ans = max(ans, a[pos] + a[i] + get(max(l, i - (pos - i)), i - 1));
if(pos + (pos - i) <= r) ans = max(ans, a[pos] + a[i] + get(pos + (pos - i), r));
}
for(int i = pos + 1; i < r; i++){
if(i + (i - pos) <= r) ans = max(ans, a[pos] + a[i] + get(i + (i - pos), r));
else break;
}
cout << ans << '\n';
}
}
main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
Compilation message
jumps.cpp:56:15: error: stray '#' in program
56 | else break;#include <bits/stdc++.h>
| ^
jumps.cpp: In function 'void solve()':
jumps.cpp:56:4: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
56 | else break;#include <bits/stdc++.h>
| ^~~~
jumps.cpp:56:16: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
56 | else break;#include <bits/stdc++.h>
| ^~~~~~~
jumps.cpp:56:16: error: 'include' was not declared in this scope
jumps.cpp:56:25: error: 'bits' was not declared in this scope
56 | else break;#include <bits/stdc++.h>
| ^~~~
jumps.cpp:56:30: error: 'stdc' was not declared in this scope; did you mean 'std'?
56 | else break;#include <bits/stdc++.h>
| ^~~~
| std
jumps.cpp:62:1: error: expected primary-expression before 'using'
62 | using namespace std;
| ^~~~~
jumps.cpp:69:22: error: a function-definition is not allowed here before '{' token
69 | int get(int l, int r){
| ^
jumps.cpp:74:13: error: a function-definition is not allowed here before '{' token
74 | void solve(){
| ^
jumps.cpp:134:1: error: 'main' was not declared in this scope
134 | main(){
| ^~~~
jumps.cpp:64:11: warning: unused variable 'INF' [-Wunused-variable]
64 | const int INF = 1e9;
| ^~~
jumps.cpp:65:11: warning: unused variable 'mod' [-Wunused-variable]
65 | const int mod = 998244353;
| ^~~
jumps.cpp:67:5: warning: unused variable 'sp' [-Wunused-variable]
67 | int sp[N][20];
| ^~
jumps.cpp: At global scope:
jumps.cpp:168:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
168 | main(){
| ^~~~