제출 #348456

#제출 시각아이디문제언어결과실행 시간메모리
348456Kevin_Zhang_TWHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
1018 ms61460 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define pb emplace_back #define AI(i) begin(i), end(i) template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); } template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); } #ifdef KEV #define DE(args...) kout("[ " + string(#args) + " ] = ", args) void kout() { cerr << endl; } template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); } template<class T> void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; } #else #define DE(...) 0 #define debug(...) 0 #endif const int MAX_N = 1000010, p = 1e9 + 7; int n, m, w[MAX_N], mx[MAX_N], res[MAX_N], req[MAX_N]; void update(int i, int v) { i = n - i + 1; for (;i <= n;i += i&-i) chmax(mx[i], v); } int qry(int i) { i = n - i + 1; int res = 0; for (;i;i ^= i&-i) chmax(res, mx[i]); return res; } int dq[MAX_N], dl; vector<pair<int,int>> allq[MAX_N]; int32_t main() { ios_base::sync_with_stdio(0), cin.tie(0); cin >> n >> m; for (int i = 1;i <= n;++i) cin >> w[i]; for (int i = 0, l, r, k;i < m;++i) { cin >> l >> r >> k; allq[r].pb(l, i); req[i] = k; } for (int i = 1;i <= n;++i) { while (dl && w[ dq[dl-1] ] <= w[i]) --dl; if (dl) update(dq[dl-1], w[i] + w[dq[dl-1]]); dq[dl++] = i; for (auto [l, id] : allq[i]) res[id] = qry(l) <= req[id]; } for (int i = 0;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...