#include "bits/stdc++.h"
using namespace std;
using ll = long long;
const int MAXN = 1e6 + 5;
int seg[MAXN * 4];
int w[MAXN], ans[MAXN];
void update(int v, int tl, int tr, int pos, int val)
{
if(tl == tr)
{
seg[v] = max(seg[v], val);
return;
}
int tm = (tl + tr) / 2;
if(pos <= tm)
update(2 * v, tl, tm, pos, val);
else
update(2 * v + 1, tm + 1, tr, pos, val);
seg[v] = max(seg[v * 2], seg[v * 2 + 1]);
}
int get(int v, int tl, int tr, int l, int r)
{
if(l > r)
return 0;
if(l == tl && r == tr)
{
return seg[v];
}
int tm = (tl + tr) / 2;
return max(get(2 * v, tl, tm, l, min(r, tm)), get(2 * v + 1, tm + 1, tr, max(tm + 1, l), r));
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> w[i];
vector< vector < pair<pair<int, int>, int> > > q(n+5);
for(int i = 1; i <= m; i++)
{
int l, r, k;
cin >> l >> r >> k;
q[l].push_back({{r, k}, i});
}
vector<int> curr;
for(int i = n; i >= 1; i--)
{
while(!curr.empty() && w[curr.back()] <= w[i])
{
if(w[curr.back()] != w[i])
update(1, 1, n, curr.back(), w[curr.back()] + w[i]);
curr.pop_back();
}
curr.push_back(i);
for(pair< pair<int, int>, int> elem : q[i])
{
int temp = get(1, 1, n, i, elem.first.first);
if(temp <= elem.first.second)
ans[elem.second] = 1;
else
ans[elem.second] = 0;
}
}
for(int i = 1; i <= m; i++)
cout << ans[i] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
5 ms |
732 KB |
Output is correct |
15 |
Correct |
5 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
18 |
Correct |
3 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1343 ms |
65260 KB |
Output is correct |
2 |
Correct |
1302 ms |
63744 KB |
Output is correct |
3 |
Correct |
1312 ms |
65344 KB |
Output is correct |
4 |
Correct |
1353 ms |
65280 KB |
Output is correct |
5 |
Correct |
1174 ms |
61100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
7796 KB |
Output is correct |
2 |
Correct |
83 ms |
7584 KB |
Output is correct |
3 |
Correct |
77 ms |
6608 KB |
Output is correct |
4 |
Correct |
74 ms |
6680 KB |
Output is correct |
5 |
Correct |
76 ms |
6772 KB |
Output is correct |
6 |
Correct |
76 ms |
6400 KB |
Output is correct |
7 |
Correct |
74 ms |
6448 KB |
Output is correct |
8 |
Correct |
62 ms |
6400 KB |
Output is correct |
9 |
Correct |
34 ms |
3300 KB |
Output is correct |
10 |
Correct |
60 ms |
6428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
5 ms |
732 KB |
Output is correct |
15 |
Correct |
5 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
18 |
Correct |
3 ms |
724 KB |
Output is correct |
19 |
Correct |
257 ms |
17144 KB |
Output is correct |
20 |
Correct |
204 ms |
17264 KB |
Output is correct |
21 |
Correct |
185 ms |
16852 KB |
Output is correct |
22 |
Correct |
220 ms |
16740 KB |
Output is correct |
23 |
Correct |
180 ms |
16776 KB |
Output is correct |
24 |
Correct |
187 ms |
15568 KB |
Output is correct |
25 |
Correct |
150 ms |
15572 KB |
Output is correct |
26 |
Correct |
182 ms |
15612 KB |
Output is correct |
27 |
Correct |
206 ms |
15796 KB |
Output is correct |
28 |
Correct |
175 ms |
15684 KB |
Output is correct |
29 |
Correct |
186 ms |
16084 KB |
Output is correct |
30 |
Correct |
194 ms |
16024 KB |
Output is correct |
31 |
Correct |
188 ms |
16148 KB |
Output is correct |
32 |
Correct |
192 ms |
16076 KB |
Output is correct |
33 |
Correct |
192 ms |
15972 KB |
Output is correct |
34 |
Correct |
161 ms |
15188 KB |
Output is correct |
35 |
Correct |
179 ms |
15468 KB |
Output is correct |
36 |
Correct |
146 ms |
15768 KB |
Output is correct |
37 |
Correct |
158 ms |
15940 KB |
Output is correct |
38 |
Correct |
175 ms |
16576 KB |
Output is correct |
39 |
Correct |
157 ms |
17724 KB |
Output is correct |
40 |
Correct |
132 ms |
14108 KB |
Output is correct |
41 |
Correct |
163 ms |
15488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
3 ms |
724 KB |
Output is correct |
14 |
Correct |
5 ms |
732 KB |
Output is correct |
15 |
Correct |
5 ms |
596 KB |
Output is correct |
16 |
Correct |
3 ms |
596 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
18 |
Correct |
3 ms |
724 KB |
Output is correct |
19 |
Correct |
1343 ms |
65260 KB |
Output is correct |
20 |
Correct |
1302 ms |
63744 KB |
Output is correct |
21 |
Correct |
1312 ms |
65344 KB |
Output is correct |
22 |
Correct |
1353 ms |
65280 KB |
Output is correct |
23 |
Correct |
1174 ms |
61100 KB |
Output is correct |
24 |
Correct |
96 ms |
7796 KB |
Output is correct |
25 |
Correct |
83 ms |
7584 KB |
Output is correct |
26 |
Correct |
77 ms |
6608 KB |
Output is correct |
27 |
Correct |
74 ms |
6680 KB |
Output is correct |
28 |
Correct |
76 ms |
6772 KB |
Output is correct |
29 |
Correct |
76 ms |
6400 KB |
Output is correct |
30 |
Correct |
74 ms |
6448 KB |
Output is correct |
31 |
Correct |
62 ms |
6400 KB |
Output is correct |
32 |
Correct |
34 ms |
3300 KB |
Output is correct |
33 |
Correct |
60 ms |
6428 KB |
Output is correct |
34 |
Correct |
257 ms |
17144 KB |
Output is correct |
35 |
Correct |
204 ms |
17264 KB |
Output is correct |
36 |
Correct |
185 ms |
16852 KB |
Output is correct |
37 |
Correct |
220 ms |
16740 KB |
Output is correct |
38 |
Correct |
180 ms |
16776 KB |
Output is correct |
39 |
Correct |
187 ms |
15568 KB |
Output is correct |
40 |
Correct |
150 ms |
15572 KB |
Output is correct |
41 |
Correct |
182 ms |
15612 KB |
Output is correct |
42 |
Correct |
206 ms |
15796 KB |
Output is correct |
43 |
Correct |
175 ms |
15684 KB |
Output is correct |
44 |
Correct |
186 ms |
16084 KB |
Output is correct |
45 |
Correct |
194 ms |
16024 KB |
Output is correct |
46 |
Correct |
188 ms |
16148 KB |
Output is correct |
47 |
Correct |
192 ms |
16076 KB |
Output is correct |
48 |
Correct |
192 ms |
15972 KB |
Output is correct |
49 |
Correct |
161 ms |
15188 KB |
Output is correct |
50 |
Correct |
179 ms |
15468 KB |
Output is correct |
51 |
Correct |
146 ms |
15768 KB |
Output is correct |
52 |
Correct |
158 ms |
15940 KB |
Output is correct |
53 |
Correct |
175 ms |
16576 KB |
Output is correct |
54 |
Correct |
157 ms |
17724 KB |
Output is correct |
55 |
Correct |
132 ms |
14108 KB |
Output is correct |
56 |
Correct |
163 ms |
15488 KB |
Output is correct |
57 |
Correct |
1547 ms |
69760 KB |
Output is correct |
58 |
Correct |
1419 ms |
69820 KB |
Output is correct |
59 |
Correct |
1263 ms |
67956 KB |
Output is correct |
60 |
Correct |
1210 ms |
67788 KB |
Output is correct |
61 |
Correct |
1209 ms |
67792 KB |
Output is correct |
62 |
Correct |
1190 ms |
68008 KB |
Output is correct |
63 |
Correct |
789 ms |
59708 KB |
Output is correct |
64 |
Correct |
786 ms |
57972 KB |
Output is correct |
65 |
Correct |
979 ms |
61732 KB |
Output is correct |
66 |
Correct |
1034 ms |
61740 KB |
Output is correct |
67 |
Correct |
1029 ms |
61820 KB |
Output is correct |
68 |
Correct |
1090 ms |
63740 KB |
Output is correct |
69 |
Correct |
1101 ms |
63784 KB |
Output is correct |
70 |
Correct |
1057 ms |
63340 KB |
Output is correct |
71 |
Correct |
1077 ms |
63296 KB |
Output is correct |
72 |
Correct |
1062 ms |
63320 KB |
Output is correct |
73 |
Correct |
695 ms |
57144 KB |
Output is correct |
74 |
Correct |
752 ms |
57020 KB |
Output is correct |
75 |
Correct |
708 ms |
57072 KB |
Output is correct |
76 |
Correct |
686 ms |
53572 KB |
Output is correct |
77 |
Correct |
695 ms |
53748 KB |
Output is correct |
78 |
Correct |
895 ms |
59732 KB |
Output is correct |
79 |
Correct |
620 ms |
41876 KB |
Output is correct |
80 |
Correct |
792 ms |
54760 KB |
Output is correct |