제출 #373141

#제출 시각아이디문제언어결과실행 시간메모리
373141maksim1744Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
708 ms41580 KiB
/* author: Maksim1744 created: 03.03.2021 16:47:45 */ #include "bits/stdc++.h" using namespace std; #define ll long long #define ld long double #define mp make_pair #define pb push_back #define eb emplace_back #define sum(a) ( accumulate ((a).begin(), (a).end(), 0ll)) #define mine(a) (*min_element((a).begin(), (a).end())) #define maxe(a) (*max_element((a).begin(), (a).end())) #define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin()) #define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin()) #define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin()) #define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin()) template<typename T> vector<T>& operator-- (vector<T>& v){for (auto& i : v) --i; return v;} template<typename T> vector<T>& operator++ (vector<T>& v){for (auto& i : v) ++i; return v;} template<typename T> istream& operator>>(istream& is, vector<T>& v){for (auto& i : v) is >> i; return is;} template<typename T> ostream& operator<<(ostream& os, vector<T>& v){for (auto& i : v) os << i << ' '; return os;} template<typename T, typename U> pair<T,U>& operator-- (pair<T, U> &p){--p.first; --p.second; return p;} template<typename T, typename U> pair<T,U>& operator++ (pair<T, U> &p){++p.first; ++p.second; return p;} template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second; return is;} template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first << ' ' << p.second; return os;} template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);} template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);} template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;} template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;} #ifdef HOME #define SHOW_COLORS #include "C:/C++ libs/print.cpp" #else #define show(...) 42 #define mclock 42 #define shows 42 #define debug if (false) #endif template<typename T> struct fenwick { vector<T> tree; int n; fenwick(int n = 0) : n(n) { tree.assign(n, 0); } void set(int i, T k) { for (; i < n; i = (i | (i + 1))) tree[i] = k; } T ask(int r) { T res = 0; for (; r >= 0; r = (r & (r + 1)) - 1) res += tree[r]; return res; } }; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); int n, q; cin >> n >> q; vector<ll> w(n); cin >> w; struct str { int l, r; ll k; int ind; }; vector<str> que(q); for (int i = 0; i < q; ++i) { cin >> que[i].l >> que[i].r >> que[i].k; que[i].ind = i; --que[i].l; --que[i].r; } vector<int> ans(q, -1); sort(que.begin(), que.end(), [&](const auto &a, const auto &b) { return a.r < b.r; }); vector<int> st; fenwick<int> tree(n); int ind = 0; for (auto q : que) { while (ind <= q.r) { while (!st.empty() && w[st.back()] <= w[ind]) st.pop_back(); if (!st.empty()) { tree.set(n - 1 - st.back(), w[ind] + w[st.back()]); } st.pb(ind); ++ind; } ll val = tree.ask(n - 1 - q.l); ans[q.ind] = (val <= q.k); } for (int k : ans) cout << k << '\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...