#include <bits/stdc++.h>
#define Y8o "main"
#define maxn (int) 1e6 + 5
#define ll long long
#define pii pair<int, int>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define fi(i, a, b) for(int i = a; i <= b; i ++)
#define fid(i, a, b) for(int i = a; i >= b; i --)
#define f first
#define s second
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
ios_base::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
if(fopen(Y8o".inp", "r"))
{
freopen(Y8o".inp", "r", stdin);
// freopen(Y8o".out", "w", stdout);
}
}
void ctime() {
cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
const int inf = 1e9;
int n, Q;
int pre[maxn], a[maxn], ans[maxn];
vector<int> cur, st[maxn];
struct dl { int l, r, val, id; } qr[maxn];
int fake(int x) {
return lower_bound(all(cur), x) - cur.begin() + 1;
}
struct BIT {
int bit[maxn];
void update(int x, int val) {
while(x > 0) bit[x] = max(bit[x], val), x -= (x & -x);
}
int get(int x, int best = 0) {
while(x <= n) best = max(best, bit[x]), x += (x & -x);
return best;
}
} Bit;
struct SEGMT {
int st[4 * maxn];
void update(int i, int val, int id = 1, int l = 1, int r = n) {
if(i < l || r < i) return;
if(l == r) return st[id] = a[l] + val, void();
int mid = (l + r) >> 1;
update(i, val, _left), update(i, val, _right);
st[id] = max(st[id * 2], st[id * 2 + 1]);
}
int get(int u, int v, int id = 1, int l = 1, int r = n) {
if(v < l || r < u) return -inf;
if(u <= l && r <= v) return st[id];
int mid = (l + r) >> 1;
return max( get(u, v, _left), get(u, v, _right) );
}
} ST;
void solve() {
cin >> n >> Q;
fi(i, 1, n) cin >> a[i], cur.push_back(a[i]);
sort(all(cur));
cur.resize(unique(all(cur)) - cur.begin());
fi(i, 1, n) {
pre[i] = Bit.get(fake(a[i]));
Bit.update(fake(a[i]) - 1, i);
st[pre[i]].push_back(i);
}
fi(i, 1, n) {
if(!pre[i]) ST.update(i, -inf);
else ST.update(i, a[pre[i]]);
}
fi(i, 1, Q) {
int l, r, val; cin >> l >> r >> val;
qr[i] = { l, r, val, i };
}
sort( qr + 1, qr + Q + 1, [](dl x, dl y) {
return x.l < y.l;
});
int j = 1;
fi(_, 1, Q) {
int l = qr[_].l, r = qr[_].r, val = qr[_].val, id = qr[_].id;
while(j < l) {
while(st[j].size()) {
int pos = st[j].back();
st[j].pop_back();
ST.update(pos, -inf);
}
j ++;
}
int mx = ST.get(l, r);
ans[id] = mx <= val;
}
fi(i, 1, Q) cout << ans[i] << '\n';
}
int main() {
iof();
int nTest = 1;
// cin >> nTest;
while(nTest --) {
solve();
}
ctime();
return 0;
}
Compilation message (stderr)
sortbooks.cpp: In function 'void iof()':
sortbooks.cpp:27:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen(Y8o".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# | 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... |