Submission #859264

#TimeUsernameProblemLanguageResultExecution timeMemory
859264nnhzzzTriple Jump (JOI19_jumps)C++14
5 / 100
4022 ms37204 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...