Submission #910536

#TimeUsernameProblemLanguageResultExecution timeMemory
910536daoquanglinh2007Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
835 ms93688 KiB
#include <bits/stdc++.h> using namespace std; #define pii pair <int, int> #define fi first #define se second #define mp make_pair const int NM = 1e6; int N, M, w[NM+5], pre[NM+5]; vector <int> st; int bit[NM+5]; vector <pair <pii, int> > q[NM+5]; bool ans[NM+5]; void update(int x, int val){ while (x <= N){ bit[x] = max(bit[x], val); x += x & (-x); } } int get(int x){ int res = 0; while (x > 0){ res = max(res, bit[x]); x -= x & (-x); } return res; } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> N >> M; for (int i = 1; i <= N; i++){ cin >> w[i]; while (!st.empty() && w[st.back()] <= w[i]) st.pop_back(); if (!st.empty()){ pre[i] = st.back(); } st.push_back(i); } for (int i = 1; i <= M; i++){ int l, r, k; cin >> l >> r >> k; q[r].push_back(mp(mp(l, k), i)); } for (int i = 1; i <= N; i++){ if (pre[i] > 0) update(N-pre[i]+1, w[i]+w[pre[i]]); for (pair <pii, int> P : q[i]){ ans[P.se] = get(N-P.fi.fi+1) <= P.fi.se; } } for (int i = 1; i <= M; 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...