#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
class segment_tree
{
#define lc id << 1
#define rc id << 1 | 1
private:
vector<int> ST; int n;
void update(int id, int l, int r, int pos, int val)
{
if(l > pos || r < pos) return;
if(l == r){
ST[id] = max(ST[id], val);
return;
}
int mid = (l + r) / 2;
update(lc, l, mid, pos, val); update(rc, mid + 1, r, pos, val);
ST[id] = max(ST[lc], ST[rc]);
}
int get(int id, int l, int r, int L, int R)
{
if(R < l || r < L) return -2e9;
if(L <= l && r <= R) return ST[id];
int mid = (l + r) / 2;
return max(get(lc, l, mid, L, R), get(rc, mid + 1, r, L, R));
}
public:
void init(int _n)
{
n = _n;
ST.assign(4 * n + 5, 0);
}
void update(int p, int v)
{
update(1, 1, n, p, v);
}
int get(int l, int r)
{
return get(1, 1, n, l, r);
}
#undef lc
#undef rc
}tr;
const int maxn = 1e6 + 5;
int N, Q, a[maxn], l[maxn], r[maxn], k[maxn], res[maxn];
vector<int> query[maxn], add[maxn];
vector<int> st;
signed main(void)
{
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("A.INP", "r", stdin);
freopen("A.OUT", "w", stdout);
#endif // LOCAL
cin >> N >> Q;
for(int i = 1; i <= N; ++i){
cin >> a[i];
while(st.size() && a[st.back()] <= a[i]) st.pop_back();
if(st.size()) add[st.back()].pb(i);
st.pb(i);
}
for(int i = 1; i <= Q; ++i){
cin >> l[i] >> r[i] >> k[i];
query[l[i]].eb(i);
}
tr.init(N);
for(int i = N; i >= 1; --i){
for(int j : add[i]) tr.update(j, a[i] + a[j]);
for(int id : query[i]){
res[id] = (tr.get(l[id], r[id]) <= k[id]);
}
}
for(int i = 1; i <= Q; ++i)
cout << res[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
47360 KB |
Output is correct |
2 |
Correct |
30 ms |
47360 KB |
Output is correct |
3 |
Correct |
36 ms |
47360 KB |
Output is correct |
4 |
Correct |
30 ms |
47360 KB |
Output is correct |
5 |
Correct |
30 ms |
47360 KB |
Output is correct |
6 |
Correct |
35 ms |
47360 KB |
Output is correct |
7 |
Correct |
35 ms |
47352 KB |
Output is correct |
8 |
Correct |
31 ms |
47360 KB |
Output is correct |
9 |
Correct |
30 ms |
47360 KB |
Output is correct |
10 |
Correct |
30 ms |
47488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
47360 KB |
Output is correct |
2 |
Correct |
30 ms |
47360 KB |
Output is correct |
3 |
Correct |
36 ms |
47360 KB |
Output is correct |
4 |
Correct |
30 ms |
47360 KB |
Output is correct |
5 |
Correct |
30 ms |
47360 KB |
Output is correct |
6 |
Correct |
35 ms |
47360 KB |
Output is correct |
7 |
Correct |
35 ms |
47352 KB |
Output is correct |
8 |
Correct |
31 ms |
47360 KB |
Output is correct |
9 |
Correct |
30 ms |
47360 KB |
Output is correct |
10 |
Correct |
30 ms |
47488 KB |
Output is correct |
11 |
Correct |
33 ms |
47616 KB |
Output is correct |
12 |
Correct |
33 ms |
47744 KB |
Output is correct |
13 |
Correct |
34 ms |
47744 KB |
Output is correct |
14 |
Correct |
36 ms |
47872 KB |
Output is correct |
15 |
Correct |
35 ms |
47864 KB |
Output is correct |
16 |
Correct |
35 ms |
47736 KB |
Output is correct |
17 |
Correct |
32 ms |
47744 KB |
Output is correct |
18 |
Correct |
38 ms |
47744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1917 ms |
150648 KB |
Output is correct |
2 |
Correct |
1915 ms |
151672 KB |
Output is correct |
3 |
Correct |
2258 ms |
151544 KB |
Output is correct |
4 |
Correct |
2215 ms |
151684 KB |
Output is correct |
5 |
Correct |
1585 ms |
135416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
157 ms |
56696 KB |
Output is correct |
2 |
Correct |
141 ms |
55672 KB |
Output is correct |
3 |
Correct |
123 ms |
54780 KB |
Output is correct |
4 |
Correct |
138 ms |
55032 KB |
Output is correct |
5 |
Correct |
125 ms |
55032 KB |
Output is correct |
6 |
Correct |
106 ms |
53600 KB |
Output is correct |
7 |
Correct |
100 ms |
53496 KB |
Output is correct |
8 |
Correct |
124 ms |
54388 KB |
Output is correct |
9 |
Correct |
75 ms |
50932 KB |
Output is correct |
10 |
Correct |
126 ms |
54260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
47360 KB |
Output is correct |
2 |
Correct |
30 ms |
47360 KB |
Output is correct |
3 |
Correct |
36 ms |
47360 KB |
Output is correct |
4 |
Correct |
30 ms |
47360 KB |
Output is correct |
5 |
Correct |
30 ms |
47360 KB |
Output is correct |
6 |
Correct |
35 ms |
47360 KB |
Output is correct |
7 |
Correct |
35 ms |
47352 KB |
Output is correct |
8 |
Correct |
31 ms |
47360 KB |
Output is correct |
9 |
Correct |
30 ms |
47360 KB |
Output is correct |
10 |
Correct |
30 ms |
47488 KB |
Output is correct |
11 |
Correct |
33 ms |
47616 KB |
Output is correct |
12 |
Correct |
33 ms |
47744 KB |
Output is correct |
13 |
Correct |
34 ms |
47744 KB |
Output is correct |
14 |
Correct |
36 ms |
47872 KB |
Output is correct |
15 |
Correct |
35 ms |
47864 KB |
Output is correct |
16 |
Correct |
35 ms |
47736 KB |
Output is correct |
17 |
Correct |
32 ms |
47744 KB |
Output is correct |
18 |
Correct |
38 ms |
47744 KB |
Output is correct |
19 |
Correct |
369 ms |
68604 KB |
Output is correct |
20 |
Correct |
351 ms |
68604 KB |
Output is correct |
21 |
Correct |
270 ms |
66168 KB |
Output is correct |
22 |
Correct |
275 ms |
66168 KB |
Output is correct |
23 |
Correct |
304 ms |
66296 KB |
Output is correct |
24 |
Correct |
221 ms |
62712 KB |
Output is correct |
25 |
Correct |
215 ms |
62712 KB |
Output is correct |
26 |
Correct |
279 ms |
63680 KB |
Output is correct |
27 |
Correct |
287 ms |
63736 KB |
Output is correct |
28 |
Correct |
256 ms |
64120 KB |
Output is correct |
29 |
Correct |
272 ms |
65400 KB |
Output is correct |
30 |
Correct |
332 ms |
65400 KB |
Output is correct |
31 |
Correct |
271 ms |
65272 KB |
Output is correct |
32 |
Correct |
270 ms |
65272 KB |
Output is correct |
33 |
Correct |
304 ms |
65272 KB |
Output is correct |
34 |
Correct |
204 ms |
62200 KB |
Output is correct |
35 |
Correct |
195 ms |
62204 KB |
Output is correct |
36 |
Correct |
199 ms |
61944 KB |
Output is correct |
37 |
Correct |
195 ms |
61944 KB |
Output is correct |
38 |
Correct |
202 ms |
62200 KB |
Output is correct |
39 |
Correct |
247 ms |
63604 KB |
Output is correct |
40 |
Correct |
212 ms |
60272 KB |
Output is correct |
41 |
Correct |
229 ms |
62836 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
29 ms |
47360 KB |
Output is correct |
2 |
Correct |
30 ms |
47360 KB |
Output is correct |
3 |
Correct |
36 ms |
47360 KB |
Output is correct |
4 |
Correct |
30 ms |
47360 KB |
Output is correct |
5 |
Correct |
30 ms |
47360 KB |
Output is correct |
6 |
Correct |
35 ms |
47360 KB |
Output is correct |
7 |
Correct |
35 ms |
47352 KB |
Output is correct |
8 |
Correct |
31 ms |
47360 KB |
Output is correct |
9 |
Correct |
30 ms |
47360 KB |
Output is correct |
10 |
Correct |
30 ms |
47488 KB |
Output is correct |
11 |
Correct |
33 ms |
47616 KB |
Output is correct |
12 |
Correct |
33 ms |
47744 KB |
Output is correct |
13 |
Correct |
34 ms |
47744 KB |
Output is correct |
14 |
Correct |
36 ms |
47872 KB |
Output is correct |
15 |
Correct |
35 ms |
47864 KB |
Output is correct |
16 |
Correct |
35 ms |
47736 KB |
Output is correct |
17 |
Correct |
32 ms |
47744 KB |
Output is correct |
18 |
Correct |
38 ms |
47744 KB |
Output is correct |
19 |
Correct |
1917 ms |
150648 KB |
Output is correct |
20 |
Correct |
1915 ms |
151672 KB |
Output is correct |
21 |
Correct |
2258 ms |
151544 KB |
Output is correct |
22 |
Correct |
2215 ms |
151684 KB |
Output is correct |
23 |
Correct |
1585 ms |
135416 KB |
Output is correct |
24 |
Correct |
157 ms |
56696 KB |
Output is correct |
25 |
Correct |
141 ms |
55672 KB |
Output is correct |
26 |
Correct |
123 ms |
54780 KB |
Output is correct |
27 |
Correct |
138 ms |
55032 KB |
Output is correct |
28 |
Correct |
125 ms |
55032 KB |
Output is correct |
29 |
Correct |
106 ms |
53600 KB |
Output is correct |
30 |
Correct |
100 ms |
53496 KB |
Output is correct |
31 |
Correct |
124 ms |
54388 KB |
Output is correct |
32 |
Correct |
75 ms |
50932 KB |
Output is correct |
33 |
Correct |
126 ms |
54260 KB |
Output is correct |
34 |
Correct |
369 ms |
68604 KB |
Output is correct |
35 |
Correct |
351 ms |
68604 KB |
Output is correct |
36 |
Correct |
270 ms |
66168 KB |
Output is correct |
37 |
Correct |
275 ms |
66168 KB |
Output is correct |
38 |
Correct |
304 ms |
66296 KB |
Output is correct |
39 |
Correct |
221 ms |
62712 KB |
Output is correct |
40 |
Correct |
215 ms |
62712 KB |
Output is correct |
41 |
Correct |
279 ms |
63680 KB |
Output is correct |
42 |
Correct |
287 ms |
63736 KB |
Output is correct |
43 |
Correct |
256 ms |
64120 KB |
Output is correct |
44 |
Correct |
272 ms |
65400 KB |
Output is correct |
45 |
Correct |
332 ms |
65400 KB |
Output is correct |
46 |
Correct |
271 ms |
65272 KB |
Output is correct |
47 |
Correct |
270 ms |
65272 KB |
Output is correct |
48 |
Correct |
304 ms |
65272 KB |
Output is correct |
49 |
Correct |
204 ms |
62200 KB |
Output is correct |
50 |
Correct |
195 ms |
62204 KB |
Output is correct |
51 |
Correct |
199 ms |
61944 KB |
Output is correct |
52 |
Correct |
195 ms |
61944 KB |
Output is correct |
53 |
Correct |
202 ms |
62200 KB |
Output is correct |
54 |
Correct |
247 ms |
63604 KB |
Output is correct |
55 |
Correct |
212 ms |
60272 KB |
Output is correct |
56 |
Correct |
229 ms |
62836 KB |
Output is correct |
57 |
Correct |
1957 ms |
154232 KB |
Output is correct |
58 |
Correct |
1877 ms |
154232 KB |
Output is correct |
59 |
Correct |
2120 ms |
148616 KB |
Output is correct |
60 |
Correct |
2072 ms |
148600 KB |
Output is correct |
61 |
Correct |
1840 ms |
148600 KB |
Output is correct |
62 |
Correct |
1793 ms |
148600 KB |
Output is correct |
63 |
Correct |
1044 ms |
121988 KB |
Output is correct |
64 |
Correct |
1109 ms |
121976 KB |
Output is correct |
65 |
Correct |
1586 ms |
131496 KB |
Output is correct |
66 |
Correct |
1492 ms |
131536 KB |
Output is correct |
67 |
Correct |
1539 ms |
132088 KB |
Output is correct |
68 |
Correct |
1604 ms |
138116 KB |
Output is correct |
69 |
Correct |
1931 ms |
137976 KB |
Output is correct |
70 |
Correct |
1611 ms |
137208 KB |
Output is correct |
71 |
Correct |
1592 ms |
137208 KB |
Output is correct |
72 |
Correct |
1576 ms |
137208 KB |
Output is correct |
73 |
Correct |
1000 ms |
120440 KB |
Output is correct |
74 |
Correct |
1010 ms |
121336 KB |
Output is correct |
75 |
Correct |
1010 ms |
120312 KB |
Output is correct |
76 |
Correct |
979 ms |
120312 KB |
Output is correct |
77 |
Correct |
993 ms |
120392 KB |
Output is correct |
78 |
Correct |
1424 ms |
129912 KB |
Output is correct |
79 |
Correct |
1010 ms |
108648 KB |
Output is correct |
80 |
Correct |
1389 ms |
124776 KB |
Output is correct |