#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
49756 KB |
Output is correct |
2 |
Correct |
7 ms |
49816 KB |
Output is correct |
3 |
Correct |
7 ms |
49908 KB |
Output is correct |
4 |
Correct |
7 ms |
49844 KB |
Output is correct |
5 |
Correct |
7 ms |
49756 KB |
Output is correct |
6 |
Correct |
7 ms |
49924 KB |
Output is correct |
7 |
Correct |
7 ms |
49756 KB |
Output is correct |
8 |
Correct |
8 ms |
49756 KB |
Output is correct |
9 |
Correct |
7 ms |
49864 KB |
Output is correct |
10 |
Correct |
7 ms |
49752 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
49756 KB |
Output is correct |
2 |
Correct |
7 ms |
49816 KB |
Output is correct |
3 |
Correct |
7 ms |
49908 KB |
Output is correct |
4 |
Correct |
7 ms |
49844 KB |
Output is correct |
5 |
Correct |
7 ms |
49756 KB |
Output is correct |
6 |
Correct |
7 ms |
49924 KB |
Output is correct |
7 |
Correct |
7 ms |
49756 KB |
Output is correct |
8 |
Correct |
8 ms |
49756 KB |
Output is correct |
9 |
Correct |
7 ms |
49864 KB |
Output is correct |
10 |
Correct |
7 ms |
49752 KB |
Output is correct |
11 |
Correct |
11 ms |
49756 KB |
Output is correct |
12 |
Correct |
8 ms |
50012 KB |
Output is correct |
13 |
Correct |
9 ms |
50012 KB |
Output is correct |
14 |
Correct |
10 ms |
50008 KB |
Output is correct |
15 |
Correct |
10 ms |
49956 KB |
Output is correct |
16 |
Correct |
10 ms |
50012 KB |
Output is correct |
17 |
Correct |
10 ms |
49880 KB |
Output is correct |
18 |
Correct |
8 ms |
50012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
715 ms |
102016 KB |
Output is correct |
2 |
Correct |
703 ms |
101968 KB |
Output is correct |
3 |
Correct |
664 ms |
101972 KB |
Output is correct |
4 |
Correct |
659 ms |
102036 KB |
Output is correct |
5 |
Correct |
502 ms |
86984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
54868 KB |
Output is correct |
2 |
Correct |
58 ms |
54740 KB |
Output is correct |
3 |
Correct |
39 ms |
52820 KB |
Output is correct |
4 |
Correct |
42 ms |
53072 KB |
Output is correct |
5 |
Correct |
41 ms |
53328 KB |
Output is correct |
6 |
Correct |
34 ms |
49752 KB |
Output is correct |
7 |
Correct |
33 ms |
49756 KB |
Output is correct |
8 |
Correct |
43 ms |
53056 KB |
Output is correct |
9 |
Correct |
30 ms |
51464 KB |
Output is correct |
10 |
Correct |
41 ms |
53136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
49756 KB |
Output is correct |
2 |
Correct |
7 ms |
49816 KB |
Output is correct |
3 |
Correct |
7 ms |
49908 KB |
Output is correct |
4 |
Correct |
7 ms |
49844 KB |
Output is correct |
5 |
Correct |
7 ms |
49756 KB |
Output is correct |
6 |
Correct |
7 ms |
49924 KB |
Output is correct |
7 |
Correct |
7 ms |
49756 KB |
Output is correct |
8 |
Correct |
8 ms |
49756 KB |
Output is correct |
9 |
Correct |
7 ms |
49864 KB |
Output is correct |
10 |
Correct |
7 ms |
49752 KB |
Output is correct |
11 |
Correct |
11 ms |
49756 KB |
Output is correct |
12 |
Correct |
8 ms |
50012 KB |
Output is correct |
13 |
Correct |
9 ms |
50012 KB |
Output is correct |
14 |
Correct |
10 ms |
50008 KB |
Output is correct |
15 |
Correct |
10 ms |
49956 KB |
Output is correct |
16 |
Correct |
10 ms |
50012 KB |
Output is correct |
17 |
Correct |
10 ms |
49880 KB |
Output is correct |
18 |
Correct |
8 ms |
50012 KB |
Output is correct |
19 |
Correct |
117 ms |
64084 KB |
Output is correct |
20 |
Correct |
121 ms |
64080 KB |
Output is correct |
21 |
Correct |
111 ms |
63572 KB |
Output is correct |
22 |
Correct |
103 ms |
63572 KB |
Output is correct |
23 |
Correct |
106 ms |
63600 KB |
Output is correct |
24 |
Correct |
74 ms |
58448 KB |
Output is correct |
25 |
Correct |
73 ms |
58448 KB |
Output is correct |
26 |
Correct |
81 ms |
59092 KB |
Output is correct |
27 |
Correct |
79 ms |
59216 KB |
Output is correct |
28 |
Correct |
83 ms |
59476 KB |
Output is correct |
29 |
Correct |
85 ms |
60752 KB |
Output is correct |
30 |
Correct |
87 ms |
60808 KB |
Output is correct |
31 |
Correct |
85 ms |
60756 KB |
Output is correct |
32 |
Correct |
84 ms |
60756 KB |
Output is correct |
33 |
Correct |
85 ms |
60624 KB |
Output is correct |
34 |
Correct |
68 ms |
57748 KB |
Output is correct |
35 |
Correct |
70 ms |
57684 KB |
Output is correct |
36 |
Correct |
70 ms |
57684 KB |
Output is correct |
37 |
Correct |
71 ms |
57676 KB |
Output is correct |
38 |
Correct |
71 ms |
57684 KB |
Output is correct |
39 |
Correct |
88 ms |
61192 KB |
Output is correct |
40 |
Correct |
73 ms |
58888 KB |
Output is correct |
41 |
Correct |
91 ms |
60368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
49756 KB |
Output is correct |
2 |
Correct |
7 ms |
49816 KB |
Output is correct |
3 |
Correct |
7 ms |
49908 KB |
Output is correct |
4 |
Correct |
7 ms |
49844 KB |
Output is correct |
5 |
Correct |
7 ms |
49756 KB |
Output is correct |
6 |
Correct |
7 ms |
49924 KB |
Output is correct |
7 |
Correct |
7 ms |
49756 KB |
Output is correct |
8 |
Correct |
8 ms |
49756 KB |
Output is correct |
9 |
Correct |
7 ms |
49864 KB |
Output is correct |
10 |
Correct |
7 ms |
49752 KB |
Output is correct |
11 |
Correct |
11 ms |
49756 KB |
Output is correct |
12 |
Correct |
8 ms |
50012 KB |
Output is correct |
13 |
Correct |
9 ms |
50012 KB |
Output is correct |
14 |
Correct |
10 ms |
50008 KB |
Output is correct |
15 |
Correct |
10 ms |
49956 KB |
Output is correct |
16 |
Correct |
10 ms |
50012 KB |
Output is correct |
17 |
Correct |
10 ms |
49880 KB |
Output is correct |
18 |
Correct |
8 ms |
50012 KB |
Output is correct |
19 |
Correct |
715 ms |
102016 KB |
Output is correct |
20 |
Correct |
703 ms |
101968 KB |
Output is correct |
21 |
Correct |
664 ms |
101972 KB |
Output is correct |
22 |
Correct |
659 ms |
102036 KB |
Output is correct |
23 |
Correct |
502 ms |
86984 KB |
Output is correct |
24 |
Correct |
52 ms |
54868 KB |
Output is correct |
25 |
Correct |
58 ms |
54740 KB |
Output is correct |
26 |
Correct |
39 ms |
52820 KB |
Output is correct |
27 |
Correct |
42 ms |
53072 KB |
Output is correct |
28 |
Correct |
41 ms |
53328 KB |
Output is correct |
29 |
Correct |
34 ms |
49752 KB |
Output is correct |
30 |
Correct |
33 ms |
49756 KB |
Output is correct |
31 |
Correct |
43 ms |
53056 KB |
Output is correct |
32 |
Correct |
30 ms |
51464 KB |
Output is correct |
33 |
Correct |
41 ms |
53136 KB |
Output is correct |
34 |
Correct |
117 ms |
64084 KB |
Output is correct |
35 |
Correct |
121 ms |
64080 KB |
Output is correct |
36 |
Correct |
111 ms |
63572 KB |
Output is correct |
37 |
Correct |
103 ms |
63572 KB |
Output is correct |
38 |
Correct |
106 ms |
63600 KB |
Output is correct |
39 |
Correct |
74 ms |
58448 KB |
Output is correct |
40 |
Correct |
73 ms |
58448 KB |
Output is correct |
41 |
Correct |
81 ms |
59092 KB |
Output is correct |
42 |
Correct |
79 ms |
59216 KB |
Output is correct |
43 |
Correct |
83 ms |
59476 KB |
Output is correct |
44 |
Correct |
85 ms |
60752 KB |
Output is correct |
45 |
Correct |
87 ms |
60808 KB |
Output is correct |
46 |
Correct |
85 ms |
60756 KB |
Output is correct |
47 |
Correct |
84 ms |
60756 KB |
Output is correct |
48 |
Correct |
85 ms |
60624 KB |
Output is correct |
49 |
Correct |
68 ms |
57748 KB |
Output is correct |
50 |
Correct |
70 ms |
57684 KB |
Output is correct |
51 |
Correct |
70 ms |
57684 KB |
Output is correct |
52 |
Correct |
71 ms |
57676 KB |
Output is correct |
53 |
Correct |
71 ms |
57684 KB |
Output is correct |
54 |
Correct |
88 ms |
61192 KB |
Output is correct |
55 |
Correct |
73 ms |
58888 KB |
Output is correct |
56 |
Correct |
91 ms |
60368 KB |
Output is correct |
57 |
Correct |
726 ms |
104016 KB |
Output is correct |
58 |
Correct |
716 ms |
104020 KB |
Output is correct |
59 |
Correct |
635 ms |
101972 KB |
Output is correct |
60 |
Correct |
650 ms |
102040 KB |
Output is correct |
61 |
Correct |
646 ms |
101972 KB |
Output is correct |
62 |
Correct |
654 ms |
101964 KB |
Output is correct |
63 |
Correct |
362 ms |
73924 KB |
Output is correct |
64 |
Correct |
349 ms |
74064 KB |
Output is correct |
65 |
Correct |
464 ms |
81492 KB |
Output is correct |
66 |
Correct |
453 ms |
81488 KB |
Output is correct |
67 |
Correct |
476 ms |
81748 KB |
Output is correct |
68 |
Correct |
569 ms |
87892 KB |
Output is correct |
69 |
Correct |
547 ms |
87892 KB |
Output is correct |
70 |
Correct |
517 ms |
86608 KB |
Output is correct |
71 |
Correct |
543 ms |
86612 KB |
Output is correct |
72 |
Correct |
572 ms |
86480 KB |
Output is correct |
73 |
Correct |
344 ms |
73040 KB |
Output is correct |
74 |
Correct |
350 ms |
72872 KB |
Output is correct |
75 |
Correct |
385 ms |
73112 KB |
Output is correct |
76 |
Correct |
336 ms |
72888 KB |
Output is correct |
77 |
Correct |
347 ms |
72792 KB |
Output is correct |
78 |
Correct |
562 ms |
89224 KB |
Output is correct |
79 |
Correct |
376 ms |
78400 KB |
Output is correct |
80 |
Correct |
512 ms |
88508 KB |
Output is correct |