#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
const ll INF = 1'000'000'000'000LL;
int main()
{
int N, M;
cin >> N >> M;
vll w(1+N, 0);
for(int i = 1; i <= N; i++) cin >> w[i];
vi p(1+N);
w[0] = INF;
vector<int> st{0};
for(int i = 1; i <= N; i++)
{
while(w[st.back()] <= w[i]) st.pop_back(); //wrong?
p[i] = st.back();
st.push_back(i);
}
vi l(1+M), r(1+M), k(1+M);
vi rq[1+N];
for(int q = 1; q <= M; q++)
{
cin >> l[q] >> r[q] >> k[q];
rq[r[q]].push_back(q);
}
const int sn = (1<<20);
vll mx(int(sn<<1), 0);
int ans[1+M];
for(int i = 1; i <= N; i++)
{
ll val = w[i] + w[p[i]];
mx[ sn + p[i] ] = max(mx[ sn + p[i] ], val);
for(int j = (sn + p[i]) >> 1; j >= 1; j >>= 1)
mx[j] = max(mx[2*j], mx[2*j+1]);
for(int q: rq[i])
{
int x = sn + l[q];
int y = sn + i + 1;
ll res = 0;
while(x < y)
{
if(x % 2 == 1)
{
res = max(res, mx[x]);
x++;
}
if(y % 2 == 1)
{
y--;
res = max(res, mx[y]);
}
x >>= 1;
y >>= 1;
}
ans[q] = (res <= k[q]);
}
}
for(int q = 1; q <= M; q++) cout << ans[q] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
16716 KB |
Output is correct |
2 |
Correct |
9 ms |
16672 KB |
Output is correct |
3 |
Correct |
8 ms |
16716 KB |
Output is correct |
4 |
Correct |
7 ms |
16716 KB |
Output is correct |
5 |
Correct |
8 ms |
16652 KB |
Output is correct |
6 |
Correct |
8 ms |
16716 KB |
Output is correct |
7 |
Correct |
8 ms |
16688 KB |
Output is correct |
8 |
Correct |
7 ms |
16716 KB |
Output is correct |
9 |
Correct |
8 ms |
16692 KB |
Output is correct |
10 |
Correct |
8 ms |
16680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
16716 KB |
Output is correct |
2 |
Correct |
9 ms |
16672 KB |
Output is correct |
3 |
Correct |
8 ms |
16716 KB |
Output is correct |
4 |
Correct |
7 ms |
16716 KB |
Output is correct |
5 |
Correct |
8 ms |
16652 KB |
Output is correct |
6 |
Correct |
8 ms |
16716 KB |
Output is correct |
7 |
Correct |
8 ms |
16688 KB |
Output is correct |
8 |
Correct |
7 ms |
16716 KB |
Output is correct |
9 |
Correct |
8 ms |
16692 KB |
Output is correct |
10 |
Correct |
8 ms |
16680 KB |
Output is correct |
11 |
Correct |
13 ms |
16840 KB |
Output is correct |
12 |
Correct |
13 ms |
17056 KB |
Output is correct |
13 |
Correct |
12 ms |
17072 KB |
Output is correct |
14 |
Correct |
17 ms |
17192 KB |
Output is correct |
15 |
Correct |
15 ms |
17092 KB |
Output is correct |
16 |
Correct |
13 ms |
17052 KB |
Output is correct |
17 |
Correct |
14 ms |
17048 KB |
Output is correct |
18 |
Correct |
14 ms |
17076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2091 ms |
88060 KB |
Output is correct |
2 |
Correct |
2092 ms |
88300 KB |
Output is correct |
3 |
Correct |
2092 ms |
90316 KB |
Output is correct |
4 |
Correct |
2028 ms |
90380 KB |
Output is correct |
5 |
Correct |
2082 ms |
90308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
143 ms |
23964 KB |
Output is correct |
2 |
Correct |
141 ms |
24004 KB |
Output is correct |
3 |
Correct |
145 ms |
24356 KB |
Output is correct |
4 |
Correct |
147 ms |
24488 KB |
Output is correct |
5 |
Correct |
141 ms |
24488 KB |
Output is correct |
6 |
Correct |
125 ms |
23448 KB |
Output is correct |
7 |
Correct |
128 ms |
23460 KB |
Output is correct |
8 |
Correct |
120 ms |
24280 KB |
Output is correct |
9 |
Correct |
88 ms |
19808 KB |
Output is correct |
10 |
Correct |
130 ms |
24348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
16716 KB |
Output is correct |
2 |
Correct |
9 ms |
16672 KB |
Output is correct |
3 |
Correct |
8 ms |
16716 KB |
Output is correct |
4 |
Correct |
7 ms |
16716 KB |
Output is correct |
5 |
Correct |
8 ms |
16652 KB |
Output is correct |
6 |
Correct |
8 ms |
16716 KB |
Output is correct |
7 |
Correct |
8 ms |
16688 KB |
Output is correct |
8 |
Correct |
7 ms |
16716 KB |
Output is correct |
9 |
Correct |
8 ms |
16692 KB |
Output is correct |
10 |
Correct |
8 ms |
16680 KB |
Output is correct |
11 |
Correct |
13 ms |
16840 KB |
Output is correct |
12 |
Correct |
13 ms |
17056 KB |
Output is correct |
13 |
Correct |
12 ms |
17072 KB |
Output is correct |
14 |
Correct |
17 ms |
17192 KB |
Output is correct |
15 |
Correct |
15 ms |
17092 KB |
Output is correct |
16 |
Correct |
13 ms |
17052 KB |
Output is correct |
17 |
Correct |
14 ms |
17048 KB |
Output is correct |
18 |
Correct |
14 ms |
17076 KB |
Output is correct |
19 |
Correct |
365 ms |
31784 KB |
Output is correct |
20 |
Correct |
379 ms |
31376 KB |
Output is correct |
21 |
Correct |
353 ms |
29664 KB |
Output is correct |
22 |
Correct |
345 ms |
29604 KB |
Output is correct |
23 |
Correct |
415 ms |
29708 KB |
Output is correct |
24 |
Correct |
405 ms |
29516 KB |
Output is correct |
25 |
Correct |
361 ms |
29508 KB |
Output is correct |
26 |
Correct |
396 ms |
30264 KB |
Output is correct |
27 |
Correct |
369 ms |
30256 KB |
Output is correct |
28 |
Correct |
387 ms |
30492 KB |
Output is correct |
29 |
Correct |
387 ms |
31428 KB |
Output is correct |
30 |
Correct |
396 ms |
31404 KB |
Output is correct |
31 |
Correct |
387 ms |
31408 KB |
Output is correct |
32 |
Correct |
368 ms |
31256 KB |
Output is correct |
33 |
Correct |
389 ms |
31452 KB |
Output is correct |
34 |
Correct |
384 ms |
29324 KB |
Output is correct |
35 |
Correct |
338 ms |
29352 KB |
Output is correct |
36 |
Correct |
323 ms |
29260 KB |
Output is correct |
37 |
Correct |
334 ms |
29336 KB |
Output is correct |
38 |
Correct |
370 ms |
29328 KB |
Output is correct |
39 |
Correct |
342 ms |
31008 KB |
Output is correct |
40 |
Correct |
315 ms |
28308 KB |
Output is correct |
41 |
Correct |
312 ms |
31116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
16716 KB |
Output is correct |
2 |
Correct |
9 ms |
16672 KB |
Output is correct |
3 |
Correct |
8 ms |
16716 KB |
Output is correct |
4 |
Correct |
7 ms |
16716 KB |
Output is correct |
5 |
Correct |
8 ms |
16652 KB |
Output is correct |
6 |
Correct |
8 ms |
16716 KB |
Output is correct |
7 |
Correct |
8 ms |
16688 KB |
Output is correct |
8 |
Correct |
7 ms |
16716 KB |
Output is correct |
9 |
Correct |
8 ms |
16692 KB |
Output is correct |
10 |
Correct |
8 ms |
16680 KB |
Output is correct |
11 |
Correct |
13 ms |
16840 KB |
Output is correct |
12 |
Correct |
13 ms |
17056 KB |
Output is correct |
13 |
Correct |
12 ms |
17072 KB |
Output is correct |
14 |
Correct |
17 ms |
17192 KB |
Output is correct |
15 |
Correct |
15 ms |
17092 KB |
Output is correct |
16 |
Correct |
13 ms |
17052 KB |
Output is correct |
17 |
Correct |
14 ms |
17048 KB |
Output is correct |
18 |
Correct |
14 ms |
17076 KB |
Output is correct |
19 |
Correct |
2091 ms |
88060 KB |
Output is correct |
20 |
Correct |
2092 ms |
88300 KB |
Output is correct |
21 |
Correct |
2092 ms |
90316 KB |
Output is correct |
22 |
Correct |
2028 ms |
90380 KB |
Output is correct |
23 |
Correct |
2082 ms |
90308 KB |
Output is correct |
24 |
Correct |
143 ms |
23964 KB |
Output is correct |
25 |
Correct |
141 ms |
24004 KB |
Output is correct |
26 |
Correct |
145 ms |
24356 KB |
Output is correct |
27 |
Correct |
147 ms |
24488 KB |
Output is correct |
28 |
Correct |
141 ms |
24488 KB |
Output is correct |
29 |
Correct |
125 ms |
23448 KB |
Output is correct |
30 |
Correct |
128 ms |
23460 KB |
Output is correct |
31 |
Correct |
120 ms |
24280 KB |
Output is correct |
32 |
Correct |
88 ms |
19808 KB |
Output is correct |
33 |
Correct |
130 ms |
24348 KB |
Output is correct |
34 |
Correct |
365 ms |
31784 KB |
Output is correct |
35 |
Correct |
379 ms |
31376 KB |
Output is correct |
36 |
Correct |
353 ms |
29664 KB |
Output is correct |
37 |
Correct |
345 ms |
29604 KB |
Output is correct |
38 |
Correct |
415 ms |
29708 KB |
Output is correct |
39 |
Correct |
405 ms |
29516 KB |
Output is correct |
40 |
Correct |
361 ms |
29508 KB |
Output is correct |
41 |
Correct |
396 ms |
30264 KB |
Output is correct |
42 |
Correct |
369 ms |
30256 KB |
Output is correct |
43 |
Correct |
387 ms |
30492 KB |
Output is correct |
44 |
Correct |
387 ms |
31428 KB |
Output is correct |
45 |
Correct |
396 ms |
31404 KB |
Output is correct |
46 |
Correct |
387 ms |
31408 KB |
Output is correct |
47 |
Correct |
368 ms |
31256 KB |
Output is correct |
48 |
Correct |
389 ms |
31452 KB |
Output is correct |
49 |
Correct |
384 ms |
29324 KB |
Output is correct |
50 |
Correct |
338 ms |
29352 KB |
Output is correct |
51 |
Correct |
323 ms |
29260 KB |
Output is correct |
52 |
Correct |
334 ms |
29336 KB |
Output is correct |
53 |
Correct |
370 ms |
29328 KB |
Output is correct |
54 |
Correct |
342 ms |
31008 KB |
Output is correct |
55 |
Correct |
315 ms |
28308 KB |
Output is correct |
56 |
Correct |
312 ms |
31116 KB |
Output is correct |
57 |
Correct |
2179 ms |
88512 KB |
Output is correct |
58 |
Correct |
2243 ms |
88512 KB |
Output is correct |
59 |
Correct |
2091 ms |
84400 KB |
Output is correct |
60 |
Correct |
2070 ms |
83968 KB |
Output is correct |
61 |
Correct |
2052 ms |
81700 KB |
Output is correct |
62 |
Correct |
2045 ms |
81752 KB |
Output is correct |
63 |
Correct |
1840 ms |
75848 KB |
Output is correct |
64 |
Correct |
1792 ms |
75796 KB |
Output is correct |
65 |
Correct |
2105 ms |
81196 KB |
Output is correct |
66 |
Correct |
2070 ms |
81088 KB |
Output is correct |
67 |
Correct |
2212 ms |
81424 KB |
Output is correct |
68 |
Correct |
2194 ms |
85732 KB |
Output is correct |
69 |
Correct |
2119 ms |
85736 KB |
Output is correct |
70 |
Correct |
2164 ms |
85084 KB |
Output is correct |
71 |
Correct |
2166 ms |
85092 KB |
Output is correct |
72 |
Correct |
2238 ms |
85012 KB |
Output is correct |
73 |
Correct |
1968 ms |
75248 KB |
Output is correct |
74 |
Correct |
1883 ms |
75268 KB |
Output is correct |
75 |
Correct |
1843 ms |
75248 KB |
Output is correct |
76 |
Correct |
1757 ms |
75268 KB |
Output is correct |
77 |
Correct |
1764 ms |
75432 KB |
Output is correct |
78 |
Correct |
1963 ms |
83896 KB |
Output is correct |
79 |
Correct |
1624 ms |
64824 KB |
Output is correct |
80 |
Correct |
1837 ms |
84496 KB |
Output is correct |