#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() {
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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
9 ms |
23920 KB |
Output is correct |
3 |
Correct |
10 ms |
23896 KB |
Output is correct |
4 |
Correct |
10 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23784 KB |
Output is correct |
8 |
Correct |
11 ms |
23900 KB |
Output is correct |
9 |
Correct |
11 ms |
23896 KB |
Output is correct |
10 |
Correct |
11 ms |
23900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
9 ms |
23920 KB |
Output is correct |
3 |
Correct |
10 ms |
23896 KB |
Output is correct |
4 |
Correct |
10 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23784 KB |
Output is correct |
8 |
Correct |
11 ms |
23900 KB |
Output is correct |
9 |
Correct |
11 ms |
23896 KB |
Output is correct |
10 |
Correct |
11 ms |
23900 KB |
Output is correct |
11 |
Correct |
12 ms |
24016 KB |
Output is correct |
12 |
Correct |
13 ms |
24156 KB |
Output is correct |
13 |
Correct |
13 ms |
24124 KB |
Output is correct |
14 |
Correct |
16 ms |
24152 KB |
Output is correct |
15 |
Correct |
15 ms |
24372 KB |
Output is correct |
16 |
Correct |
14 ms |
24156 KB |
Output is correct |
17 |
Correct |
13 ms |
24156 KB |
Output is correct |
18 |
Correct |
13 ms |
24156 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1078 ms |
110980 KB |
Output is correct |
2 |
Correct |
1284 ms |
111952 KB |
Output is correct |
3 |
Correct |
1351 ms |
111720 KB |
Output is correct |
4 |
Correct |
1307 ms |
111836 KB |
Output is correct |
5 |
Correct |
1111 ms |
107900 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
86 ms |
31056 KB |
Output is correct |
2 |
Correct |
75 ms |
30288 KB |
Output is correct |
3 |
Correct |
72 ms |
30544 KB |
Output is correct |
4 |
Correct |
78 ms |
30800 KB |
Output is correct |
5 |
Correct |
72 ms |
30800 KB |
Output is correct |
6 |
Correct |
71 ms |
29524 KB |
Output is correct |
7 |
Correct |
73 ms |
29524 KB |
Output is correct |
8 |
Correct |
84 ms |
30412 KB |
Output is correct |
9 |
Correct |
67 ms |
27472 KB |
Output is correct |
10 |
Correct |
75 ms |
30264 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
9 ms |
23920 KB |
Output is correct |
3 |
Correct |
10 ms |
23896 KB |
Output is correct |
4 |
Correct |
10 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23784 KB |
Output is correct |
8 |
Correct |
11 ms |
23900 KB |
Output is correct |
9 |
Correct |
11 ms |
23896 KB |
Output is correct |
10 |
Correct |
11 ms |
23900 KB |
Output is correct |
11 |
Correct |
12 ms |
24016 KB |
Output is correct |
12 |
Correct |
13 ms |
24156 KB |
Output is correct |
13 |
Correct |
13 ms |
24124 KB |
Output is correct |
14 |
Correct |
16 ms |
24152 KB |
Output is correct |
15 |
Correct |
15 ms |
24372 KB |
Output is correct |
16 |
Correct |
14 ms |
24156 KB |
Output is correct |
17 |
Correct |
13 ms |
24156 KB |
Output is correct |
18 |
Correct |
13 ms |
24156 KB |
Output is correct |
19 |
Correct |
210 ms |
41040 KB |
Output is correct |
20 |
Correct |
217 ms |
41040 KB |
Output is correct |
21 |
Correct |
200 ms |
39248 KB |
Output is correct |
22 |
Correct |
218 ms |
39252 KB |
Output is correct |
23 |
Correct |
194 ms |
39248 KB |
Output is correct |
24 |
Correct |
180 ms |
38228 KB |
Output is correct |
25 |
Correct |
195 ms |
38224 KB |
Output is correct |
26 |
Correct |
195 ms |
39040 KB |
Output is correct |
27 |
Correct |
186 ms |
38960 KB |
Output is correct |
28 |
Correct |
196 ms |
39280 KB |
Output is correct |
29 |
Correct |
207 ms |
40276 KB |
Output is correct |
30 |
Correct |
198 ms |
40436 KB |
Output is correct |
31 |
Correct |
203 ms |
40248 KB |
Output is correct |
32 |
Correct |
196 ms |
40164 KB |
Output is correct |
33 |
Correct |
191 ms |
40296 KB |
Output is correct |
34 |
Correct |
176 ms |
37968 KB |
Output is correct |
35 |
Correct |
173 ms |
37752 KB |
Output is correct |
36 |
Correct |
175 ms |
37712 KB |
Output is correct |
37 |
Correct |
161 ms |
37712 KB |
Output is correct |
38 |
Correct |
182 ms |
37852 KB |
Output is correct |
39 |
Correct |
178 ms |
38860 KB |
Output is correct |
40 |
Correct |
156 ms |
36608 KB |
Output is correct |
41 |
Correct |
162 ms |
38340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
23900 KB |
Output is correct |
2 |
Correct |
9 ms |
23920 KB |
Output is correct |
3 |
Correct |
10 ms |
23896 KB |
Output is correct |
4 |
Correct |
10 ms |
23900 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
23900 KB |
Output is correct |
7 |
Correct |
10 ms |
23784 KB |
Output is correct |
8 |
Correct |
11 ms |
23900 KB |
Output is correct |
9 |
Correct |
11 ms |
23896 KB |
Output is correct |
10 |
Correct |
11 ms |
23900 KB |
Output is correct |
11 |
Correct |
12 ms |
24016 KB |
Output is correct |
12 |
Correct |
13 ms |
24156 KB |
Output is correct |
13 |
Correct |
13 ms |
24124 KB |
Output is correct |
14 |
Correct |
16 ms |
24152 KB |
Output is correct |
15 |
Correct |
15 ms |
24372 KB |
Output is correct |
16 |
Correct |
14 ms |
24156 KB |
Output is correct |
17 |
Correct |
13 ms |
24156 KB |
Output is correct |
18 |
Correct |
13 ms |
24156 KB |
Output is correct |
19 |
Correct |
1078 ms |
110980 KB |
Output is correct |
20 |
Correct |
1284 ms |
111952 KB |
Output is correct |
21 |
Correct |
1351 ms |
111720 KB |
Output is correct |
22 |
Correct |
1307 ms |
111836 KB |
Output is correct |
23 |
Correct |
1111 ms |
107900 KB |
Output is correct |
24 |
Correct |
86 ms |
31056 KB |
Output is correct |
25 |
Correct |
75 ms |
30288 KB |
Output is correct |
26 |
Correct |
72 ms |
30544 KB |
Output is correct |
27 |
Correct |
78 ms |
30800 KB |
Output is correct |
28 |
Correct |
72 ms |
30800 KB |
Output is correct |
29 |
Correct |
71 ms |
29524 KB |
Output is correct |
30 |
Correct |
73 ms |
29524 KB |
Output is correct |
31 |
Correct |
84 ms |
30412 KB |
Output is correct |
32 |
Correct |
67 ms |
27472 KB |
Output is correct |
33 |
Correct |
75 ms |
30264 KB |
Output is correct |
34 |
Correct |
210 ms |
41040 KB |
Output is correct |
35 |
Correct |
217 ms |
41040 KB |
Output is correct |
36 |
Correct |
200 ms |
39248 KB |
Output is correct |
37 |
Correct |
218 ms |
39252 KB |
Output is correct |
38 |
Correct |
194 ms |
39248 KB |
Output is correct |
39 |
Correct |
180 ms |
38228 KB |
Output is correct |
40 |
Correct |
195 ms |
38224 KB |
Output is correct |
41 |
Correct |
195 ms |
39040 KB |
Output is correct |
42 |
Correct |
186 ms |
38960 KB |
Output is correct |
43 |
Correct |
196 ms |
39280 KB |
Output is correct |
44 |
Correct |
207 ms |
40276 KB |
Output is correct |
45 |
Correct |
198 ms |
40436 KB |
Output is correct |
46 |
Correct |
203 ms |
40248 KB |
Output is correct |
47 |
Correct |
196 ms |
40164 KB |
Output is correct |
48 |
Correct |
191 ms |
40296 KB |
Output is correct |
49 |
Correct |
176 ms |
37968 KB |
Output is correct |
50 |
Correct |
173 ms |
37752 KB |
Output is correct |
51 |
Correct |
175 ms |
37712 KB |
Output is correct |
52 |
Correct |
161 ms |
37712 KB |
Output is correct |
53 |
Correct |
182 ms |
37852 KB |
Output is correct |
54 |
Correct |
178 ms |
38860 KB |
Output is correct |
55 |
Correct |
156 ms |
36608 KB |
Output is correct |
56 |
Correct |
162 ms |
38340 KB |
Output is correct |
57 |
Correct |
1085 ms |
111164 KB |
Output is correct |
58 |
Correct |
1060 ms |
110568 KB |
Output is correct |
59 |
Correct |
1028 ms |
106752 KB |
Output is correct |
60 |
Correct |
992 ms |
106540 KB |
Output is correct |
61 |
Correct |
1045 ms |
106576 KB |
Output is correct |
62 |
Correct |
1030 ms |
106620 KB |
Output is correct |
63 |
Correct |
943 ms |
94972 KB |
Output is correct |
64 |
Correct |
924 ms |
95148 KB |
Output is correct |
65 |
Correct |
1052 ms |
102068 KB |
Output is correct |
66 |
Correct |
991 ms |
102172 KB |
Output is correct |
67 |
Correct |
1041 ms |
102480 KB |
Output is correct |
68 |
Correct |
1155 ms |
106832 KB |
Output is correct |
69 |
Correct |
1105 ms |
106836 KB |
Output is correct |
70 |
Correct |
1010 ms |
106320 KB |
Output is correct |
71 |
Correct |
1028 ms |
106268 KB |
Output is correct |
72 |
Correct |
1065 ms |
106108 KB |
Output is correct |
73 |
Correct |
866 ms |
93092 KB |
Output is correct |
74 |
Correct |
865 ms |
93932 KB |
Output is correct |
75 |
Correct |
929 ms |
93080 KB |
Output is correct |
76 |
Correct |
1014 ms |
92960 KB |
Output is correct |
77 |
Correct |
1032 ms |
92972 KB |
Output is correct |
78 |
Correct |
1130 ms |
100356 KB |
Output is correct |
79 |
Correct |
873 ms |
84288 KB |
Output is correct |
80 |
Correct |
995 ms |
96704 KB |
Output is correct |