Submission #1114981

#TimeUsernameProblemLanguageResultExecution timeMemory
1114981AdamGSFire (JOI20_ho_t5)C++17
0 / 100
13 ms3664 KiB
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Q{ int l, r, time, index; }; bool comp(const Q &q1, const Q &q2){ return q1.time<q2.time; } int tree[400'007]; void Update(int v, int l, int r, int vl, int vr, int val){ if (vl>r||vr<l) return; if (vl>=l&&vr<=r){ tree[v]=max(tree[v], val); return; } int mid=(vl+vr)/2; Update(v*2, l, r, vl, mid, val); Update(v*2+1, l, r, mid+1, vr, val); } int Get(int v){ int out=-1; while (v>0){ out=max(out, tree[v]); v/=2; } return out; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); for (int i=0;i<400'007;i++) tree[i]=-1; int n, q; cin>>n>>q; int trsize=1; while (trsize<n) trsize<<=1; for (int i=0;i<n;i++){ cin>>tree[trsize+i]; } vector<Q> qv(q); for (int i=0;i<q;i++){ cin>>qv[i].time>>qv[i].l>>qv[i].r; qv[i].index=i; } sort(qv.begin(), qv.end(), comp); int t=0; vector<int> out(q); for (Q qe:qv){ int tDiff=qe.time-t; t=qe.time; for (int i=n-tDiff-1;i>=0;i--){ Update(1, trsize+i, trsize+i+tDiff, trsize, trsize*2-1, Get(trsize+i)); } out[qe.index]=Get(trsize+qe.l-1); } for (int x:out) cout<<x<<'\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...