제출 #571829

#제출 시각아이디문제언어결과실행 시간메모리
571829AzamatRustamovHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
875 ms116364 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; int n; vector<ll> fenwick; // for max void print() { cout << "Fenwick:\n"; for (int i=0; i<=n; i++) cout << fenwick[i] << ' '; cout << '\n'; } void upd(int i, ll val) { while (i > 0) { fenwick[i] = max(fenwick[i], val); i -= -i&i; } //print(); } ll get(int r) { ll mx = 0; while (r <= n) { mx = max(mx, fenwick[r]); r += -r&r; } //print(); return mx; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int m; cin >> n >> m; fenwick.assign(n, 0); //print(); ll w[n]; for (int i=1; i<=n; i++) cin >> w[i]; vector< pair< pair <ll, ll>, ll > > que[n+1]; for (int i=0; i<m; i++) { ll l, r, k; cin >> l >> r >> k; que[r].push_back({{l, k}, i}); } ll ans[m]; stack<int> st; st.push(0); for (int i=1; i<=n; i++) { while (!st.empty() and w[i] >= w[st.top()]) st.pop(); if (!st.empty()) upd(st.top(), w[st.top()]+w[i]); for (auto q : que[i]) { ans[q.second] = get(q.first.first)<=q.first.second; } st.push(i); } for (int i=0; i<m; i++) cout << ans[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...