#include <bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long double ld;
#define pb push_back
#define pf push_front
#define fi first
#define se second
const ll mod = 1e9+7, mxn = 1e6+7;
struct node
{
vector<ll> v;
ll mx = -mod, ans = -mod;
};
node merge(node const a, node const b)
{
node c;
c.mx = max(a.mx, b.mx);
c.ans = max({a.ans, b.ans});
ll p = lower_bound(b.v.begin(), b.v.end(), a.mx)-b.v.begin()-1;
if (p >= 0) c.ans = max({c.ans,b.v[p]+a.mx});
ll id_a = 0, id_b = 0;
while (id_a < a.v.size() && id_b < b.v.size())
{
if (a.v[id_a] < b.v[id_b]) c.v.pb(a.v[id_a++]);
else c.v.pb(b.v[id_b++]);
}
while (id_a < a.v.size()) c.v.pb(a.v[id_a++]);
while (id_b < b.v.size()) c.v.pb(b.v[id_b++]);
return c;
}
vector<node> st(mxn<<2);
ll a[mxn], n, q;
void build(ll id, ll l, ll r)
{
if (l == r) {st[id].mx = a[l]; st[id].v = {a[l]}; return;}
ll m = (r+l)>>1;
build(id<<1,l,m); build(id<<1|1,m+1,r);
st[id] = merge(st[id<<1], st[id<<1|1]);
}
node get(ll id, ll l, ll r, ll u, ll v)
{
if (u <= l && r <= v) return st[id];
ll m = (r+l)>>1;
if (v <= m) return get(id<<1,l,m,u,v);
else if (m+1 <= u) return get(id<<1|1,m+1,r,u,v);
else return merge(get(id<<1,l,m,u,v), get(id<<1|1,m+1,r,u,v));
}
signed main()
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// freopen("test.inp","r",stdin); freopen("test.out","w",stdout); freopen("test.err","w",stderr);
cin >> n >> q;
for (ll i = 1; i <= n; i++) cin >> a[i];
build(1,1,n);
while (q--)
{
ll l, r, k; cin >> l >> r >> k;
cout << (get(1,1,n,l,r).ans <= k) << '\n';
}
}
Compilation message
sortbooks.cpp: In function 'node merge(node, node)':
sortbooks.cpp:23:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | while (id_a < a.v.size() && id_b < b.v.size())
| ~~~~~^~~~~~~~~~~~
sortbooks.cpp:23:38: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | while (id_a < a.v.size() && id_b < b.v.size())
| ~~~~~^~~~~~~~~~~~
sortbooks.cpp:28:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
28 | while (id_a < a.v.size()) c.v.pb(a.v[id_a++]);
| ~~~~~^~~~~~~~~~~~
sortbooks.cpp:29:17: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | while (id_b < b.v.size()) c.v.pb(b.v[id_b++]);
| ~~~~~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
125528 KB |
Output is correct |
2 |
Correct |
19 ms |
125532 KB |
Output is correct |
3 |
Correct |
18 ms |
125740 KB |
Output is correct |
4 |
Correct |
19 ms |
125532 KB |
Output is correct |
5 |
Correct |
20 ms |
125532 KB |
Output is correct |
6 |
Correct |
20 ms |
125788 KB |
Output is correct |
7 |
Correct |
19 ms |
125788 KB |
Output is correct |
8 |
Correct |
19 ms |
125788 KB |
Output is correct |
9 |
Correct |
18 ms |
125624 KB |
Output is correct |
10 |
Correct |
18 ms |
125592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
125528 KB |
Output is correct |
2 |
Correct |
19 ms |
125532 KB |
Output is correct |
3 |
Correct |
18 ms |
125740 KB |
Output is correct |
4 |
Correct |
19 ms |
125532 KB |
Output is correct |
5 |
Correct |
20 ms |
125532 KB |
Output is correct |
6 |
Correct |
20 ms |
125788 KB |
Output is correct |
7 |
Correct |
19 ms |
125788 KB |
Output is correct |
8 |
Correct |
19 ms |
125788 KB |
Output is correct |
9 |
Correct |
18 ms |
125624 KB |
Output is correct |
10 |
Correct |
18 ms |
125592 KB |
Output is correct |
11 |
Correct |
37 ms |
125784 KB |
Output is correct |
12 |
Correct |
66 ms |
126552 KB |
Output is correct |
13 |
Correct |
77 ms |
126552 KB |
Output is correct |
14 |
Correct |
110 ms |
126556 KB |
Output is correct |
15 |
Correct |
112 ms |
126552 KB |
Output is correct |
16 |
Correct |
69 ms |
126556 KB |
Output is correct |
17 |
Correct |
32 ms |
126296 KB |
Output is correct |
18 |
Correct |
60 ms |
126428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
301 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3071 ms |
143460 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
125528 KB |
Output is correct |
2 |
Correct |
19 ms |
125532 KB |
Output is correct |
3 |
Correct |
18 ms |
125740 KB |
Output is correct |
4 |
Correct |
19 ms |
125532 KB |
Output is correct |
5 |
Correct |
20 ms |
125532 KB |
Output is correct |
6 |
Correct |
20 ms |
125788 KB |
Output is correct |
7 |
Correct |
19 ms |
125788 KB |
Output is correct |
8 |
Correct |
19 ms |
125788 KB |
Output is correct |
9 |
Correct |
18 ms |
125624 KB |
Output is correct |
10 |
Correct |
18 ms |
125592 KB |
Output is correct |
11 |
Correct |
37 ms |
125784 KB |
Output is correct |
12 |
Correct |
66 ms |
126552 KB |
Output is correct |
13 |
Correct |
77 ms |
126552 KB |
Output is correct |
14 |
Correct |
110 ms |
126556 KB |
Output is correct |
15 |
Correct |
112 ms |
126552 KB |
Output is correct |
16 |
Correct |
69 ms |
126556 KB |
Output is correct |
17 |
Correct |
32 ms |
126296 KB |
Output is correct |
18 |
Correct |
60 ms |
126428 KB |
Output is correct |
19 |
Execution timed out |
3072 ms |
160192 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
125528 KB |
Output is correct |
2 |
Correct |
19 ms |
125532 KB |
Output is correct |
3 |
Correct |
18 ms |
125740 KB |
Output is correct |
4 |
Correct |
19 ms |
125532 KB |
Output is correct |
5 |
Correct |
20 ms |
125532 KB |
Output is correct |
6 |
Correct |
20 ms |
125788 KB |
Output is correct |
7 |
Correct |
19 ms |
125788 KB |
Output is correct |
8 |
Correct |
19 ms |
125788 KB |
Output is correct |
9 |
Correct |
18 ms |
125624 KB |
Output is correct |
10 |
Correct |
18 ms |
125592 KB |
Output is correct |
11 |
Correct |
37 ms |
125784 KB |
Output is correct |
12 |
Correct |
66 ms |
126552 KB |
Output is correct |
13 |
Correct |
77 ms |
126552 KB |
Output is correct |
14 |
Correct |
110 ms |
126556 KB |
Output is correct |
15 |
Correct |
112 ms |
126552 KB |
Output is correct |
16 |
Correct |
69 ms |
126556 KB |
Output is correct |
17 |
Correct |
32 ms |
126296 KB |
Output is correct |
18 |
Correct |
60 ms |
126428 KB |
Output is correct |
19 |
Runtime error |
301 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |