Submission #242347

#TimeUsernameProblemLanguageResultExecution timeMemory
242347SomeoneUnknownTriple Jump (JOI19_jumps)C++14
19 / 100
3341 ms104064 KiB
#include <bits/stdc++.h> using namespace std; struct nodei{ int lo, hi, mid, val; int lazyclr; nodei *lft, *rght; nodei(int l, int h){ lo = l; hi = h; mid = (l+h)/2; val = 0; lazyclr = 0; if(h<l) exit(-1); if(l<h){ lft = new nodei(l, mid); rght = new nodei(mid+1, h); } } void propogate(){ //if(!lazyclr) return; //val = 0; if(lo<hi){ lft->lazyclr += lazyclr; rght->lazyclr += lazyclr; } val += lazyclr; lazyclr = 0; } int queryf(){ propogate(); if(lo == hi) return lo; lft->propogate(); rght->propogate(); if(lft->val < rght->val){ return rght->queryf(); }else{ return lft->queryf(); } } int queryr(int l, int h){ propogate(); if(l <= lo && h >= hi) return val; if(l > mid) return rght->queryr(l, h); if(h <= mid) return lft->queryr(l, h); return max(lft->queryr(l, h), rght->queryr(l, h)); } void update(int l, int h, int v){ propogate(); if(l <= lo && h >= hi){ lazyclr += v; return; } if(h > mid) rght->update(l, h, v); if(l <= mid) lft->update(l, h, v); lft->propogate(); rght->propogate(); val = max(lft->val, rght->val); } //write query! } *rootv, *rootc; int main(){ int n; scanf("%d", &n); rootv = new nodei(0, n-1); //rootc = new nodei(0, n-1); int firm[n]; for(int i = 0; i < n; ++i){ scanf("%d", &firm[i]); rootv->update(i, i, firm[i]); } int best[n][n]; for(int i = 0; i < n; i++){ for(int j = 0; j < n; j++){ best[i][j] = 0; if(j <= i+1){ continue; } int base = firm[i]+firm[j]; best[i][j] = rootv->queryr(i+1, (i+j)/2)+base; } } for(int i = n-2; i >= 0; i--){ for(int j = 1; j < n; j++){ best[i][j] = max(best[i][j], best[i+1][j]); best[i][j] = max(best[i][j], best[i][j-1]); } } int q; scanf("%d", &q); for(int i = 0; i < q; i++){ int a, c; scanf("%d %d", &a, &c); a--; c--; int cbest = best[a][c]; printf("%d\n", cbest); } }

Compilation message (stderr)

jumps.cpp: In function 'int main()':
jumps.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
jumps.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &firm[i]);
         ~~~~~^~~~~~~~~~~~~~~~
jumps.cpp:93:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &q);
     ~~~~~^~~~~~~~~~
jumps.cpp:96:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &c);
         ~~~~~^~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...