#include <bits/stdc++.h>
using namespace std;
struct update {
int l, r, k;
};
struct query {
int l, r, k, ans;
};
const int MAX_N = 1e6;
const int MAX_Q = 1e6;
const int INF = 1e9 + 1;
int v[MAX_N + 1];
update updates[MAX_N + 1];
query queries[MAX_Q];
vector<int> queriesByR[MAX_N + 1];
struct AIB_SUF {
int aib[MAX_N + 2];
void update( int i, int x ) {
i = MAX_N + 1 - i;
while ( i <= MAX_N ) {
aib[i] = max( aib[i], x );
i += (i & -i);
}
}
int query( int i ) {
i = MAX_N + 1 - i;
int x = 0;
while ( i > 0 ) {
x = max( x, aib[i] );
i -= (i & -i);
}
return x;
}
} maxKSuf;
int main() {
cin.tie( NULL );
ios_base::sync_with_stdio( false );
int n, q;
cin >> n >> q;
v[0] = INF;
for ( int i = 1; i <= n; i++ )
cin >> v[i];
for ( int i = 0; i < q; i++ )
cin >> queries[i].l >> queries[i].r >> queries[i].k;
vector<int> stack;
stack.push_back( 0 );
for ( int i = 1; i <= n; i++ ) {
while ( !stack.empty() && v[i] >= v[stack.back()] )
stack.pop_back();
updates[i] = { stack.back(), i, v[stack.back()] + v[i] };
stack.push_back( i );
}
for ( int i = 0; i < q; i++ )
queriesByR[queries[i].r].push_back( i );
for ( int i = 1; i <= n; i++ ) {
maxKSuf.update( updates[i].l, updates[i].k );
for ( int j: queriesByR[i] )
queries[j].ans = maxKSuf.query( queries[j].l );
}
for ( int i = 0; i < q; i++ )
cout << (queries[i].ans <= queries[i].k) << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
23964 KB |
Output is correct |
3 |
Correct |
11 ms |
23968 KB |
Output is correct |
4 |
Correct |
9 ms |
23900 KB |
Output is correct |
5 |
Correct |
9 ms |
23900 KB |
Output is correct |
6 |
Correct |
9 ms |
23900 KB |
Output is correct |
7 |
Correct |
11 ms |
23928 KB |
Output is correct |
8 |
Correct |
12 ms |
23832 KB |
Output is correct |
9 |
Correct |
12 ms |
23980 KB |
Output is correct |
10 |
Correct |
10 ms |
23968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
23964 KB |
Output is correct |
3 |
Correct |
11 ms |
23968 KB |
Output is correct |
4 |
Correct |
9 ms |
23900 KB |
Output is correct |
5 |
Correct |
9 ms |
23900 KB |
Output is correct |
6 |
Correct |
9 ms |
23900 KB |
Output is correct |
7 |
Correct |
11 ms |
23928 KB |
Output is correct |
8 |
Correct |
12 ms |
23832 KB |
Output is correct |
9 |
Correct |
12 ms |
23980 KB |
Output is correct |
10 |
Correct |
10 ms |
23968 KB |
Output is correct |
11 |
Correct |
12 ms |
24156 KB |
Output is correct |
12 |
Correct |
12 ms |
24156 KB |
Output is correct |
13 |
Correct |
9 ms |
24084 KB |
Output is correct |
14 |
Correct |
14 ms |
24400 KB |
Output is correct |
15 |
Correct |
11 ms |
24156 KB |
Output is correct |
16 |
Correct |
16 ms |
24156 KB |
Output is correct |
17 |
Correct |
12 ms |
24316 KB |
Output is correct |
18 |
Correct |
12 ms |
24172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
678 ms |
103396 KB |
Output is correct |
2 |
Correct |
632 ms |
104020 KB |
Output is correct |
3 |
Correct |
608 ms |
103764 KB |
Output is correct |
4 |
Correct |
604 ms |
104024 KB |
Output is correct |
5 |
Correct |
539 ms |
100176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
50 ms |
30868 KB |
Output is correct |
2 |
Correct |
43 ms |
30236 KB |
Output is correct |
3 |
Correct |
45 ms |
30448 KB |
Output is correct |
4 |
Correct |
42 ms |
30544 KB |
Output is correct |
5 |
Correct |
49 ms |
30500 KB |
Output is correct |
6 |
Correct |
40 ms |
29556 KB |
Output is correct |
7 |
Correct |
38 ms |
29480 KB |
Output is correct |
8 |
Correct |
42 ms |
30304 KB |
Output is correct |
9 |
Correct |
32 ms |
27352 KB |
Output is correct |
10 |
Correct |
46 ms |
30252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
23964 KB |
Output is correct |
3 |
Correct |
11 ms |
23968 KB |
Output is correct |
4 |
Correct |
9 ms |
23900 KB |
Output is correct |
5 |
Correct |
9 ms |
23900 KB |
Output is correct |
6 |
Correct |
9 ms |
23900 KB |
Output is correct |
7 |
Correct |
11 ms |
23928 KB |
Output is correct |
8 |
Correct |
12 ms |
23832 KB |
Output is correct |
9 |
Correct |
12 ms |
23980 KB |
Output is correct |
10 |
Correct |
10 ms |
23968 KB |
Output is correct |
11 |
Correct |
12 ms |
24156 KB |
Output is correct |
12 |
Correct |
12 ms |
24156 KB |
Output is correct |
13 |
Correct |
9 ms |
24084 KB |
Output is correct |
14 |
Correct |
14 ms |
24400 KB |
Output is correct |
15 |
Correct |
11 ms |
24156 KB |
Output is correct |
16 |
Correct |
16 ms |
24156 KB |
Output is correct |
17 |
Correct |
12 ms |
24316 KB |
Output is correct |
18 |
Correct |
12 ms |
24172 KB |
Output is correct |
19 |
Correct |
101 ms |
39932 KB |
Output is correct |
20 |
Correct |
93 ms |
37972 KB |
Output is correct |
21 |
Correct |
82 ms |
36360 KB |
Output is correct |
22 |
Correct |
92 ms |
36424 KB |
Output is correct |
23 |
Correct |
81 ms |
36428 KB |
Output is correct |
24 |
Correct |
76 ms |
35152 KB |
Output is correct |
25 |
Correct |
70 ms |
35152 KB |
Output is correct |
26 |
Correct |
83 ms |
36180 KB |
Output is correct |
27 |
Correct |
90 ms |
36176 KB |
Output is correct |
28 |
Correct |
102 ms |
36556 KB |
Output is correct |
29 |
Correct |
88 ms |
37200 KB |
Output is correct |
30 |
Correct |
89 ms |
37200 KB |
Output is correct |
31 |
Correct |
99 ms |
37228 KB |
Output is correct |
32 |
Correct |
76 ms |
37200 KB |
Output is correct |
33 |
Correct |
81 ms |
37200 KB |
Output is correct |
34 |
Correct |
83 ms |
34900 KB |
Output is correct |
35 |
Correct |
67 ms |
35064 KB |
Output is correct |
36 |
Correct |
77 ms |
34888 KB |
Output is correct |
37 |
Correct |
79 ms |
34900 KB |
Output is correct |
38 |
Correct |
87 ms |
34900 KB |
Output is correct |
39 |
Correct |
81 ms |
36520 KB |
Output is correct |
40 |
Correct |
76 ms |
34504 KB |
Output is correct |
41 |
Correct |
79 ms |
36040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23900 KB |
Output is correct |
2 |
Correct |
11 ms |
23964 KB |
Output is correct |
3 |
Correct |
11 ms |
23968 KB |
Output is correct |
4 |
Correct |
9 ms |
23900 KB |
Output is correct |
5 |
Correct |
9 ms |
23900 KB |
Output is correct |
6 |
Correct |
9 ms |
23900 KB |
Output is correct |
7 |
Correct |
11 ms |
23928 KB |
Output is correct |
8 |
Correct |
12 ms |
23832 KB |
Output is correct |
9 |
Correct |
12 ms |
23980 KB |
Output is correct |
10 |
Correct |
10 ms |
23968 KB |
Output is correct |
11 |
Correct |
12 ms |
24156 KB |
Output is correct |
12 |
Correct |
12 ms |
24156 KB |
Output is correct |
13 |
Correct |
9 ms |
24084 KB |
Output is correct |
14 |
Correct |
14 ms |
24400 KB |
Output is correct |
15 |
Correct |
11 ms |
24156 KB |
Output is correct |
16 |
Correct |
16 ms |
24156 KB |
Output is correct |
17 |
Correct |
12 ms |
24316 KB |
Output is correct |
18 |
Correct |
12 ms |
24172 KB |
Output is correct |
19 |
Correct |
678 ms |
103396 KB |
Output is correct |
20 |
Correct |
632 ms |
104020 KB |
Output is correct |
21 |
Correct |
608 ms |
103764 KB |
Output is correct |
22 |
Correct |
604 ms |
104024 KB |
Output is correct |
23 |
Correct |
539 ms |
100176 KB |
Output is correct |
24 |
Correct |
50 ms |
30868 KB |
Output is correct |
25 |
Correct |
43 ms |
30236 KB |
Output is correct |
26 |
Correct |
45 ms |
30448 KB |
Output is correct |
27 |
Correct |
42 ms |
30544 KB |
Output is correct |
28 |
Correct |
49 ms |
30500 KB |
Output is correct |
29 |
Correct |
40 ms |
29556 KB |
Output is correct |
30 |
Correct |
38 ms |
29480 KB |
Output is correct |
31 |
Correct |
42 ms |
30304 KB |
Output is correct |
32 |
Correct |
32 ms |
27352 KB |
Output is correct |
33 |
Correct |
46 ms |
30252 KB |
Output is correct |
34 |
Correct |
101 ms |
39932 KB |
Output is correct |
35 |
Correct |
93 ms |
37972 KB |
Output is correct |
36 |
Correct |
82 ms |
36360 KB |
Output is correct |
37 |
Correct |
92 ms |
36424 KB |
Output is correct |
38 |
Correct |
81 ms |
36428 KB |
Output is correct |
39 |
Correct |
76 ms |
35152 KB |
Output is correct |
40 |
Correct |
70 ms |
35152 KB |
Output is correct |
41 |
Correct |
83 ms |
36180 KB |
Output is correct |
42 |
Correct |
90 ms |
36176 KB |
Output is correct |
43 |
Correct |
102 ms |
36556 KB |
Output is correct |
44 |
Correct |
88 ms |
37200 KB |
Output is correct |
45 |
Correct |
89 ms |
37200 KB |
Output is correct |
46 |
Correct |
99 ms |
37228 KB |
Output is correct |
47 |
Correct |
76 ms |
37200 KB |
Output is correct |
48 |
Correct |
81 ms |
37200 KB |
Output is correct |
49 |
Correct |
83 ms |
34900 KB |
Output is correct |
50 |
Correct |
67 ms |
35064 KB |
Output is correct |
51 |
Correct |
77 ms |
34888 KB |
Output is correct |
52 |
Correct |
79 ms |
34900 KB |
Output is correct |
53 |
Correct |
87 ms |
34900 KB |
Output is correct |
54 |
Correct |
81 ms |
36520 KB |
Output is correct |
55 |
Correct |
76 ms |
34504 KB |
Output is correct |
56 |
Correct |
79 ms |
36040 KB |
Output is correct |
57 |
Correct |
557 ms |
94132 KB |
Output is correct |
58 |
Correct |
542 ms |
77512 KB |
Output is correct |
59 |
Correct |
469 ms |
73044 KB |
Output is correct |
60 |
Correct |
481 ms |
73120 KB |
Output is correct |
61 |
Correct |
474 ms |
73044 KB |
Output is correct |
62 |
Correct |
485 ms |
73044 KB |
Output is correct |
63 |
Correct |
360 ms |
63312 KB |
Output is correct |
64 |
Correct |
504 ms |
63312 KB |
Output is correct |
65 |
Correct |
432 ms |
68688 KB |
Output is correct |
66 |
Correct |
445 ms |
68688 KB |
Output is correct |
67 |
Correct |
461 ms |
69100 KB |
Output is correct |
68 |
Correct |
466 ms |
73296 KB |
Output is correct |
69 |
Correct |
510 ms |
73260 KB |
Output is correct |
70 |
Correct |
469 ms |
72696 KB |
Output is correct |
71 |
Correct |
465 ms |
72532 KB |
Output is correct |
72 |
Correct |
454 ms |
72528 KB |
Output is correct |
73 |
Correct |
355 ms |
62888 KB |
Output is correct |
74 |
Correct |
332 ms |
62836 KB |
Output is correct |
75 |
Correct |
341 ms |
63068 KB |
Output is correct |
76 |
Correct |
351 ms |
63060 KB |
Output is correct |
77 |
Correct |
331 ms |
62804 KB |
Output is correct |
78 |
Correct |
441 ms |
72816 KB |
Output is correct |
79 |
Correct |
354 ms |
61884 KB |
Output is correct |
80 |
Correct |
389 ms |
72240 KB |
Output is correct |