#include <bits/stdc++.h>
using namespace std;
typedef long long 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;
ll bit[mxn], n, q, w[mxn], lis[mxn];
bool ans[mxn];
vector<vector<pair<pair<ll,ll>,ll>>> qx(mxn);
void upd(ll u, ll v) {while (u) {bit[u] = max(bit[u],v); u -= (u&(-u));}}
ll get(ll u) {if (!u) {return 1e18;} ll sum = 0; while (u < mxn) {sum = max(sum,bit[u]); u += (u&(-u));} return sum;}
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 >> w[i]; lis[i] = i-1;
while (lis[i] && w[i] >= w[lis[i]]) lis[i] = lis[lis[i]];
// cerr << lis[i] << ' ';
}
for (ll i = 1; i <= q; i++)
{
ll l, r, c; cin >> l >> r >> c;
qx[r].pb({{l,i},c});
}
for (ll i = 1; i <= n; i++)
{
upd(lis[i],w[lis[i]]+w[i]);
for (pair<pair<ll,ll>,ll> j : qx[i]) ans[j.fi.se] = (get(j.fi.fi) <= j.se);
}
for (ll i = 1; i <= q; i++) cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
30044 KB |
Output is correct |
2 |
Correct |
4 ms |
30044 KB |
Output is correct |
3 |
Correct |
4 ms |
30044 KB |
Output is correct |
4 |
Correct |
4 ms |
30044 KB |
Output is correct |
5 |
Correct |
6 ms |
30044 KB |
Output is correct |
6 |
Correct |
4 ms |
30040 KB |
Output is correct |
7 |
Correct |
4 ms |
30044 KB |
Output is correct |
8 |
Correct |
4 ms |
30044 KB |
Output is correct |
9 |
Correct |
4 ms |
30044 KB |
Output is correct |
10 |
Correct |
4 ms |
30048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
30044 KB |
Output is correct |
2 |
Correct |
4 ms |
30044 KB |
Output is correct |
3 |
Correct |
4 ms |
30044 KB |
Output is correct |
4 |
Correct |
4 ms |
30044 KB |
Output is correct |
5 |
Correct |
6 ms |
30044 KB |
Output is correct |
6 |
Correct |
4 ms |
30040 KB |
Output is correct |
7 |
Correct |
4 ms |
30044 KB |
Output is correct |
8 |
Correct |
4 ms |
30044 KB |
Output is correct |
9 |
Correct |
4 ms |
30044 KB |
Output is correct |
10 |
Correct |
4 ms |
30048 KB |
Output is correct |
11 |
Correct |
4 ms |
30044 KB |
Output is correct |
12 |
Correct |
6 ms |
30044 KB |
Output is correct |
13 |
Correct |
5 ms |
30044 KB |
Output is correct |
14 |
Correct |
6 ms |
30300 KB |
Output is correct |
15 |
Correct |
7 ms |
30128 KB |
Output is correct |
16 |
Correct |
5 ms |
30300 KB |
Output is correct |
17 |
Correct |
5 ms |
30300 KB |
Output is correct |
18 |
Correct |
5 ms |
30044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
454 ms |
82848 KB |
Output is correct |
2 |
Correct |
466 ms |
82712 KB |
Output is correct |
3 |
Correct |
470 ms |
82864 KB |
Output is correct |
4 |
Correct |
445 ms |
82768 KB |
Output is correct |
5 |
Correct |
466 ms |
76900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
33620 KB |
Output is correct |
2 |
Correct |
37 ms |
33788 KB |
Output is correct |
3 |
Correct |
31 ms |
33620 KB |
Output is correct |
4 |
Correct |
32 ms |
33620 KB |
Output is correct |
5 |
Correct |
33 ms |
33452 KB |
Output is correct |
6 |
Correct |
25 ms |
33624 KB |
Output is correct |
7 |
Correct |
27 ms |
33628 KB |
Output is correct |
8 |
Correct |
38 ms |
33584 KB |
Output is correct |
9 |
Correct |
22 ms |
33296 KB |
Output is correct |
10 |
Correct |
34 ms |
33548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
30044 KB |
Output is correct |
2 |
Correct |
4 ms |
30044 KB |
Output is correct |
3 |
Correct |
4 ms |
30044 KB |
Output is correct |
4 |
Correct |
4 ms |
30044 KB |
Output is correct |
5 |
Correct |
6 ms |
30044 KB |
Output is correct |
6 |
Correct |
4 ms |
30040 KB |
Output is correct |
7 |
Correct |
4 ms |
30044 KB |
Output is correct |
8 |
Correct |
4 ms |
30044 KB |
Output is correct |
9 |
Correct |
4 ms |
30044 KB |
Output is correct |
10 |
Correct |
4 ms |
30048 KB |
Output is correct |
11 |
Correct |
4 ms |
30044 KB |
Output is correct |
12 |
Correct |
6 ms |
30044 KB |
Output is correct |
13 |
Correct |
5 ms |
30044 KB |
Output is correct |
14 |
Correct |
6 ms |
30300 KB |
Output is correct |
15 |
Correct |
7 ms |
30128 KB |
Output is correct |
16 |
Correct |
5 ms |
30300 KB |
Output is correct |
17 |
Correct |
5 ms |
30300 KB |
Output is correct |
18 |
Correct |
5 ms |
30044 KB |
Output is correct |
19 |
Correct |
74 ms |
39044 KB |
Output is correct |
20 |
Correct |
100 ms |
39056 KB |
Output is correct |
21 |
Correct |
70 ms |
39760 KB |
Output is correct |
22 |
Correct |
67 ms |
39824 KB |
Output is correct |
23 |
Correct |
65 ms |
39692 KB |
Output is correct |
24 |
Correct |
60 ms |
39824 KB |
Output is correct |
25 |
Correct |
66 ms |
34784 KB |
Output is correct |
26 |
Correct |
74 ms |
34384 KB |
Output is correct |
27 |
Correct |
70 ms |
34388 KB |
Output is correct |
28 |
Correct |
105 ms |
34304 KB |
Output is correct |
29 |
Correct |
91 ms |
34128 KB |
Output is correct |
30 |
Correct |
77 ms |
39124 KB |
Output is correct |
31 |
Correct |
77 ms |
39168 KB |
Output is correct |
32 |
Correct |
83 ms |
37428 KB |
Output is correct |
33 |
Correct |
71 ms |
39252 KB |
Output is correct |
34 |
Correct |
57 ms |
39252 KB |
Output is correct |
35 |
Correct |
92 ms |
36688 KB |
Output is correct |
36 |
Correct |
55 ms |
36692 KB |
Output is correct |
37 |
Correct |
55 ms |
36180 KB |
Output is correct |
38 |
Correct |
62 ms |
36436 KB |
Output is correct |
39 |
Correct |
64 ms |
35592 KB |
Output is correct |
40 |
Correct |
64 ms |
32132 KB |
Output is correct |
41 |
Correct |
65 ms |
36420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
30044 KB |
Output is correct |
2 |
Correct |
4 ms |
30044 KB |
Output is correct |
3 |
Correct |
4 ms |
30044 KB |
Output is correct |
4 |
Correct |
4 ms |
30044 KB |
Output is correct |
5 |
Correct |
6 ms |
30044 KB |
Output is correct |
6 |
Correct |
4 ms |
30040 KB |
Output is correct |
7 |
Correct |
4 ms |
30044 KB |
Output is correct |
8 |
Correct |
4 ms |
30044 KB |
Output is correct |
9 |
Correct |
4 ms |
30044 KB |
Output is correct |
10 |
Correct |
4 ms |
30048 KB |
Output is correct |
11 |
Correct |
4 ms |
30044 KB |
Output is correct |
12 |
Correct |
6 ms |
30044 KB |
Output is correct |
13 |
Correct |
5 ms |
30044 KB |
Output is correct |
14 |
Correct |
6 ms |
30300 KB |
Output is correct |
15 |
Correct |
7 ms |
30128 KB |
Output is correct |
16 |
Correct |
5 ms |
30300 KB |
Output is correct |
17 |
Correct |
5 ms |
30300 KB |
Output is correct |
18 |
Correct |
5 ms |
30044 KB |
Output is correct |
19 |
Correct |
454 ms |
82848 KB |
Output is correct |
20 |
Correct |
466 ms |
82712 KB |
Output is correct |
21 |
Correct |
470 ms |
82864 KB |
Output is correct |
22 |
Correct |
445 ms |
82768 KB |
Output is correct |
23 |
Correct |
466 ms |
76900 KB |
Output is correct |
24 |
Correct |
36 ms |
33620 KB |
Output is correct |
25 |
Correct |
37 ms |
33788 KB |
Output is correct |
26 |
Correct |
31 ms |
33620 KB |
Output is correct |
27 |
Correct |
32 ms |
33620 KB |
Output is correct |
28 |
Correct |
33 ms |
33452 KB |
Output is correct |
29 |
Correct |
25 ms |
33624 KB |
Output is correct |
30 |
Correct |
27 ms |
33628 KB |
Output is correct |
31 |
Correct |
38 ms |
33584 KB |
Output is correct |
32 |
Correct |
22 ms |
33296 KB |
Output is correct |
33 |
Correct |
34 ms |
33548 KB |
Output is correct |
34 |
Correct |
74 ms |
39044 KB |
Output is correct |
35 |
Correct |
100 ms |
39056 KB |
Output is correct |
36 |
Correct |
70 ms |
39760 KB |
Output is correct |
37 |
Correct |
67 ms |
39824 KB |
Output is correct |
38 |
Correct |
65 ms |
39692 KB |
Output is correct |
39 |
Correct |
60 ms |
39824 KB |
Output is correct |
40 |
Correct |
66 ms |
34784 KB |
Output is correct |
41 |
Correct |
74 ms |
34384 KB |
Output is correct |
42 |
Correct |
70 ms |
34388 KB |
Output is correct |
43 |
Correct |
105 ms |
34304 KB |
Output is correct |
44 |
Correct |
91 ms |
34128 KB |
Output is correct |
45 |
Correct |
77 ms |
39124 KB |
Output is correct |
46 |
Correct |
77 ms |
39168 KB |
Output is correct |
47 |
Correct |
83 ms |
37428 KB |
Output is correct |
48 |
Correct |
71 ms |
39252 KB |
Output is correct |
49 |
Correct |
57 ms |
39252 KB |
Output is correct |
50 |
Correct |
92 ms |
36688 KB |
Output is correct |
51 |
Correct |
55 ms |
36692 KB |
Output is correct |
52 |
Correct |
55 ms |
36180 KB |
Output is correct |
53 |
Correct |
62 ms |
36436 KB |
Output is correct |
54 |
Correct |
64 ms |
35592 KB |
Output is correct |
55 |
Correct |
64 ms |
32132 KB |
Output is correct |
56 |
Correct |
65 ms |
36420 KB |
Output is correct |
57 |
Correct |
457 ms |
82988 KB |
Output is correct |
58 |
Correct |
438 ms |
83028 KB |
Output is correct |
59 |
Correct |
427 ms |
83792 KB |
Output is correct |
60 |
Correct |
418 ms |
83880 KB |
Output is correct |
61 |
Correct |
430 ms |
83640 KB |
Output is correct |
62 |
Correct |
409 ms |
83896 KB |
Output is correct |
63 |
Correct |
288 ms |
77908 KB |
Output is correct |
64 |
Correct |
281 ms |
80048 KB |
Output is correct |
65 |
Correct |
406 ms |
78164 KB |
Output is correct |
66 |
Correct |
395 ms |
78164 KB |
Output is correct |
67 |
Correct |
377 ms |
78164 KB |
Output is correct |
68 |
Correct |
435 ms |
75208 KB |
Output is correct |
69 |
Correct |
413 ms |
77136 KB |
Output is correct |
70 |
Correct |
411 ms |
77244 KB |
Output is correct |
71 |
Correct |
443 ms |
75348 KB |
Output is correct |
72 |
Correct |
409 ms |
75348 KB |
Output is correct |
73 |
Correct |
276 ms |
73548 KB |
Output is correct |
74 |
Correct |
261 ms |
75536 KB |
Output is correct |
75 |
Correct |
256 ms |
75348 KB |
Output is correct |
76 |
Correct |
270 ms |
73856 KB |
Output is correct |
77 |
Correct |
308 ms |
75348 KB |
Output is correct |
78 |
Correct |
371 ms |
77216 KB |
Output is correct |
79 |
Correct |
288 ms |
62948 KB |
Output is correct |
80 |
Correct |
396 ms |
73704 KB |
Output is correct |