제출 #1010990

#제출 시각아이디문제언어결과실행 시간메모리
1010990phoenixHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
715 ms101220 KiB
#include <bits/stdc++.h> using namespace std; const int N = 1'000'100; const int M = (1 << 20); int tr[2 * M]; void update(int pos, int val) { for (tr[pos += M] = val; pos > 1; pos >>= 1) tr[pos >> 1] = max(tr[pos], tr[pos ^ 1]); } int get(int ql, int qr) { int res = 0; for (ql += M, qr += M + 1; ql < qr; ql >>= 1, qr >>= 1) { if (ql & 1) res = max(res, tr[ql++]); if (qr & 1) res = max(res, tr[--qr]); } return res; } int n, m; int w[N]; vector<int> qrs[N]; struct query { int l, r, k; } Q[N]; bool res[N]; int main() { ios::sync_with_stdio(0); cin.tie(0); cin >> n >> m; for (int i = 1; i <= n; i++) cin >> w[i]; for (int i = 1; i <= m; i++) { cin >> Q[i].l >> Q[i].r >> Q[i].k; qrs[Q[i].r].push_back(i); } vector<int> st; for (int r = 1; r <= n; r++) { while (!st.empty() && w[st.back()] <= w[r]) st.pop_back(); if (!st.empty()) update(st.back(), w[st.back()] + w[r]); for (int i : qrs[r]) { res[i] = (get(Q[i].l, Q[i].r) <= Q[i].k); } st.push_back(r); } for (int i = 1; i <= m; i++) cout << res[i] << '\n'; }
#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...