Submission #1103936

#TimeUsernameProblemLanguageResultExecution timeMemory
1103936ntminTriple Jump (JOI19_jumps)C++14
19 / 100
279 ms116260 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> pii; #define ON(a, b) (a >> b & 1) #define all(x) x.begin(), x.end() template<typename T> bool maximise(T &a, T b){if(a < b){a = b; return 1;} return 0;} template<typename T> bool minimise(T &a, T b){if(a > b){a = b; return 1;} return 0;} const int N = 5e5 + 1; int a[N], n, q; pii st[19][N]; const int M = 5010; int maxx[M][M]; void sub1(){ auto getmax = [&](int l, int r) -> int { int k = __lg(r - l + 1); return max(st[k][l].first, st[k][r - (1 << k) + 1].first); }; for(int i = 1; i <= n; ++i){ for(int j = i + 2; j <= n; ++j){ maxx[i][j] = a[i] + a[j] + getmax(i + 1, i + ((j - i + 1) / 2 - ((j - i + 1) % 2 == 0))); } } for(int i = n; i >= 1; --i){ for(int j = i + 1; j <= n; ++j){ maximise(maxx[i][j], max({maxx[i + 1][j], maxx[i][j - 1], maxx[i + 1][j - 1]})); } } int q; cin >> q; while(q--){ int l, r; cin >> l >> r; cout << maxx[l][r] << '\n'; } } void sub2(){ priority_queue<pair<int, int>> q; for(int i = 1; i <= n; ++i){ } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen("tjump.INP", "r")){ freopen("tjump.INP", "r", stdin); freopen("tjump.OUT", "w", stdout); } cin >> n; for(int i = 1; i <= n; ++i){ cin >> a[i]; st[0][i] = {a[i], i}; } for(int k = 1; k < 19; ++k){ for(int i = 1; i + (1 << k) - 1 <= n; ++i){ st[k][i] = max(st[k - 1][i], st[k - 1][i + (1 << (k - 1))]); } } if(n <= 5000) sub1(); else sub2(); return 0; }

Compilation message (stderr)

jumps.cpp: In function 'int main()':
jumps.cpp:55:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |         freopen("tjump.INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
jumps.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen("tjump.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...