//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
//#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ss second
#define ff first
#define vt vector
#define uid(a, b) uniform_int_distribution<int>(a, b)(mt)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int inf = 2e9;
const int mod = 1e9+7;
const int maxn = 1e6;
mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
int t[maxn * 4], it, val;
void upd(int v, int l, int r){
t[v] = max(t[v], val);
if(l + 1 == r){
return;
}
if(((l + r) >> 1) <= it)upd(v * 2 + 2, ((l + r) >> 1), r);
else upd(v * 2 + 1, l, ((l + r) >> 1));
}
int get(int v, int l, int r){
if(it <= l)return t[v];
if(r <= it)return 0;
return max(get(v * 2 + 1, l, ((l + r) >> 1)), get(v * 2 + 2, ((l + r) >> 1), r));
}
void solve() {
int n, m;
cin >> n >> m;
int w[n];
for(int i = 0; i < n; i++){
cin >> w[i];
}
vt<int> q[n];
int l[m], x[m], ans[m];
for(int j = 0, r; j < m; j++){
cin >> l[j] >> r >> x[j];
l[j]--, r--;
q[r].pb(j);
}
stack<int> st;
for(int i = 0; i < n; i++){
while(!st.empty() && w[st.top()] <= w[i])st.pop();
if(!st.empty()){
val = w[i] + w[st.top()];
it = st.top();
upd(0, 0, n);
}
st.push(i);
for(auto j : q[i]){
it = l[j];
ans[j] = get(0, 0, n);
}
}
for(int i = 0; i < m; i++)cout << (ans[i] <= x[i]) << '\n';
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int times = 1; //cin >> times;
for(int i = 1; i <= times; i++) {
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
484 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
484 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
480 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
3 ms |
856 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
3 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1082 ms |
99524 KB |
Output is correct |
2 |
Correct |
1068 ms |
100488 KB |
Output is correct |
3 |
Correct |
1050 ms |
100404 KB |
Output is correct |
4 |
Correct |
945 ms |
100436 KB |
Output is correct |
5 |
Correct |
981 ms |
92432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
65 ms |
9160 KB |
Output is correct |
2 |
Correct |
53 ms |
8276 KB |
Output is correct |
3 |
Correct |
48 ms |
7760 KB |
Output is correct |
4 |
Correct |
49 ms |
8020 KB |
Output is correct |
5 |
Correct |
58 ms |
7972 KB |
Output is correct |
6 |
Correct |
40 ms |
6880 KB |
Output is correct |
7 |
Correct |
59 ms |
6992 KB |
Output is correct |
8 |
Correct |
50 ms |
7620 KB |
Output is correct |
9 |
Correct |
28 ms |
3544 KB |
Output is correct |
10 |
Correct |
45 ms |
7888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
484 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
480 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
3 ms |
856 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
3 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
155 ms |
20564 KB |
Output is correct |
20 |
Correct |
143 ms |
20364 KB |
Output is correct |
21 |
Correct |
132 ms |
18504 KB |
Output is correct |
22 |
Correct |
119 ms |
18512 KB |
Output is correct |
23 |
Correct |
127 ms |
18616 KB |
Output is correct |
24 |
Correct |
100 ms |
16148 KB |
Output is correct |
25 |
Correct |
145 ms |
16208 KB |
Output is correct |
26 |
Correct |
112 ms |
17120 KB |
Output is correct |
27 |
Correct |
134 ms |
17224 KB |
Output is correct |
28 |
Correct |
130 ms |
17428 KB |
Output is correct |
29 |
Correct |
125 ms |
18512 KB |
Output is correct |
30 |
Correct |
158 ms |
18416 KB |
Output is correct |
31 |
Correct |
118 ms |
18256 KB |
Output is correct |
32 |
Correct |
134 ms |
18376 KB |
Output is correct |
33 |
Correct |
120 ms |
18260 KB |
Output is correct |
34 |
Correct |
93 ms |
15956 KB |
Output is correct |
35 |
Correct |
92 ms |
15828 KB |
Output is correct |
36 |
Correct |
96 ms |
15744 KB |
Output is correct |
37 |
Correct |
121 ms |
15828 KB |
Output is correct |
38 |
Correct |
96 ms |
15876 KB |
Output is correct |
39 |
Correct |
115 ms |
17416 KB |
Output is correct |
40 |
Correct |
88 ms |
13684 KB |
Output is correct |
41 |
Correct |
105 ms |
16264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
484 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
480 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
3 ms |
856 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
3 ms |
856 KB |
Output is correct |
15 |
Correct |
3 ms |
860 KB |
Output is correct |
16 |
Correct |
3 ms |
856 KB |
Output is correct |
17 |
Correct |
2 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
1082 ms |
99524 KB |
Output is correct |
20 |
Correct |
1068 ms |
100488 KB |
Output is correct |
21 |
Correct |
1050 ms |
100404 KB |
Output is correct |
22 |
Correct |
945 ms |
100436 KB |
Output is correct |
23 |
Correct |
981 ms |
92432 KB |
Output is correct |
24 |
Correct |
65 ms |
9160 KB |
Output is correct |
25 |
Correct |
53 ms |
8276 KB |
Output is correct |
26 |
Correct |
48 ms |
7760 KB |
Output is correct |
27 |
Correct |
49 ms |
8020 KB |
Output is correct |
28 |
Correct |
58 ms |
7972 KB |
Output is correct |
29 |
Correct |
40 ms |
6880 KB |
Output is correct |
30 |
Correct |
59 ms |
6992 KB |
Output is correct |
31 |
Correct |
50 ms |
7620 KB |
Output is correct |
32 |
Correct |
28 ms |
3544 KB |
Output is correct |
33 |
Correct |
45 ms |
7888 KB |
Output is correct |
34 |
Correct |
155 ms |
20564 KB |
Output is correct |
35 |
Correct |
143 ms |
20364 KB |
Output is correct |
36 |
Correct |
132 ms |
18504 KB |
Output is correct |
37 |
Correct |
119 ms |
18512 KB |
Output is correct |
38 |
Correct |
127 ms |
18616 KB |
Output is correct |
39 |
Correct |
100 ms |
16148 KB |
Output is correct |
40 |
Correct |
145 ms |
16208 KB |
Output is correct |
41 |
Correct |
112 ms |
17120 KB |
Output is correct |
42 |
Correct |
134 ms |
17224 KB |
Output is correct |
43 |
Correct |
130 ms |
17428 KB |
Output is correct |
44 |
Correct |
125 ms |
18512 KB |
Output is correct |
45 |
Correct |
158 ms |
18416 KB |
Output is correct |
46 |
Correct |
118 ms |
18256 KB |
Output is correct |
47 |
Correct |
134 ms |
18376 KB |
Output is correct |
48 |
Correct |
120 ms |
18260 KB |
Output is correct |
49 |
Correct |
93 ms |
15956 KB |
Output is correct |
50 |
Correct |
92 ms |
15828 KB |
Output is correct |
51 |
Correct |
96 ms |
15744 KB |
Output is correct |
52 |
Correct |
121 ms |
15828 KB |
Output is correct |
53 |
Correct |
96 ms |
15876 KB |
Output is correct |
54 |
Correct |
115 ms |
17416 KB |
Output is correct |
55 |
Correct |
88 ms |
13684 KB |
Output is correct |
56 |
Correct |
105 ms |
16264 KB |
Output is correct |
57 |
Correct |
1094 ms |
99384 KB |
Output is correct |
58 |
Correct |
1026 ms |
99336 KB |
Output is correct |
59 |
Correct |
1000 ms |
95168 KB |
Output is correct |
60 |
Correct |
982 ms |
95176 KB |
Output is correct |
61 |
Correct |
867 ms |
95272 KB |
Output is correct |
62 |
Correct |
1012 ms |
95264 KB |
Output is correct |
63 |
Correct |
538 ms |
79264 KB |
Output is correct |
64 |
Correct |
533 ms |
79272 KB |
Output is correct |
65 |
Correct |
720 ms |
86504 KB |
Output is correct |
66 |
Correct |
805 ms |
86356 KB |
Output is correct |
67 |
Correct |
802 ms |
86852 KB |
Output is correct |
68 |
Correct |
990 ms |
91348 KB |
Output is correct |
69 |
Correct |
901 ms |
91044 KB |
Output is correct |
70 |
Correct |
794 ms |
90464 KB |
Output is correct |
71 |
Correct |
790 ms |
90612 KB |
Output is correct |
72 |
Correct |
778 ms |
90640 KB |
Output is correct |
73 |
Correct |
509 ms |
77416 KB |
Output is correct |
74 |
Correct |
468 ms |
78292 KB |
Output is correct |
75 |
Correct |
486 ms |
77296 KB |
Output is correct |
76 |
Correct |
478 ms |
77644 KB |
Output is correct |
77 |
Correct |
473 ms |
77588 KB |
Output is correct |
78 |
Correct |
696 ms |
85960 KB |
Output is correct |
79 |
Correct |
567 ms |
63172 KB |
Output is correct |
80 |
Correct |
643 ms |
81084 KB |
Output is correct |