#include <iostream>
#include <vector>
#include <stack>
using namespace std;
int n, m, w[1000001], a[5000001], l[1000001], pos, val, x, y;
bool f[1000001];
struct Query { int id, l, k; };
vector<Query> q[1000001];
stack<int> s;
void update(int nod, int l, int r)
{
if(l == r) a[nod] = max(a[nod], val);
else
{
int m = (l + r)/2;
if(pos <= m) update(2*nod, l, m);
else update(2*nod+1, m+1, r);
a[nod] = max(a[2*nod], a[2*nod+1]);
}
}
void read()
{
cin >> n >> m;
for(int i = 1; i <= n; ++i)
cin >> w[i];
for(int i = 1, r, l, k; i <= m; ++i)
{
cin >> l >> r >> k;
q[r].push_back({i, l, k});
}
}
int query(int nod, int l, int r)
{
if(x <= l && r <= y) return a[nod];
int m = (l + r)/2, rez = 0;
if(x <= m) rez = max(rez, query(2*nod, l, m));
if(m < y) rez = max(rez, query(2*nod+1, m+1, r));
return rez;
}
void config()
{
for(int i = 1; i <= n; ++i)
{
l[i] = i;
for(;!s.empty() && w[i] >= w[s.top()];s.pop())
l[i] = l[s.top()];
s.push(i);
}
}
void afis()
{
for(int i = 1; i <= m; ++i)
cout << f[i] << '\n';
}
void solve()
{
for(int i = 1; i <= n; ++i)
{
if(l[i] > 1)
{
pos = l[i] - 1;
val = w[i] + w[pos];
update(1, 1, n);
}
for(auto j : q[i])
{
x = j.l, y = i;
f[j.id] = (j.k >= query(1, 1, n));
}
}
}
int main()
{
read();
config();
solve();
afis();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23740 KB |
Output is correct |
3 |
Correct |
12 ms |
23756 KB |
Output is correct |
4 |
Correct |
12 ms |
23752 KB |
Output is correct |
5 |
Correct |
13 ms |
23756 KB |
Output is correct |
6 |
Correct |
13 ms |
23756 KB |
Output is correct |
7 |
Correct |
17 ms |
23780 KB |
Output is correct |
8 |
Correct |
12 ms |
23756 KB |
Output is correct |
9 |
Correct |
17 ms |
23776 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23740 KB |
Output is correct |
3 |
Correct |
12 ms |
23756 KB |
Output is correct |
4 |
Correct |
12 ms |
23752 KB |
Output is correct |
5 |
Correct |
13 ms |
23756 KB |
Output is correct |
6 |
Correct |
13 ms |
23756 KB |
Output is correct |
7 |
Correct |
17 ms |
23780 KB |
Output is correct |
8 |
Correct |
12 ms |
23756 KB |
Output is correct |
9 |
Correct |
17 ms |
23776 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
16 ms |
23884 KB |
Output is correct |
12 |
Correct |
18 ms |
23896 KB |
Output is correct |
13 |
Correct |
17 ms |
23884 KB |
Output is correct |
14 |
Correct |
19 ms |
24000 KB |
Output is correct |
15 |
Correct |
20 ms |
23996 KB |
Output is correct |
16 |
Correct |
21 ms |
23884 KB |
Output is correct |
17 |
Correct |
17 ms |
23908 KB |
Output is correct |
18 |
Correct |
20 ms |
23992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2208 ms |
67488 KB |
Output is correct |
2 |
Correct |
2261 ms |
73064 KB |
Output is correct |
3 |
Correct |
2197 ms |
72852 KB |
Output is correct |
4 |
Correct |
2235 ms |
72932 KB |
Output is correct |
5 |
Correct |
1984 ms |
68768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
152 ms |
27920 KB |
Output is correct |
2 |
Correct |
153 ms |
27784 KB |
Output is correct |
3 |
Correct |
141 ms |
26864 KB |
Output is correct |
4 |
Correct |
144 ms |
26948 KB |
Output is correct |
5 |
Correct |
143 ms |
26948 KB |
Output is correct |
6 |
Correct |
131 ms |
26716 KB |
Output is correct |
7 |
Correct |
137 ms |
26484 KB |
Output is correct |
8 |
Correct |
129 ms |
26776 KB |
Output is correct |
9 |
Correct |
90 ms |
25560 KB |
Output is correct |
10 |
Correct |
134 ms |
27180 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23740 KB |
Output is correct |
3 |
Correct |
12 ms |
23756 KB |
Output is correct |
4 |
Correct |
12 ms |
23752 KB |
Output is correct |
5 |
Correct |
13 ms |
23756 KB |
Output is correct |
6 |
Correct |
13 ms |
23756 KB |
Output is correct |
7 |
Correct |
17 ms |
23780 KB |
Output is correct |
8 |
Correct |
12 ms |
23756 KB |
Output is correct |
9 |
Correct |
17 ms |
23776 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
16 ms |
23884 KB |
Output is correct |
12 |
Correct |
18 ms |
23896 KB |
Output is correct |
13 |
Correct |
17 ms |
23884 KB |
Output is correct |
14 |
Correct |
19 ms |
24000 KB |
Output is correct |
15 |
Correct |
20 ms |
23996 KB |
Output is correct |
16 |
Correct |
21 ms |
23884 KB |
Output is correct |
17 |
Correct |
17 ms |
23908 KB |
Output is correct |
18 |
Correct |
20 ms |
23992 KB |
Output is correct |
19 |
Correct |
379 ms |
32204 KB |
Output is correct |
20 |
Correct |
518 ms |
32208 KB |
Output is correct |
21 |
Correct |
416 ms |
38244 KB |
Output is correct |
22 |
Correct |
354 ms |
38168 KB |
Output is correct |
23 |
Correct |
379 ms |
38120 KB |
Output is correct |
24 |
Correct |
421 ms |
35928 KB |
Output is correct |
25 |
Correct |
372 ms |
35888 KB |
Output is correct |
26 |
Correct |
402 ms |
36208 KB |
Output is correct |
27 |
Correct |
355 ms |
36212 KB |
Output is correct |
28 |
Correct |
383 ms |
36460 KB |
Output is correct |
29 |
Correct |
355 ms |
36768 KB |
Output is correct |
30 |
Correct |
412 ms |
36788 KB |
Output is correct |
31 |
Correct |
449 ms |
36732 KB |
Output is correct |
32 |
Correct |
408 ms |
36704 KB |
Output is correct |
33 |
Correct |
464 ms |
36728 KB |
Output is correct |
34 |
Correct |
319 ms |
35460 KB |
Output is correct |
35 |
Correct |
386 ms |
35540 KB |
Output is correct |
36 |
Correct |
405 ms |
35256 KB |
Output is correct |
37 |
Correct |
386 ms |
35328 KB |
Output is correct |
38 |
Correct |
357 ms |
35568 KB |
Output is correct |
39 |
Correct |
351 ms |
35628 KB |
Output is correct |
40 |
Correct |
320 ms |
33472 KB |
Output is correct |
41 |
Correct |
298 ms |
34552 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23756 KB |
Output is correct |
2 |
Correct |
12 ms |
23740 KB |
Output is correct |
3 |
Correct |
12 ms |
23756 KB |
Output is correct |
4 |
Correct |
12 ms |
23752 KB |
Output is correct |
5 |
Correct |
13 ms |
23756 KB |
Output is correct |
6 |
Correct |
13 ms |
23756 KB |
Output is correct |
7 |
Correct |
17 ms |
23780 KB |
Output is correct |
8 |
Correct |
12 ms |
23756 KB |
Output is correct |
9 |
Correct |
17 ms |
23776 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
16 ms |
23884 KB |
Output is correct |
12 |
Correct |
18 ms |
23896 KB |
Output is correct |
13 |
Correct |
17 ms |
23884 KB |
Output is correct |
14 |
Correct |
19 ms |
24000 KB |
Output is correct |
15 |
Correct |
20 ms |
23996 KB |
Output is correct |
16 |
Correct |
21 ms |
23884 KB |
Output is correct |
17 |
Correct |
17 ms |
23908 KB |
Output is correct |
18 |
Correct |
20 ms |
23992 KB |
Output is correct |
19 |
Correct |
2208 ms |
67488 KB |
Output is correct |
20 |
Correct |
2261 ms |
73064 KB |
Output is correct |
21 |
Correct |
2197 ms |
72852 KB |
Output is correct |
22 |
Correct |
2235 ms |
72932 KB |
Output is correct |
23 |
Correct |
1984 ms |
68768 KB |
Output is correct |
24 |
Correct |
152 ms |
27920 KB |
Output is correct |
25 |
Correct |
153 ms |
27784 KB |
Output is correct |
26 |
Correct |
141 ms |
26864 KB |
Output is correct |
27 |
Correct |
144 ms |
26948 KB |
Output is correct |
28 |
Correct |
143 ms |
26948 KB |
Output is correct |
29 |
Correct |
131 ms |
26716 KB |
Output is correct |
30 |
Correct |
137 ms |
26484 KB |
Output is correct |
31 |
Correct |
129 ms |
26776 KB |
Output is correct |
32 |
Correct |
90 ms |
25560 KB |
Output is correct |
33 |
Correct |
134 ms |
27180 KB |
Output is correct |
34 |
Correct |
379 ms |
32204 KB |
Output is correct |
35 |
Correct |
518 ms |
32208 KB |
Output is correct |
36 |
Correct |
416 ms |
38244 KB |
Output is correct |
37 |
Correct |
354 ms |
38168 KB |
Output is correct |
38 |
Correct |
379 ms |
38120 KB |
Output is correct |
39 |
Correct |
421 ms |
35928 KB |
Output is correct |
40 |
Correct |
372 ms |
35888 KB |
Output is correct |
41 |
Correct |
402 ms |
36208 KB |
Output is correct |
42 |
Correct |
355 ms |
36212 KB |
Output is correct |
43 |
Correct |
383 ms |
36460 KB |
Output is correct |
44 |
Correct |
355 ms |
36768 KB |
Output is correct |
45 |
Correct |
412 ms |
36788 KB |
Output is correct |
46 |
Correct |
449 ms |
36732 KB |
Output is correct |
47 |
Correct |
408 ms |
36704 KB |
Output is correct |
48 |
Correct |
464 ms |
36728 KB |
Output is correct |
49 |
Correct |
319 ms |
35460 KB |
Output is correct |
50 |
Correct |
386 ms |
35540 KB |
Output is correct |
51 |
Correct |
405 ms |
35256 KB |
Output is correct |
52 |
Correct |
386 ms |
35328 KB |
Output is correct |
53 |
Correct |
357 ms |
35568 KB |
Output is correct |
54 |
Correct |
351 ms |
35628 KB |
Output is correct |
55 |
Correct |
320 ms |
33472 KB |
Output is correct |
56 |
Correct |
298 ms |
34552 KB |
Output is correct |
57 |
Correct |
2365 ms |
97512 KB |
Output is correct |
58 |
Correct |
2484 ms |
97548 KB |
Output is correct |
59 |
Correct |
2199 ms |
95940 KB |
Output is correct |
60 |
Correct |
2300 ms |
95940 KB |
Output is correct |
61 |
Correct |
2448 ms |
95888 KB |
Output is correct |
62 |
Correct |
2178 ms |
95840 KB |
Output is correct |
63 |
Correct |
1737 ms |
84552 KB |
Output is correct |
64 |
Correct |
1807 ms |
84480 KB |
Output is correct |
65 |
Correct |
2111 ms |
87652 KB |
Output is correct |
66 |
Correct |
2003 ms |
87608 KB |
Output is correct |
67 |
Correct |
2041 ms |
87724 KB |
Output is correct |
68 |
Correct |
2077 ms |
89344 KB |
Output is correct |
69 |
Correct |
2141 ms |
89336 KB |
Output is correct |
70 |
Correct |
2174 ms |
88936 KB |
Output is correct |
71 |
Correct |
2240 ms |
88936 KB |
Output is correct |
72 |
Correct |
2121 ms |
88952 KB |
Output is correct |
73 |
Correct |
1738 ms |
80460 KB |
Output is correct |
74 |
Correct |
1694 ms |
81548 KB |
Output is correct |
75 |
Correct |
1546 ms |
80712 KB |
Output is correct |
76 |
Correct |
1519 ms |
80696 KB |
Output is correct |
77 |
Correct |
1518 ms |
80556 KB |
Output is correct |
78 |
Correct |
1662 ms |
84184 KB |
Output is correct |
79 |
Correct |
1339 ms |
70736 KB |
Output is correct |
80 |
Correct |
1566 ms |
78724 KB |
Output is correct |