/*
ID: varunra2
LANG: C++
TASK: books
*/
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif
#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second
const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions
struct node {
int mx = 0;
int retl = 0;
int retr = 0;
int ret = 0;
void deb() {
debug(mx);
debug(retl);
debug(retr);
debug(ret);
}
} bad, cur, a, b;
void comb(node& a, node& l, node& r) {
a.mx = max(l.mx, r.mx);
if (l.ret > r.ret) {
a.retl = l.retl;
a.retr = l.retr;
a.ret = l.ret;
} else {
a.retl = r.retl;
a.retr = r.retr;
a.ret = r.ret;
}
if (l.mx > r.retr and l.mx + r.retr > max(l.ret, r.ret)) {
a.retl = l.mx;
a.retr = r.retr;
a.ret = l.mx + r.retr;
}
}
void sett(node& a, int val) {
a.mx = val;
a.retr = val;
a.retl = 0;
a.ret = 0;
}
struct segtree {
int siz;
int n;
vector<node> st;
VI vals;
void build(int node, int l, int r) {
if (l > r) return;
if (l == r) {
sett(st[node], vals[l]);
return;
}
int mid = (l + r) / 2;
build(2 * node + 1, l, mid);
build(2 * node + 2, mid + 1, r);
comb(st[node], st[2 * node + 1], st[2 * node + 2]);
}
void init(VI& _vals) {
n = sz(_vals);
st.resize(4 * n);
vals = _vals;
build(0, 0, n - 1);
}
node qry(int tl, int tr, int node, int l, int r) {
if (l > tr) return bad;
if (r < tl) return bad;
if (l > r) return bad;
if (l >= tl and r <= tr) {
return st[node];
}
int mid = (l + r) / 2;
a = qry(tl, tr, 2 * node + 1, l, mid);
b = qry(tl, tr, 2 * node + 2, mid + 1, r);
// a.deb();
// b.deb();
// debug("here");
comb(cur, a, b);
return cur;
}
int qry(int l, int r) {
cur = qry(l, r, 0, 0, n - 1);
// cur.deb();
return qry(l, r, 0, 0, n - 1).ret;
}
};
int main() {
// #ifndef ONLINE_JUDGE
// freopen("books.in", "r", stdin);
// freopen("books.out", "w", stdout);
// #endif
cin.sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
VI vals(n);
for (int i = 0; i < n; i++) {
cin >> vals[i];
}
segtree st;
st.init(vals);
for (int i = 0; i < m; i++) {
int l, r, val;
cin >> l >> r >> val;
l--, r--;
int cur = st.qry(l, r);
// debug(cur);
cout << (cur <= val ? 1 : 0) << '\n';
}
return 0;
}
Compilation message
sortbooks.cpp: In member function 'void node::deb()':
sortbooks.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
sortbooks.cpp:62:5: note: in expansion of macro 'debug'
62 | debug(mx);
| ^~~~~
sortbooks.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
sortbooks.cpp:63:5: note: in expansion of macro 'debug'
63 | debug(retl);
| ^~~~~
sortbooks.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
sortbooks.cpp:64:5: note: in expansion of macro 'debug'
64 | debug(retr);
| ^~~~~
sortbooks.cpp:19:20: warning: statement has no effect [-Wunused-value]
19 | #define debug(...) 42
| ^~
sortbooks.cpp:65:5: note: in expansion of macro 'debug'
65 | debug(ret);
| ^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2598 ms |
79640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
192 ms |
9580 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Incorrect |
1 ms |
364 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |