Submission #352047

#TimeUsernameProblemLanguageResultExecution timeMemory
352047cheissmartHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++14
100 / 100
1105 ms94116 KiB
#include <bits/stdc++.h> #define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0); #define F first #define S second #define V vector #define PB push_back #define MP make_pair #define EB emplace_back #define ALL(v) (v).begin(), (v).end() #define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << (x) << endl using namespace std; typedef long long ll; typedef pair<int, int> pi; typedef V<int> vi; const int INF = 1e9 + 7, N = 1e6 + 7, C = 1e9 + 7; int a[N], ans[N]; V<array<int, 3>> G[N]; int bit[N]; void add(int pos, int val) { for(; pos < N; pos += pos & -pos) bit[pos] = max(bit[pos], val); } int qry(int pos) { int res = 0; for(; pos; pos -= pos & -pos) res = max(res, bit[pos]); return res; } signed main() { IO_OP; int n, m; cin >> n >> m; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 0; i < m; i++) { int l, r, k; cin >> l >> r >> k; G[l].PB({r, k, i}); } a[n + 1] = INF; deque<int> cut; cut.PB(n + 1); for(int i = n; i >= 1; i--) { while(a[i] > a[cut[0]]) { add(cut[0], a[cut[0]] + a[i]); cut.pop_front(); } cut.push_front(i); for(auto qq:G[i]) { int r = qq[0], k = qq[1], qi = qq[2]; int tt = qry(r); if(tt <= k) ans[qi] = 1; else ans[qi] = 0; } } 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...