제출 #993071

#제출 시각아이디문제언어결과실행 시간메모리
993071serkanrashidHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
0 / 100
728 ms92244 KiB
#include <bits/stdc++.h> #define endl "\n" using namespace std; const int maxn = 1e6+5; int n,m; int w[maxn],bigidx[maxn]; int what[maxn],jump[maxn][20]; void pre() { int last = 0; for(int j = 0; j <= 20; j++) { int gr = min(n,(1<<(j+1))); for(int i = last + 1; i <= gr; i++) what[i] = j; last = gr; } for(int i = 1; i <= n; i++) jump[i][0] = w[i]; for(int j = 1; j <= 20; j++) { for(int i = 1; i <= n; i++) { jump[i][j] = max(jump[i][j-1],jump[jump[i][j-1]+1][j-1]); } } } int query(int l, int r) { int step = what[r-l+1]; return max(jump[l][step],jump[r-(1<<step)+1][step]); } bool check(int l, int r, int k) { int maxch,razmqna; maxch = razmqna = 0; for(int i = l; i < r; i = bigidx[i]) { maxch = w[i]; razmqna = max(razmqna,maxch+query(i+1,r)); } return k >= razmqna; } void read() { cin >> n >> m; pre(); for(int i = 1; i <= n; i++) cin >> w[i]; w[n+1] = 1e9+1; stack<int>s1; s1.push(n+1); for(int i = n; i >= 1; i--) { while(!s1.empty()&&w[s1.top()]<w[i]) s1.pop(); bigidx[i] = s1.top(); s1.push(i); } int l,r,k; for(int i = 1; i <= m; i++) { cin >> l >> r >> k; if(check(l,r,k)) cout << 1 << endl; else cout << 0 << endl; } } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); read(); 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...
#Verdict Execution timeMemoryGrader output
Fetching results...