# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
859264 |
2023-10-10T02:48:57 Z |
nnhzzz |
Triple Jump (JOI19_jumps) |
C++14 |
|
4000 ms |
37204 KB |
#include<bits/stdc++.h>
using namespace std;
#define task "test"
#define REP(i,a,b) for(int i = (a); i<=(b); ++i)
#define REPD(i,a,b) for(int i = (a); i>=(b); --i)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) (int)(x).size()
#define BIT(x,i) ((x>>i)&1LL)
#define MASK(i) (1LL<<i)
#define fi first
#define se second
#define vi vector<int>
#define pii pair<int,int>
//-----------------------------------------------------------------------//
const int oo = 1e9,LOG = 19,MAXN = 5e5+7,N = 1e2+3;
const int MOD = 1e9+7,MOD1 = 1e9+207,MOD2 = 1e9+407,MOD3 = 998244353;
//-----------------------------------------------------------------------//
template<typename T> bool mini(T &a, T b){if(a>b){a=b;return true;} return false;}
template<typename T> bool maxi(T &a, T b){if(a<b){a=b;return true;} return false;}
int a[MAXN],f[MAXN][LOG];
int n,q;
int get(int l, int r){
int k = __lg(r-l+1);
return max(f[l][k],f[r-MASK(k)+1][k]);
}
void sub1(){
while(q--){
int res = 0,l,r; cin >> l >> r;
REP(i,l,r){
REP(j,i+1,r){
int k = j+j-i;
if(k>r) break;
maxi(res,a[i]+a[j]+get(k,r));
}
}
cout << res << "\n";
}
}
void sub2(){
cout << 0;
}
void sub3(){
while(q--){
int res = 0,l,r; cin >> l >> r;
stack<int> st; vi dp(n+3,0);
REP(i,l,r){
while(SZ(st)!=0 && a[st.top()]<a[i]){
maxi(dp[2*i-st.top()],a[i]+a[st.top()]);
st.pop();
}
if(SZ(st)!=0) maxi(dp[2*i-st.top()],a[i]+a[st.top()]);
st.push(i);
}
REP(i,l,r){
maxi(dp[i],dp[i-1]);
maxi(res,dp[i]+a[i]);
}
cout << res << "\n";
}
}
void solve(){
cin >> n;
REP(i,1,n){
cin >> a[i];
f[i][0] = a[i];
}
REP(j,1,LOG-1){
REP(i,1,n){
f[i][j] = max(f[i][j-1],f[i+MASK(j-1)][j-1]);
}
}
cin >> q;
if(n<=100 && q<=100){
sub1(); return ;
}
sub3();
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if(fopen(task".inp","r")){
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
solve();
return 0;
}
Compilation message
jumps.cpp: In function 'void solve()':
jumps.cpp:77:47: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
77 | f[i][j] = max(f[i][j-1],f[i+MASK(j-1)][j-1]);
| ~^~
jumps.cpp:11:23: note: in definition of macro 'MASK'
11 | #define MASK(i) (1LL<<i)
| ^
jumps.cpp: In function 'int main()':
jumps.cpp:91:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
91 | freopen(task".inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
jumps.cpp:92:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
92 | freopen(task".out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Execution timed out |
4022 ms |
4368 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
53 ms |
37204 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
2 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Execution timed out |
4022 ms |
4368 KB |
Time limit exceeded |
12 |
Halted |
0 ms |
0 KB |
- |