#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 1e6 + 10;
int n, m, w[maxn];
int tree[4 * maxn];
void update(int root, int left, int right, int pivot, int val)
{
if (left == right)
{
tree[root] = max(tree[root] , val);
return;
}
int mid = (left + right) / 2;
if (pivot <= mid)
update(root * 2, left, mid, pivot, val);
else
update(root * 2 + 1, mid + 1, right, pivot, val);
tree[root] = max(tree[root * 2], tree[root * 2 + 1]);
}
int query(int root, int left, int right, int qleft, int qright)
{
if (left > qright || right < qleft)
return 0;
if (left >= qleft && right <= qright)
return tree[root];
int mid = (left + right) / 2;
return max(query(root * 2, left, mid, qleft, qright),
query(root * 2 + 1, mid + 1, right, qleft, qright));
}
vector < pair < int, int > > spot[maxn];
struct query_data
{
int idx, r, k;
};
int ans[maxn];
vector < query_data > task[maxn];
void solve()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++)
{
cin >> w[i];
}
stack < int > st;
vector < pair < int, int > > fun;
for (int i = 1; i <= n; i ++)
{
while(!st.empty() && w[st.top()] <= w[i])
st.pop();
if (!st.empty())
{
fun.push_back({st.top(), i});
}
st.push(i);
}
for (pair < int, int > cur : fun)
{
spot[cur.first].push_back({cur.second, w[cur.first] + w[cur.second]});
}
for (int i = 1; i <= m; i ++)
{
query_data cur;
int sp;
cin >> sp >> cur.r >> cur.k;
cur.idx = i;
task[sp].push_back(cur);
}
for (int i = n; i > 0; i --)
{
for (pair < int, int > cur : spot[i])
{
update(1, 1, n, cur.first, cur.second);
}
for (query_data cur : task[i])
{
int mx = query(1, 1, n, i, cur.r);
ans[cur.idx] = (mx <= cur.k);
}
}
for (int i = 1; i <= m; i ++)
cout << ans[i] << endl;
}
int main()
{
speed();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
48472 KB |
Output is correct |
2 |
Correct |
9 ms |
48476 KB |
Output is correct |
3 |
Correct |
9 ms |
48612 KB |
Output is correct |
4 |
Correct |
9 ms |
48476 KB |
Output is correct |
5 |
Correct |
9 ms |
48568 KB |
Output is correct |
6 |
Correct |
9 ms |
48472 KB |
Output is correct |
7 |
Correct |
11 ms |
48476 KB |
Output is correct |
8 |
Correct |
9 ms |
48472 KB |
Output is correct |
9 |
Correct |
9 ms |
48600 KB |
Output is correct |
10 |
Correct |
8 ms |
48472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
48472 KB |
Output is correct |
2 |
Correct |
9 ms |
48476 KB |
Output is correct |
3 |
Correct |
9 ms |
48612 KB |
Output is correct |
4 |
Correct |
9 ms |
48476 KB |
Output is correct |
5 |
Correct |
9 ms |
48568 KB |
Output is correct |
6 |
Correct |
9 ms |
48472 KB |
Output is correct |
7 |
Correct |
11 ms |
48476 KB |
Output is correct |
8 |
Correct |
9 ms |
48472 KB |
Output is correct |
9 |
Correct |
9 ms |
48600 KB |
Output is correct |
10 |
Correct |
8 ms |
48472 KB |
Output is correct |
11 |
Correct |
13 ms |
48476 KB |
Output is correct |
12 |
Correct |
13 ms |
48584 KB |
Output is correct |
13 |
Correct |
12 ms |
48728 KB |
Output is correct |
14 |
Correct |
12 ms |
48732 KB |
Output is correct |
15 |
Correct |
12 ms |
48872 KB |
Output is correct |
16 |
Correct |
13 ms |
48732 KB |
Output is correct |
17 |
Correct |
10 ms |
48732 KB |
Output is correct |
18 |
Correct |
14 ms |
48728 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1012 ms |
113588 KB |
Output is correct |
2 |
Correct |
1070 ms |
113528 KB |
Output is correct |
3 |
Correct |
1008 ms |
113664 KB |
Output is correct |
4 |
Correct |
985 ms |
113772 KB |
Output is correct |
5 |
Correct |
807 ms |
79484 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
54736 KB |
Output is correct |
2 |
Correct |
76 ms |
55984 KB |
Output is correct |
3 |
Correct |
73 ms |
52832 KB |
Output is correct |
4 |
Correct |
67 ms |
52812 KB |
Output is correct |
5 |
Correct |
67 ms |
53072 KB |
Output is correct |
6 |
Correct |
54 ms |
52564 KB |
Output is correct |
7 |
Correct |
54 ms |
52560 KB |
Output is correct |
8 |
Correct |
66 ms |
54476 KB |
Output is correct |
9 |
Correct |
34 ms |
51468 KB |
Output is correct |
10 |
Correct |
62 ms |
53416 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
48472 KB |
Output is correct |
2 |
Correct |
9 ms |
48476 KB |
Output is correct |
3 |
Correct |
9 ms |
48612 KB |
Output is correct |
4 |
Correct |
9 ms |
48476 KB |
Output is correct |
5 |
Correct |
9 ms |
48568 KB |
Output is correct |
6 |
Correct |
9 ms |
48472 KB |
Output is correct |
7 |
Correct |
11 ms |
48476 KB |
Output is correct |
8 |
Correct |
9 ms |
48472 KB |
Output is correct |
9 |
Correct |
9 ms |
48600 KB |
Output is correct |
10 |
Correct |
8 ms |
48472 KB |
Output is correct |
11 |
Correct |
13 ms |
48476 KB |
Output is correct |
12 |
Correct |
13 ms |
48584 KB |
Output is correct |
13 |
Correct |
12 ms |
48728 KB |
Output is correct |
14 |
Correct |
12 ms |
48732 KB |
Output is correct |
15 |
Correct |
12 ms |
48872 KB |
Output is correct |
16 |
Correct |
13 ms |
48732 KB |
Output is correct |
17 |
Correct |
10 ms |
48732 KB |
Output is correct |
18 |
Correct |
14 ms |
48728 KB |
Output is correct |
19 |
Correct |
180 ms |
62920 KB |
Output is correct |
20 |
Correct |
184 ms |
65428 KB |
Output is correct |
21 |
Correct |
153 ms |
64708 KB |
Output is correct |
22 |
Correct |
158 ms |
64712 KB |
Output is correct |
23 |
Correct |
157 ms |
64712 KB |
Output is correct |
24 |
Correct |
115 ms |
57680 KB |
Output is correct |
25 |
Correct |
120 ms |
57684 KB |
Output is correct |
26 |
Correct |
137 ms |
57940 KB |
Output is correct |
27 |
Correct |
134 ms |
58184 KB |
Output is correct |
28 |
Correct |
134 ms |
58064 KB |
Output is correct |
29 |
Correct |
140 ms |
58456 KB |
Output is correct |
30 |
Correct |
152 ms |
58404 KB |
Output is correct |
31 |
Correct |
140 ms |
58452 KB |
Output is correct |
32 |
Correct |
139 ms |
58448 KB |
Output is correct |
33 |
Correct |
146 ms |
58452 KB |
Output is correct |
34 |
Correct |
111 ms |
57168 KB |
Output is correct |
35 |
Correct |
109 ms |
57172 KB |
Output is correct |
36 |
Correct |
107 ms |
57424 KB |
Output is correct |
37 |
Correct |
105 ms |
57172 KB |
Output is correct |
38 |
Correct |
108 ms |
57168 KB |
Output is correct |
39 |
Correct |
125 ms |
59260 KB |
Output is correct |
40 |
Correct |
95 ms |
56836 KB |
Output is correct |
41 |
Correct |
122 ms |
59432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
48472 KB |
Output is correct |
2 |
Correct |
9 ms |
48476 KB |
Output is correct |
3 |
Correct |
9 ms |
48612 KB |
Output is correct |
4 |
Correct |
9 ms |
48476 KB |
Output is correct |
5 |
Correct |
9 ms |
48568 KB |
Output is correct |
6 |
Correct |
9 ms |
48472 KB |
Output is correct |
7 |
Correct |
11 ms |
48476 KB |
Output is correct |
8 |
Correct |
9 ms |
48472 KB |
Output is correct |
9 |
Correct |
9 ms |
48600 KB |
Output is correct |
10 |
Correct |
8 ms |
48472 KB |
Output is correct |
11 |
Correct |
13 ms |
48476 KB |
Output is correct |
12 |
Correct |
13 ms |
48584 KB |
Output is correct |
13 |
Correct |
12 ms |
48728 KB |
Output is correct |
14 |
Correct |
12 ms |
48732 KB |
Output is correct |
15 |
Correct |
12 ms |
48872 KB |
Output is correct |
16 |
Correct |
13 ms |
48732 KB |
Output is correct |
17 |
Correct |
10 ms |
48732 KB |
Output is correct |
18 |
Correct |
14 ms |
48728 KB |
Output is correct |
19 |
Correct |
1012 ms |
113588 KB |
Output is correct |
20 |
Correct |
1070 ms |
113528 KB |
Output is correct |
21 |
Correct |
1008 ms |
113664 KB |
Output is correct |
22 |
Correct |
985 ms |
113772 KB |
Output is correct |
23 |
Correct |
807 ms |
79484 KB |
Output is correct |
24 |
Correct |
83 ms |
54736 KB |
Output is correct |
25 |
Correct |
76 ms |
55984 KB |
Output is correct |
26 |
Correct |
73 ms |
52832 KB |
Output is correct |
27 |
Correct |
67 ms |
52812 KB |
Output is correct |
28 |
Correct |
67 ms |
53072 KB |
Output is correct |
29 |
Correct |
54 ms |
52564 KB |
Output is correct |
30 |
Correct |
54 ms |
52560 KB |
Output is correct |
31 |
Correct |
66 ms |
54476 KB |
Output is correct |
32 |
Correct |
34 ms |
51468 KB |
Output is correct |
33 |
Correct |
62 ms |
53416 KB |
Output is correct |
34 |
Correct |
180 ms |
62920 KB |
Output is correct |
35 |
Correct |
184 ms |
65428 KB |
Output is correct |
36 |
Correct |
153 ms |
64708 KB |
Output is correct |
37 |
Correct |
158 ms |
64712 KB |
Output is correct |
38 |
Correct |
157 ms |
64712 KB |
Output is correct |
39 |
Correct |
115 ms |
57680 KB |
Output is correct |
40 |
Correct |
120 ms |
57684 KB |
Output is correct |
41 |
Correct |
137 ms |
57940 KB |
Output is correct |
42 |
Correct |
134 ms |
58184 KB |
Output is correct |
43 |
Correct |
134 ms |
58064 KB |
Output is correct |
44 |
Correct |
140 ms |
58456 KB |
Output is correct |
45 |
Correct |
152 ms |
58404 KB |
Output is correct |
46 |
Correct |
140 ms |
58452 KB |
Output is correct |
47 |
Correct |
139 ms |
58448 KB |
Output is correct |
48 |
Correct |
146 ms |
58452 KB |
Output is correct |
49 |
Correct |
111 ms |
57168 KB |
Output is correct |
50 |
Correct |
109 ms |
57172 KB |
Output is correct |
51 |
Correct |
107 ms |
57424 KB |
Output is correct |
52 |
Correct |
105 ms |
57172 KB |
Output is correct |
53 |
Correct |
108 ms |
57168 KB |
Output is correct |
54 |
Correct |
125 ms |
59260 KB |
Output is correct |
55 |
Correct |
95 ms |
56836 KB |
Output is correct |
56 |
Correct |
122 ms |
59432 KB |
Output is correct |
57 |
Correct |
1018 ms |
131264 KB |
Output is correct |
58 |
Correct |
1000 ms |
131292 KB |
Output is correct |
59 |
Correct |
983 ms |
129468 KB |
Output is correct |
60 |
Correct |
922 ms |
129368 KB |
Output is correct |
61 |
Correct |
957 ms |
129180 KB |
Output is correct |
62 |
Correct |
917 ms |
129188 KB |
Output is correct |
63 |
Correct |
561 ms |
90460 KB |
Output is correct |
64 |
Correct |
569 ms |
90528 KB |
Output is correct |
65 |
Correct |
731 ms |
95160 KB |
Output is correct |
66 |
Correct |
733 ms |
95056 KB |
Output is correct |
67 |
Correct |
751 ms |
95096 KB |
Output is correct |
68 |
Correct |
796 ms |
97016 KB |
Output is correct |
69 |
Correct |
837 ms |
97040 KB |
Output is correct |
70 |
Correct |
789 ms |
96596 KB |
Output is correct |
71 |
Correct |
788 ms |
96592 KB |
Output is correct |
72 |
Correct |
828 ms |
96800 KB |
Output is correct |
73 |
Correct |
544 ms |
89172 KB |
Output is correct |
74 |
Correct |
537 ms |
91584 KB |
Output is correct |
75 |
Correct |
533 ms |
88916 KB |
Output is correct |
76 |
Correct |
529 ms |
88796 KB |
Output is correct |
77 |
Correct |
531 ms |
88904 KB |
Output is correct |
78 |
Correct |
679 ms |
88120 KB |
Output is correct |
79 |
Correct |
461 ms |
75332 KB |
Output is correct |
80 |
Correct |
683 ms |
93456 KB |
Output is correct |