This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
using namespace std;
#define INF 1000000000000000000
#define int long long int
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#ifdef wiwihorz
#define print(a...) cerr << "Line " << __LINE__ << ": ", kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
namespace bit {
int n;
vector<int> v;
void init_(int _n) {
n = _n;
v.assign(n + 1, 0);
}
int lowbit(int x) {
return x & (-x);
}
void modify(int x, int val) {
for(int i = x; i <= n; i += lowbit(i)) {
v[i] = max(v[i], val);
}
}
int query(int x) {
int ans = 0;
for(int i = x; i > 0; i -= lowbit(i)) {
ans = max(ans, v[i]);
}
return ans;
}
};
namespace solver {
int n, m;
vector<int> a, ans, r, k;
vector<vector<int>> q;
vector<pii> p;
void init_(int _n, int _m) {
n = _n, m = _m;
a.assign(n + 1, 0);
ans.assign(m + 1, 0);
r.assign(m + 1, 0);
k.assign(m + 1, 0);
q.assign(n + 1, vector<int>());
p.clear();
bit::init_(n);
}
void solve() {
vector<int> s;
rep(i, 1, n) {
while(s.size() && a[s.back()] <= a[i]) s.pop_back();
if(s.size()) p.push_back({s.back(), i});
s.push_back(i);
}
sort(all(p));
int ii = signed(p.size()) - 1;
rrep(i, 1, n) {
while(ii >= 0 && p[ii].first >= i) {
int L = p[ii].first, R = p[ii].second;
bit::modify(R, a[L] + a[R]);
ii--;
}
for(auto j : q[i]) {
ans[j] = bit::query(r[j]) <= k[j];
}
}
rep(i, 1 ,m) cout << ans[i] << "\n";
}
};
using namespace solver;
signed main() {
ios::sync_with_stdio(false), cin.tie(0);
int n, m;
cin >> n >> m;
init_(n, m);
rep(i, 1, n) cin >> a[i];
rep(i, 1, m) {
int l; cin >> l;
cin >> r[i] >> k[i];
q[l].push_back(i);
}
solve();
return 0;
}
Compilation message (stderr)
sortbooks.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
4 | #pragma loop-opt(on)
|
sortbooks.cpp:20:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
20 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
sortbooks.cpp:20:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
20 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
| ^~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |