Submission #555775

#TimeUsernameProblemLanguageResultExecution timeMemory
555775ngpin04Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
1046 ms134936 KiB
#include <bits/stdc++.h> #define fi first #define se second #define mp make_pair #define TASK "" #define ALL(x) (x).begin(), (x).end() using namespace std; template <typename T1, typename T2> bool mini(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maxi(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } const int N = 1e6 + 5; const int oo = 1e9; const long long ooo = 1e18; const int mod = 1e9 + 7; // 998244353; const long double pi = acos(-1); vector <int> ind[N]; vector <int> qr[N]; int bit[N]; int ans[N]; int a[N]; int r[N]; int w[N]; int n,q; void update(int pos, int val) { for (; pos <= n; pos += pos & -pos) maxi(bit[pos], val); } int getmax(int pos) { int res = 0; for (; pos; pos -= pos & -pos) maxi(res, bit[pos]); return res; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); #ifdef ONLINE_JUDGE // freopen(TASK".inp","r",stdin); // freopen(TASK".out","w",stdout); #endif cin >> n >> q; for (int i = 1; i <= n; i++) cin >> a[i]; for (int i = 1; i <= q; i++) { int l; cin >> l >> r[i] >> w[i]; qr[l].push_back(i); } a[0] = 2 * oo; vector <int> s(1, 0); for (int i = 1; i <= n; i++) { while (s.size() && a[i] >= a[s.back()]) s.pop_back(); ind[s.back()].push_back(i); s.push_back(i); } for (int i = n; i >= 1; i--) { for (int j : ind[i]) update(j, a[i] + a[j]); for (int id : qr[i]) ans[id] = (getmax(r[id]) <= w[id]); } for (int i = 1; i <= q; i++) cout << ans[i] << "\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...
#Verdict Execution timeMemoryGrader output
Fetching results...