Submission #345537

#TimeUsernameProblemLanguageResultExecution timeMemory
345537darkxeonHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
1173 ms82916 KiB
#include <bits/stdc++.h> #define sz(x) (long long)(x).size() using namespace std; //mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()); const int N = 1e5 + 5, M = 1e6 + 7, SM = 1e3 + 5, logN = 20; const long long MOD = 1e9 + 7, INF = 1e18 + 9; const int dx[] = {1, 0, 0, -1, -1, 1, -1, 1}; const int dy[] = {0, 1, -1, 0, -1, 1, 1, -1}; void debug() { cerr << "\n"; } template<typename Head, typename... Tail> void debug(Head a, Tail... b) { cerr << a << " "; debug(b...); } struct Query { long long l, k, i; }; vector<Query> q[M]; long long n, m, a[M], t[M], ans[M]; void update(long long i, long long x) { i = n - i + 1; for(; i <= n; i += i & -i) { t[i] = max(t[i], x); } } long long getMax(long long l) { l = n - l + 1; long long res = 0; for(; l >= 1; l -= l & -l) { res = max(res, t[l]); } return res; } int main() { //freopen(".in", "r", stdin); //freopen(".out", "w", stdout); ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> m; for(long long i = 1; i <= n; i++) { cin >> a[i]; } for(long long i = 1; i <= m; i++) { long long l, r, k; cin >> l >> r >> k; q[r].push_back({l, k, i}); } stack<long long> s; for(long long r = 1; r <= n; r++) { while(!s.empty() && a[r] >= a[s.top()]) { s.pop(); } if(!s.empty()) { update(s.top(), a[r] + a[s.top()]); } s.push(r); for(auto [l, k, i] : q[r]) { ans[i] = (getMax(l) <= k); } } for(long long i = 1; i <= m; i++) { cout << ans[i] << "\n"; } cout << endl; 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...