#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define ll int
#define ld long double
#define endl "\n"
#define fi first
#define se second
#define y1 sadjfskldf
#define PB push_back
#define sqr(x) ((x) * (x))
#define all(x) x.begin(), x.end()
using namespace std;
using namespace __gnu_pbds;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
const ll N = 1e6 + 200;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
struct trees
{
ll ans;
vector<ll> val;
};
trees t[4 * N];
ll a[N],global,n,Q,l,r,x,k;
ll quest(ll mx,vector<ll> &v)
{
ll pos = lower_bound(all(v), mx) - v.begin();
if(!pos) return 0;
return mx + v[--pos];
}
void build(ll v,ll tl,ll tr)
{
if(tl == tr)
{
t[v].val.PB(a[tl]);
return;
}
ll tm = (tl + tr) / 2;
build(2 * v, tl, tm);
build(2 * v + 1, tm + 1, tr);
for(auto x : t[2 * v].val) t[v].val.PB(x);
for(auto x : t[2 * v + 1].val) t[v].val.PB(x);
sort(all(t[v].val));
t[v].ans = max(max(t[2 * v].ans, t[2 * v + 1].ans), quest((t[2 * v].val).back(), (t[2 * v + 1].val)));
}
ll get(ll v,ll tl,ll tr,ll l, ll r)
{
if(l > r) return 0;
if(tl == l && tr == r)
{
ll ans = t[v].ans;
ans = max(ans, quest(global, t[v].val));
global = max(global, t[v].val.back());
return ans;
}
ll tm = (tl + tr) / 2,x,y;
x = get(2 * v, tl, tm, l, min(tm, r));
y = get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r);
return max(x, y);
}
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>Q;
for(int i = 1; i <= n; i++) cin>>a[i];
build(1, 1, n);
while(Q--)
{
cin>>l>>r>>k;
global = 0;
x = get(1, 1, n, l, r);
if(x <= k) cout<<1<<endl;
else cout<<0<<endl;
}
return 0;
}
/*
8 1
5 4 3 1 6 7 8 2
2 5
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
125688 KB |
Output is correct |
2 |
Correct |
111 ms |
125724 KB |
Output is correct |
3 |
Correct |
114 ms |
125660 KB |
Output is correct |
4 |
Correct |
110 ms |
125692 KB |
Output is correct |
5 |
Correct |
112 ms |
125560 KB |
Output is correct |
6 |
Correct |
111 ms |
125660 KB |
Output is correct |
7 |
Correct |
111 ms |
125688 KB |
Output is correct |
8 |
Correct |
110 ms |
125608 KB |
Output is correct |
9 |
Correct |
111 ms |
125776 KB |
Output is correct |
10 |
Correct |
112 ms |
125664 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
125688 KB |
Output is correct |
2 |
Correct |
111 ms |
125724 KB |
Output is correct |
3 |
Correct |
114 ms |
125660 KB |
Output is correct |
4 |
Correct |
110 ms |
125692 KB |
Output is correct |
5 |
Correct |
112 ms |
125560 KB |
Output is correct |
6 |
Correct |
111 ms |
125660 KB |
Output is correct |
7 |
Correct |
111 ms |
125688 KB |
Output is correct |
8 |
Correct |
110 ms |
125608 KB |
Output is correct |
9 |
Correct |
111 ms |
125776 KB |
Output is correct |
10 |
Correct |
112 ms |
125664 KB |
Output is correct |
11 |
Correct |
114 ms |
125816 KB |
Output is correct |
12 |
Correct |
117 ms |
126200 KB |
Output is correct |
13 |
Correct |
119 ms |
126204 KB |
Output is correct |
14 |
Correct |
122 ms |
126328 KB |
Output is correct |
15 |
Correct |
120 ms |
126328 KB |
Output is correct |
16 |
Correct |
118 ms |
126296 KB |
Output is correct |
17 |
Correct |
117 ms |
126076 KB |
Output is correct |
18 |
Correct |
119 ms |
126328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1508 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
404 ms |
139544 KB |
Output is correct |
2 |
Correct |
384 ms |
139416 KB |
Output is correct |
3 |
Correct |
333 ms |
139408 KB |
Output is correct |
4 |
Correct |
337 ms |
139504 KB |
Output is correct |
5 |
Correct |
332 ms |
139508 KB |
Output is correct |
6 |
Correct |
282 ms |
139484 KB |
Output is correct |
7 |
Correct |
283 ms |
139504 KB |
Output is correct |
8 |
Correct |
304 ms |
139508 KB |
Output is correct |
9 |
Correct |
161 ms |
125864 KB |
Output is correct |
10 |
Correct |
297 ms |
139576 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
125688 KB |
Output is correct |
2 |
Correct |
111 ms |
125724 KB |
Output is correct |
3 |
Correct |
114 ms |
125660 KB |
Output is correct |
4 |
Correct |
110 ms |
125692 KB |
Output is correct |
5 |
Correct |
112 ms |
125560 KB |
Output is correct |
6 |
Correct |
111 ms |
125660 KB |
Output is correct |
7 |
Correct |
111 ms |
125688 KB |
Output is correct |
8 |
Correct |
110 ms |
125608 KB |
Output is correct |
9 |
Correct |
111 ms |
125776 KB |
Output is correct |
10 |
Correct |
112 ms |
125664 KB |
Output is correct |
11 |
Correct |
114 ms |
125816 KB |
Output is correct |
12 |
Correct |
117 ms |
126200 KB |
Output is correct |
13 |
Correct |
119 ms |
126204 KB |
Output is correct |
14 |
Correct |
122 ms |
126328 KB |
Output is correct |
15 |
Correct |
120 ms |
126328 KB |
Output is correct |
16 |
Correct |
118 ms |
126296 KB |
Output is correct |
17 |
Correct |
117 ms |
126076 KB |
Output is correct |
18 |
Correct |
119 ms |
126328 KB |
Output is correct |
19 |
Correct |
855 ms |
154164 KB |
Output is correct |
20 |
Correct |
829 ms |
154160 KB |
Output is correct |
21 |
Correct |
759 ms |
154356 KB |
Output is correct |
22 |
Correct |
744 ms |
154152 KB |
Output is correct |
23 |
Correct |
752 ms |
154136 KB |
Output is correct |
24 |
Correct |
532 ms |
154200 KB |
Output is correct |
25 |
Correct |
550 ms |
154140 KB |
Output is correct |
26 |
Correct |
610 ms |
154172 KB |
Output is correct |
27 |
Correct |
621 ms |
154348 KB |
Output is correct |
28 |
Correct |
646 ms |
154192 KB |
Output is correct |
29 |
Correct |
638 ms |
154092 KB |
Output is correct |
30 |
Correct |
657 ms |
154152 KB |
Output is correct |
31 |
Correct |
697 ms |
154296 KB |
Output is correct |
32 |
Correct |
647 ms |
154232 KB |
Output is correct |
33 |
Correct |
662 ms |
154056 KB |
Output is correct |
34 |
Correct |
509 ms |
154132 KB |
Output is correct |
35 |
Correct |
510 ms |
154192 KB |
Output is correct |
36 |
Correct |
498 ms |
154136 KB |
Output is correct |
37 |
Correct |
508 ms |
154168 KB |
Output is correct |
38 |
Correct |
505 ms |
154220 KB |
Output is correct |
39 |
Correct |
631 ms |
154116 KB |
Output is correct |
40 |
Correct |
432 ms |
142320 KB |
Output is correct |
41 |
Correct |
557 ms |
154224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
110 ms |
125688 KB |
Output is correct |
2 |
Correct |
111 ms |
125724 KB |
Output is correct |
3 |
Correct |
114 ms |
125660 KB |
Output is correct |
4 |
Correct |
110 ms |
125692 KB |
Output is correct |
5 |
Correct |
112 ms |
125560 KB |
Output is correct |
6 |
Correct |
111 ms |
125660 KB |
Output is correct |
7 |
Correct |
111 ms |
125688 KB |
Output is correct |
8 |
Correct |
110 ms |
125608 KB |
Output is correct |
9 |
Correct |
111 ms |
125776 KB |
Output is correct |
10 |
Correct |
112 ms |
125664 KB |
Output is correct |
11 |
Correct |
114 ms |
125816 KB |
Output is correct |
12 |
Correct |
117 ms |
126200 KB |
Output is correct |
13 |
Correct |
119 ms |
126204 KB |
Output is correct |
14 |
Correct |
122 ms |
126328 KB |
Output is correct |
15 |
Correct |
120 ms |
126328 KB |
Output is correct |
16 |
Correct |
118 ms |
126296 KB |
Output is correct |
17 |
Correct |
117 ms |
126076 KB |
Output is correct |
18 |
Correct |
119 ms |
126328 KB |
Output is correct |
19 |
Runtime error |
1508 ms |
262144 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
20 |
Halted |
0 ms |
0 KB |
- |