#include <bits/stdc++.h>
using namespace std;
int t[4000005], res[1000005], a[1000005];
vector<int> g[1000005];
struct QUERY
{
int r, x, num;
};
vector<QUERY> v[1000005];
void update(int v, int tl, int tr, int l, int r, int x)
{
if (l > r) return;
if (tl == l && tr == r)
{
t[v] = max(t[v], x);
return;
}
t[v * 2] = max(t[v * 2], t[v]);
t[v * 2 + 1] = max(t[v * 2 + 1], t[v]);
int mid = (tl + tr) / 2;
update(v * 2, tl, mid, l, min(r, mid), x);
update(v * 2 + 1, mid + 1, tr, max(l, mid + 1), r, x);
}
int sum(int v, int tl, int tr, int x)
{
if (tl == tr)
return t[v];
t[v * 2] = max(t[v * 2], t[v]);
t[v * 2 + 1] = max(t[v * 2 + 1], t[v]);
int mid = (tl + tr) / 2;
if (mid >= x) return sum(v * 2, tl, mid, x);
return sum(v * 2 + 1, mid + 1, tr, x);
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, q;
cin >> n >> q;
stack<pair<int, int>> s;
for (int i = 1; i <= n; i++)
{
cin >> a[i];
while (!s.empty() && (s.top()).first <= a[i])
s.pop();
if (!s.empty())
g[(s.top()).second].push_back(i);
s.push({a[i], i});
}
for (int i = 1; i <= q; i++)
{
int l, r, k;
cin >> l >> r >> k;
v[l].push_back({r, k, i});
}
for (int i = n; i >= 1; i--)
{
for (int w : g[i])
update(1, 1, n, w, n, a[i] + a[w]);
for (auto w : v[i])
if (sum(1, 1, n, w.r) <= w.x)
res[w.num] = 1;
}
for (int i = 1; i <= q; i++)
cout << res[i] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
49756 KB |
Output is correct |
2 |
Correct |
9 ms |
49752 KB |
Output is correct |
3 |
Correct |
8 ms |
49908 KB |
Output is correct |
4 |
Correct |
7 ms |
49752 KB |
Output is correct |
5 |
Correct |
7 ms |
49756 KB |
Output is correct |
6 |
Correct |
7 ms |
49756 KB |
Output is correct |
7 |
Correct |
7 ms |
49920 KB |
Output is correct |
8 |
Correct |
7 ms |
49756 KB |
Output is correct |
9 |
Correct |
7 ms |
49756 KB |
Output is correct |
10 |
Correct |
7 ms |
49752 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
49756 KB |
Output is correct |
2 |
Correct |
9 ms |
49752 KB |
Output is correct |
3 |
Correct |
8 ms |
49908 KB |
Output is correct |
4 |
Correct |
7 ms |
49752 KB |
Output is correct |
5 |
Correct |
7 ms |
49756 KB |
Output is correct |
6 |
Correct |
7 ms |
49756 KB |
Output is correct |
7 |
Correct |
7 ms |
49920 KB |
Output is correct |
8 |
Correct |
7 ms |
49756 KB |
Output is correct |
9 |
Correct |
7 ms |
49756 KB |
Output is correct |
10 |
Correct |
7 ms |
49752 KB |
Output is correct |
11 |
Correct |
8 ms |
49756 KB |
Output is correct |
12 |
Correct |
9 ms |
50104 KB |
Output is correct |
13 |
Correct |
9 ms |
50012 KB |
Output is correct |
14 |
Correct |
10 ms |
50012 KB |
Output is correct |
15 |
Correct |
10 ms |
50008 KB |
Output is correct |
16 |
Correct |
9 ms |
50076 KB |
Output is correct |
17 |
Correct |
8 ms |
50012 KB |
Output is correct |
18 |
Correct |
10 ms |
50012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
711 ms |
102020 KB |
Output is correct |
2 |
Correct |
717 ms |
102280 KB |
Output is correct |
3 |
Correct |
694 ms |
101968 KB |
Output is correct |
4 |
Correct |
654 ms |
101968 KB |
Output is correct |
5 |
Correct |
530 ms |
87216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
54 ms |
54864 KB |
Output is correct |
2 |
Correct |
52 ms |
54608 KB |
Output is correct |
3 |
Correct |
39 ms |
52820 KB |
Output is correct |
4 |
Correct |
40 ms |
53084 KB |
Output is correct |
5 |
Correct |
41 ms |
53332 KB |
Output is correct |
6 |
Correct |
34 ms |
49756 KB |
Output is correct |
7 |
Correct |
33 ms |
49748 KB |
Output is correct |
8 |
Correct |
44 ms |
53132 KB |
Output is correct |
9 |
Correct |
25 ms |
51476 KB |
Output is correct |
10 |
Correct |
41 ms |
52988 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
49756 KB |
Output is correct |
2 |
Correct |
9 ms |
49752 KB |
Output is correct |
3 |
Correct |
8 ms |
49908 KB |
Output is correct |
4 |
Correct |
7 ms |
49752 KB |
Output is correct |
5 |
Correct |
7 ms |
49756 KB |
Output is correct |
6 |
Correct |
7 ms |
49756 KB |
Output is correct |
7 |
Correct |
7 ms |
49920 KB |
Output is correct |
8 |
Correct |
7 ms |
49756 KB |
Output is correct |
9 |
Correct |
7 ms |
49756 KB |
Output is correct |
10 |
Correct |
7 ms |
49752 KB |
Output is correct |
11 |
Correct |
8 ms |
49756 KB |
Output is correct |
12 |
Correct |
9 ms |
50104 KB |
Output is correct |
13 |
Correct |
9 ms |
50012 KB |
Output is correct |
14 |
Correct |
10 ms |
50012 KB |
Output is correct |
15 |
Correct |
10 ms |
50008 KB |
Output is correct |
16 |
Correct |
9 ms |
50076 KB |
Output is correct |
17 |
Correct |
8 ms |
50012 KB |
Output is correct |
18 |
Correct |
10 ms |
50012 KB |
Output is correct |
19 |
Correct |
126 ms |
64020 KB |
Output is correct |
20 |
Correct |
114 ms |
64152 KB |
Output is correct |
21 |
Correct |
102 ms |
63572 KB |
Output is correct |
22 |
Correct |
103 ms |
63484 KB |
Output is correct |
23 |
Correct |
109 ms |
63572 KB |
Output is correct |
24 |
Correct |
73 ms |
58328 KB |
Output is correct |
25 |
Correct |
83 ms |
58360 KB |
Output is correct |
26 |
Correct |
82 ms |
59052 KB |
Output is correct |
27 |
Correct |
79 ms |
59220 KB |
Output is correct |
28 |
Correct |
91 ms |
59476 KB |
Output is correct |
29 |
Correct |
85 ms |
60788 KB |
Output is correct |
30 |
Correct |
104 ms |
60736 KB |
Output is correct |
31 |
Correct |
86 ms |
60752 KB |
Output is correct |
32 |
Correct |
84 ms |
60572 KB |
Output is correct |
33 |
Correct |
85 ms |
60760 KB |
Output is correct |
34 |
Correct |
68 ms |
57684 KB |
Output is correct |
35 |
Correct |
82 ms |
57684 KB |
Output is correct |
36 |
Correct |
69 ms |
57624 KB |
Output is correct |
37 |
Correct |
68 ms |
57684 KB |
Output is correct |
38 |
Correct |
68 ms |
57664 KB |
Output is correct |
39 |
Correct |
83 ms |
61236 KB |
Output is correct |
40 |
Correct |
80 ms |
58884 KB |
Output is correct |
41 |
Correct |
86 ms |
60492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
49756 KB |
Output is correct |
2 |
Correct |
9 ms |
49752 KB |
Output is correct |
3 |
Correct |
8 ms |
49908 KB |
Output is correct |
4 |
Correct |
7 ms |
49752 KB |
Output is correct |
5 |
Correct |
7 ms |
49756 KB |
Output is correct |
6 |
Correct |
7 ms |
49756 KB |
Output is correct |
7 |
Correct |
7 ms |
49920 KB |
Output is correct |
8 |
Correct |
7 ms |
49756 KB |
Output is correct |
9 |
Correct |
7 ms |
49756 KB |
Output is correct |
10 |
Correct |
7 ms |
49752 KB |
Output is correct |
11 |
Correct |
8 ms |
49756 KB |
Output is correct |
12 |
Correct |
9 ms |
50104 KB |
Output is correct |
13 |
Correct |
9 ms |
50012 KB |
Output is correct |
14 |
Correct |
10 ms |
50012 KB |
Output is correct |
15 |
Correct |
10 ms |
50008 KB |
Output is correct |
16 |
Correct |
9 ms |
50076 KB |
Output is correct |
17 |
Correct |
8 ms |
50012 KB |
Output is correct |
18 |
Correct |
10 ms |
50012 KB |
Output is correct |
19 |
Correct |
711 ms |
102020 KB |
Output is correct |
20 |
Correct |
717 ms |
102280 KB |
Output is correct |
21 |
Correct |
694 ms |
101968 KB |
Output is correct |
22 |
Correct |
654 ms |
101968 KB |
Output is correct |
23 |
Correct |
530 ms |
87216 KB |
Output is correct |
24 |
Correct |
54 ms |
54864 KB |
Output is correct |
25 |
Correct |
52 ms |
54608 KB |
Output is correct |
26 |
Correct |
39 ms |
52820 KB |
Output is correct |
27 |
Correct |
40 ms |
53084 KB |
Output is correct |
28 |
Correct |
41 ms |
53332 KB |
Output is correct |
29 |
Correct |
34 ms |
49756 KB |
Output is correct |
30 |
Correct |
33 ms |
49748 KB |
Output is correct |
31 |
Correct |
44 ms |
53132 KB |
Output is correct |
32 |
Correct |
25 ms |
51476 KB |
Output is correct |
33 |
Correct |
41 ms |
52988 KB |
Output is correct |
34 |
Correct |
126 ms |
64020 KB |
Output is correct |
35 |
Correct |
114 ms |
64152 KB |
Output is correct |
36 |
Correct |
102 ms |
63572 KB |
Output is correct |
37 |
Correct |
103 ms |
63484 KB |
Output is correct |
38 |
Correct |
109 ms |
63572 KB |
Output is correct |
39 |
Correct |
73 ms |
58328 KB |
Output is correct |
40 |
Correct |
83 ms |
58360 KB |
Output is correct |
41 |
Correct |
82 ms |
59052 KB |
Output is correct |
42 |
Correct |
79 ms |
59220 KB |
Output is correct |
43 |
Correct |
91 ms |
59476 KB |
Output is correct |
44 |
Correct |
85 ms |
60788 KB |
Output is correct |
45 |
Correct |
104 ms |
60736 KB |
Output is correct |
46 |
Correct |
86 ms |
60752 KB |
Output is correct |
47 |
Correct |
84 ms |
60572 KB |
Output is correct |
48 |
Correct |
85 ms |
60760 KB |
Output is correct |
49 |
Correct |
68 ms |
57684 KB |
Output is correct |
50 |
Correct |
82 ms |
57684 KB |
Output is correct |
51 |
Correct |
69 ms |
57624 KB |
Output is correct |
52 |
Correct |
68 ms |
57684 KB |
Output is correct |
53 |
Correct |
68 ms |
57664 KB |
Output is correct |
54 |
Correct |
83 ms |
61236 KB |
Output is correct |
55 |
Correct |
80 ms |
58884 KB |
Output is correct |
56 |
Correct |
86 ms |
60492 KB |
Output is correct |
57 |
Correct |
697 ms |
104016 KB |
Output is correct |
58 |
Correct |
710 ms |
104020 KB |
Output is correct |
59 |
Correct |
644 ms |
102132 KB |
Output is correct |
60 |
Correct |
625 ms |
102116 KB |
Output is correct |
61 |
Correct |
615 ms |
101928 KB |
Output is correct |
62 |
Correct |
609 ms |
101972 KB |
Output is correct |
63 |
Correct |
333 ms |
73936 KB |
Output is correct |
64 |
Correct |
349 ms |
74068 KB |
Output is correct |
65 |
Correct |
467 ms |
81596 KB |
Output is correct |
66 |
Correct |
468 ms |
81612 KB |
Output is correct |
67 |
Correct |
455 ms |
81756 KB |
Output is correct |
68 |
Correct |
530 ms |
87892 KB |
Output is correct |
69 |
Correct |
539 ms |
87752 KB |
Output is correct |
70 |
Correct |
540 ms |
86608 KB |
Output is correct |
71 |
Correct |
526 ms |
86608 KB |
Output is correct |
72 |
Correct |
522 ms |
86612 KB |
Output is correct |
73 |
Correct |
315 ms |
72828 KB |
Output is correct |
74 |
Correct |
323 ms |
72784 KB |
Output is correct |
75 |
Correct |
312 ms |
72976 KB |
Output is correct |
76 |
Correct |
313 ms |
72780 KB |
Output is correct |
77 |
Correct |
318 ms |
72916 KB |
Output is correct |
78 |
Correct |
478 ms |
89340 KB |
Output is correct |
79 |
Correct |
343 ms |
78396 KB |
Output is correct |
80 |
Correct |
479 ms |
86720 KB |
Output is correct |