#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 |
30040 KB |
Output is correct |
2 |
Correct |
4 ms |
30044 KB |
Output is correct |
3 |
Correct |
5 ms |
30044 KB |
Output is correct |
4 |
Correct |
4 ms |
30044 KB |
Output is correct |
5 |
Correct |
4 ms |
30044 KB |
Output is correct |
6 |
Correct |
5 ms |
29924 KB |
Output is correct |
7 |
Correct |
5 ms |
30044 KB |
Output is correct |
8 |
Correct |
5 ms |
30044 KB |
Output is correct |
9 |
Correct |
4 ms |
30044 KB |
Output is correct |
10 |
Correct |
5 ms |
30040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
30040 KB |
Output is correct |
2 |
Correct |
4 ms |
30044 KB |
Output is correct |
3 |
Correct |
5 ms |
30044 KB |
Output is correct |
4 |
Correct |
4 ms |
30044 KB |
Output is correct |
5 |
Correct |
4 ms |
30044 KB |
Output is correct |
6 |
Correct |
5 ms |
29924 KB |
Output is correct |
7 |
Correct |
5 ms |
30044 KB |
Output is correct |
8 |
Correct |
5 ms |
30044 KB |
Output is correct |
9 |
Correct |
4 ms |
30044 KB |
Output is correct |
10 |
Correct |
5 ms |
30040 KB |
Output is correct |
11 |
Correct |
7 ms |
30044 KB |
Output is correct |
12 |
Correct |
13 ms |
30132 KB |
Output is correct |
13 |
Correct |
13 ms |
30044 KB |
Output is correct |
14 |
Correct |
14 ms |
30300 KB |
Output is correct |
15 |
Correct |
14 ms |
30300 KB |
Output is correct |
16 |
Correct |
14 ms |
30300 KB |
Output is correct |
17 |
Correct |
13 ms |
30300 KB |
Output is correct |
18 |
Correct |
14 ms |
30300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2194 ms |
89808 KB |
Output is correct |
2 |
Correct |
2237 ms |
89684 KB |
Output is correct |
3 |
Correct |
2219 ms |
89680 KB |
Output is correct |
4 |
Correct |
2196 ms |
89680 KB |
Output is correct |
5 |
Correct |
2205 ms |
97752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
203 ms |
34128 KB |
Output is correct |
2 |
Correct |
200 ms |
34756 KB |
Output is correct |
3 |
Correct |
203 ms |
35428 KB |
Output is correct |
4 |
Correct |
200 ms |
35280 KB |
Output is correct |
5 |
Correct |
197 ms |
35204 KB |
Output is correct |
6 |
Correct |
197 ms |
35152 KB |
Output is correct |
7 |
Correct |
203 ms |
35152 KB |
Output is correct |
8 |
Correct |
203 ms |
35404 KB |
Output is correct |
9 |
Correct |
24 ms |
34316 KB |
Output is correct |
10 |
Correct |
198 ms |
35592 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
30040 KB |
Output is correct |
2 |
Correct |
4 ms |
30044 KB |
Output is correct |
3 |
Correct |
5 ms |
30044 KB |
Output is correct |
4 |
Correct |
4 ms |
30044 KB |
Output is correct |
5 |
Correct |
4 ms |
30044 KB |
Output is correct |
6 |
Correct |
5 ms |
29924 KB |
Output is correct |
7 |
Correct |
5 ms |
30044 KB |
Output is correct |
8 |
Correct |
5 ms |
30044 KB |
Output is correct |
9 |
Correct |
4 ms |
30044 KB |
Output is correct |
10 |
Correct |
5 ms |
30040 KB |
Output is correct |
11 |
Correct |
7 ms |
30044 KB |
Output is correct |
12 |
Correct |
13 ms |
30132 KB |
Output is correct |
13 |
Correct |
13 ms |
30044 KB |
Output is correct |
14 |
Correct |
14 ms |
30300 KB |
Output is correct |
15 |
Correct |
14 ms |
30300 KB |
Output is correct |
16 |
Correct |
14 ms |
30300 KB |
Output is correct |
17 |
Correct |
13 ms |
30300 KB |
Output is correct |
18 |
Correct |
14 ms |
30300 KB |
Output is correct |
19 |
Correct |
416 ms |
42068 KB |
Output is correct |
20 |
Correct |
433 ms |
45464 KB |
Output is correct |
21 |
Correct |
410 ms |
45996 KB |
Output is correct |
22 |
Correct |
413 ms |
45996 KB |
Output is correct |
23 |
Correct |
425 ms |
45900 KB |
Output is correct |
24 |
Correct |
425 ms |
44956 KB |
Output is correct |
25 |
Correct |
467 ms |
44984 KB |
Output is correct |
26 |
Correct |
409 ms |
44884 KB |
Output is correct |
27 |
Correct |
403 ms |
44884 KB |
Output is correct |
28 |
Correct |
415 ms |
44772 KB |
Output is correct |
29 |
Correct |
425 ms |
44624 KB |
Output is correct |
30 |
Correct |
434 ms |
44628 KB |
Output is correct |
31 |
Correct |
427 ms |
44792 KB |
Output is correct |
32 |
Correct |
403 ms |
44628 KB |
Output is correct |
33 |
Correct |
421 ms |
44712 KB |
Output is correct |
34 |
Correct |
401 ms |
44296 KB |
Output is correct |
35 |
Correct |
399 ms |
44352 KB |
Output is correct |
36 |
Correct |
387 ms |
44116 KB |
Output is correct |
37 |
Correct |
393 ms |
44108 KB |
Output is correct |
38 |
Correct |
395 ms |
44468 KB |
Output is correct |
39 |
Correct |
433 ms |
43532 KB |
Output is correct |
40 |
Correct |
284 ms |
40016 KB |
Output is correct |
41 |
Correct |
417 ms |
44548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
30040 KB |
Output is correct |
2 |
Correct |
4 ms |
30044 KB |
Output is correct |
3 |
Correct |
5 ms |
30044 KB |
Output is correct |
4 |
Correct |
4 ms |
30044 KB |
Output is correct |
5 |
Correct |
4 ms |
30044 KB |
Output is correct |
6 |
Correct |
5 ms |
29924 KB |
Output is correct |
7 |
Correct |
5 ms |
30044 KB |
Output is correct |
8 |
Correct |
5 ms |
30044 KB |
Output is correct |
9 |
Correct |
4 ms |
30044 KB |
Output is correct |
10 |
Correct |
5 ms |
30040 KB |
Output is correct |
11 |
Correct |
7 ms |
30044 KB |
Output is correct |
12 |
Correct |
13 ms |
30132 KB |
Output is correct |
13 |
Correct |
13 ms |
30044 KB |
Output is correct |
14 |
Correct |
14 ms |
30300 KB |
Output is correct |
15 |
Correct |
14 ms |
30300 KB |
Output is correct |
16 |
Correct |
14 ms |
30300 KB |
Output is correct |
17 |
Correct |
13 ms |
30300 KB |
Output is correct |
18 |
Correct |
14 ms |
30300 KB |
Output is correct |
19 |
Correct |
2194 ms |
89808 KB |
Output is correct |
20 |
Correct |
2237 ms |
89684 KB |
Output is correct |
21 |
Correct |
2219 ms |
89680 KB |
Output is correct |
22 |
Correct |
2196 ms |
89680 KB |
Output is correct |
23 |
Correct |
2205 ms |
97752 KB |
Output is correct |
24 |
Correct |
203 ms |
34128 KB |
Output is correct |
25 |
Correct |
200 ms |
34756 KB |
Output is correct |
26 |
Correct |
203 ms |
35428 KB |
Output is correct |
27 |
Correct |
200 ms |
35280 KB |
Output is correct |
28 |
Correct |
197 ms |
35204 KB |
Output is correct |
29 |
Correct |
197 ms |
35152 KB |
Output is correct |
30 |
Correct |
203 ms |
35152 KB |
Output is correct |
31 |
Correct |
203 ms |
35404 KB |
Output is correct |
32 |
Correct |
24 ms |
34316 KB |
Output is correct |
33 |
Correct |
198 ms |
35592 KB |
Output is correct |
34 |
Correct |
416 ms |
42068 KB |
Output is correct |
35 |
Correct |
433 ms |
45464 KB |
Output is correct |
36 |
Correct |
410 ms |
45996 KB |
Output is correct |
37 |
Correct |
413 ms |
45996 KB |
Output is correct |
38 |
Correct |
425 ms |
45900 KB |
Output is correct |
39 |
Correct |
425 ms |
44956 KB |
Output is correct |
40 |
Correct |
467 ms |
44984 KB |
Output is correct |
41 |
Correct |
409 ms |
44884 KB |
Output is correct |
42 |
Correct |
403 ms |
44884 KB |
Output is correct |
43 |
Correct |
415 ms |
44772 KB |
Output is correct |
44 |
Correct |
425 ms |
44624 KB |
Output is correct |
45 |
Correct |
434 ms |
44628 KB |
Output is correct |
46 |
Correct |
427 ms |
44792 KB |
Output is correct |
47 |
Correct |
403 ms |
44628 KB |
Output is correct |
48 |
Correct |
421 ms |
44712 KB |
Output is correct |
49 |
Correct |
401 ms |
44296 KB |
Output is correct |
50 |
Correct |
399 ms |
44352 KB |
Output is correct |
51 |
Correct |
387 ms |
44116 KB |
Output is correct |
52 |
Correct |
393 ms |
44108 KB |
Output is correct |
53 |
Correct |
395 ms |
44468 KB |
Output is correct |
54 |
Correct |
433 ms |
43532 KB |
Output is correct |
55 |
Correct |
284 ms |
40016 KB |
Output is correct |
56 |
Correct |
417 ms |
44548 KB |
Output is correct |
57 |
Correct |
2194 ms |
122740 KB |
Output is correct |
58 |
Correct |
2214 ms |
122704 KB |
Output is correct |
59 |
Correct |
2165 ms |
123504 KB |
Output is correct |
60 |
Correct |
2144 ms |
123388 KB |
Output is correct |
61 |
Correct |
2170 ms |
123472 KB |
Output is correct |
62 |
Correct |
2118 ms |
123580 KB |
Output is correct |
63 |
Correct |
1993 ms |
112956 KB |
Output is correct |
64 |
Correct |
1984 ms |
112980 KB |
Output is correct |
65 |
Correct |
2146 ms |
112976 KB |
Output is correct |
66 |
Correct |
2183 ms |
112812 KB |
Output is correct |
67 |
Correct |
2091 ms |
112748 KB |
Output is correct |
68 |
Correct |
2221 ms |
111872 KB |
Output is correct |
69 |
Correct |
2452 ms |
111916 KB |
Output is correct |
70 |
Correct |
2200 ms |
112132 KB |
Output is correct |
71 |
Correct |
2186 ms |
111920 KB |
Output is correct |
72 |
Correct |
2213 ms |
111956 KB |
Output is correct |
73 |
Correct |
2023 ms |
106956 KB |
Output is correct |
74 |
Correct |
1989 ms |
107980 KB |
Output is correct |
75 |
Correct |
1967 ms |
106604 KB |
Output is correct |
76 |
Correct |
1994 ms |
107412 KB |
Output is correct |
77 |
Correct |
1978 ms |
106916 KB |
Output is correct |
78 |
Correct |
2124 ms |
107712 KB |
Output is correct |
79 |
Correct |
1256 ms |
91632 KB |
Output is correct |
80 |
Correct |
2168 ms |
104720 KB |
Output is correct |