# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1166362 | CrabCNH | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++20 | 486 ms | 84912 KiB |
#include <bits/stdc++.h>
#define task "BriantheCrab"
#define int long long
#define pii pair <int, int>
#define fi first
#define se second
#define szf sizeof
#define sz(s) (int)((s).size())
using namespace std;
template <class T> void mini (T &t, T f) {if (t > f) t = f;}
template <class T> void maxi (T &t, T f) {if (t < f) t = f;}
const int maxN = 1e6 + 5;
const int inf = 1e18 + 7;
const int mod = 1e9 + 7;
struct off {
int l, c, id;
};
int n, m;
int a[maxN], res[maxN];
vector <off> q[maxN];
struct Fenwick {
int bit[maxN];
Fenwick () {
memset (bit, 0, szf (bit));
}
void upd (int x, int v) {
for (; x > 0; x -= x & (-x)) {
maxi (bit[x], v);
}
}
int getMax (int x) {
int mx = -inf;
for (; x <= n; x += x & (-x)) {
maxi (mx, bit[x]);
}
return mx;
}
};
Fenwick T;
void solve () {
cin >> n >> m;
for (int i = 1; i <= n; i ++) {
cin >> a[i];
}
for (int i = 1; i <= m; i ++) {
int l, r, c;
cin >> l >> r >> c;
q[r].push_back ({l, c, i});
}
stack <int> st;
for (int i = 1; i <= n; i ++) {
while (!st.empty () && a[st.top ()] <= a[i]) {
//cout << "OUT " << st.top () << '\n';
st.pop ();
}
if (!st.empty ()) {
T.upd (st.top (), a[st.top ()] + a[i]);
}
st.push (i);
//cout << "IN " << st.top () << '\n';
for (auto [l, c, id] : q[i]) {
res[id] = (T.getMax (l) <= c);
}
}
for (int i = 1; i <= m; i ++) {
cout << res[i] << '\n';
}
}
signed main () {
cin.tie (nullptr) -> sync_with_stdio (false);
if (fopen (task".inp", "r")) {
freopen (task".inp", "r", stdin);
freopen (task".out", "w", stdout);
}
int t = 1;
//cin >> t;
while (t --) {
solve ();
}
return 0;
}
// thfdgb
Compilation message (stderr)
# | 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... |