Submission #774240

#TimeUsernameProblemLanguageResultExecution timeMemory
774240NintsiChkhaidzeHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
2573 ms100388 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define s second #define f first #define pll pair <ll,ll> #define pii pair <int,int> #define left h*2,l,(l + r)/2 #define right h*2+1,(l + r)/2 + 1,r #define int ll using namespace std; const int N = 1e6 + 5,inf = 1e9; int a[N],le[N],ri[N],ans[N],k[N]; int t[4*N]; vector <int> v[N]; void upd(int h,int l,int r,int idx,int val){ if (l == r){ t[h] = max(t[h],val); return; } int mid = (l + r)/2; if (idx > mid) upd(right,idx,val); else upd(left,idx,val); t[h] = max(t[h*2],t[h*2 + 1]); } int get(int h,int l,int r,int L,int R){ if (r < L || R < l) return 0; if (L <= l && r <= R) return t[h]; return max(get(left,L,R),get(right,L,R)); } signed main() { ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL); int n,Q; cin>>n>>Q; for (int i = 1; i <= n; i++){ cin>>a[i]; } for (int i = 1; i <= Q; i++){ cin>>le[i]>>ri[i]>>k[i]; v[ri[i]].pb(i); } deque <int> dq; for (int i = 1; i <= n; i++){ while (dq.size() && a[dq.back()] <= a[i]){ dq.pop_back(); } if (dq.size()){ upd(1,1,n,dq.back(),a[i] + a[dq.back()]); } dq.pb(i); for (int id: v[i]){ if (get(1,1,n,le[id],i) <= k[id]) ans[id] = 1; } } for (int i = 1; i <= Q; i++) cout<<ans[i]<<endl; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...