Submission #808648

#TimeUsernameProblemLanguageResultExecution timeMemory
808648oscar1fTriple Jump (JOI19_jumps)C++17
27 / 100
42 ms10244 KiB
#include<bits/stdc++.h> using namespace std; #define int long long const int MAX_VAL=500*1000+5,INFINI=1000*1000*1000; int nbVal,nbReq,debReq,finReq,idReq,posRep,debInter,midInter,ancPos; int val[MAX_VAL]; int maxi[MAX_VAL]; int rep[MAX_VAL]; vector<int> enCours; vector<pair<int,int>> paireInter; vector<tuple<int,int,int>> listeReq; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); cin>>nbVal; for (int i=1;i<=nbVal;i++) { cin>>val[i]; } enCours.push_back(1); for (int i=2;i<=nbVal;i++) { while (!enCours.empty() and val[enCours.back()]<=val[i]) { if (nbVal-i>=i-enCours.back()) { paireInter.push_back({enCours.back(),i}); } enCours.pop_back(); } if (!enCours.empty()) { if (nbVal-i>=i-enCours.back()) { paireInter.push_back({enCours.back(),i}); } } enCours.push_back(i); } sort(paireInter.begin(),paireInter.end()); /*for (auto i:paireInter) { cout<<i.first<<" "<<i.second<<endl; } cout<<endl;*/ cin>>nbReq; for (int ireq=1;ireq<=nbReq;ireq++) { cin>>debReq>>finReq; listeReq.push_back(make_tuple(debReq,finReq,ireq)); } sort(listeReq.begin(),listeReq.end()); for (auto r:listeReq) { debReq=get<0>(r); finReq=get<1>(r); idReq=get<2>(r); maxi[finReq+1]=0; for (int i=finReq;i>=debReq;i--) { maxi[i]=max(maxi[i+1],val[i]); } for (int i=0;i<(int)paireInter.size();i++) { debInter=paireInter[i].first; midInter=paireInter[i].second; if (debInter>=debReq and 2*midInter-debInter<=finReq and rep[idReq]<val[debInter]+val[midInter]+maxi[2*midInter-debInter]) { rep[idReq]=val[debInter]+val[midInter]+maxi[2*midInter-debInter]; posRep=i; } } if (posRep<ancPos) { exit(1); } ancPos=posRep; //cout<<posRep<<" "; } //cout<<endl; for (int ireq=1;ireq<=nbReq;ireq++) { cout<<rep[ireq]<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...