#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<ll, ll> pii;
typedef pair<ld, ld> pld;
ll n, m;
ll a[1000009];
vector<pair<pii, ll>> q[1000009];
ll bit[1000009];
void upd(ll idx, ll val){
for(++idx; idx <= n; idx += idx&(-idx))
bit[idx] = max(bit[idx], val);
}
ll get(ll idx){
ll ret = 0;
for(++idx; idx > 0; idx -= idx&(-idx))
ret = max(ret, bit[idx]);
return ret;
}
ll ans[1000009];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
//freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
cin >> n >> m;
for(ll i = 0; i < n; ++i)
cin >> a[i];
for(ll i = 0; i < m; ++i){
ll l, r, k;
cin >> l >> r >> k;
--l;
--r;
q[l].pb({{r, k}, i});
}
vector<ll> vec;
for(ll i = n-1; i >= 0; --i){
while(vec.size() && a[vec.back()] < a[i]){
upd(vec.back(), a[vec.back()]+a[i]);
vec.pop_back();
}
while(vec.size() && a[vec.back()] == a[i])
vec.pop_back();
vec.pb(i);
for(auto u : q[i]){
ans[u.ss] = (get(u.ff.ff) <= u.ff.ss);
}
}
for(ll i = 0; i < m; ++i)
cout << ans[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23760 KB |
Output is correct |
2 |
Correct |
13 ms |
23812 KB |
Output is correct |
3 |
Correct |
14 ms |
23820 KB |
Output is correct |
4 |
Correct |
14 ms |
23756 KB |
Output is correct |
5 |
Correct |
16 ms |
23812 KB |
Output is correct |
6 |
Correct |
14 ms |
23756 KB |
Output is correct |
7 |
Correct |
16 ms |
23816 KB |
Output is correct |
8 |
Correct |
15 ms |
23756 KB |
Output is correct |
9 |
Correct |
13 ms |
23756 KB |
Output is correct |
10 |
Correct |
13 ms |
23808 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23760 KB |
Output is correct |
2 |
Correct |
13 ms |
23812 KB |
Output is correct |
3 |
Correct |
14 ms |
23820 KB |
Output is correct |
4 |
Correct |
14 ms |
23756 KB |
Output is correct |
5 |
Correct |
16 ms |
23812 KB |
Output is correct |
6 |
Correct |
14 ms |
23756 KB |
Output is correct |
7 |
Correct |
16 ms |
23816 KB |
Output is correct |
8 |
Correct |
15 ms |
23756 KB |
Output is correct |
9 |
Correct |
13 ms |
23756 KB |
Output is correct |
10 |
Correct |
13 ms |
23808 KB |
Output is correct |
11 |
Correct |
15 ms |
23952 KB |
Output is correct |
12 |
Correct |
15 ms |
24004 KB |
Output is correct |
13 |
Correct |
16 ms |
24032 KB |
Output is correct |
14 |
Correct |
17 ms |
24264 KB |
Output is correct |
15 |
Correct |
17 ms |
24228 KB |
Output is correct |
16 |
Correct |
16 ms |
24172 KB |
Output is correct |
17 |
Correct |
18 ms |
24184 KB |
Output is correct |
18 |
Correct |
19 ms |
24024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1087 ms |
81672 KB |
Output is correct |
2 |
Correct |
1222 ms |
81652 KB |
Output is correct |
3 |
Correct |
1203 ms |
81752 KB |
Output is correct |
4 |
Correct |
1171 ms |
81676 KB |
Output is correct |
5 |
Correct |
1042 ms |
81800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
29548 KB |
Output is correct |
2 |
Correct |
98 ms |
30048 KB |
Output is correct |
3 |
Correct |
90 ms |
28784 KB |
Output is correct |
4 |
Correct |
83 ms |
28740 KB |
Output is correct |
5 |
Correct |
94 ms |
28740 KB |
Output is correct |
6 |
Correct |
69 ms |
29084 KB |
Output is correct |
7 |
Correct |
76 ms |
28952 KB |
Output is correct |
8 |
Correct |
82 ms |
28508 KB |
Output is correct |
9 |
Correct |
68 ms |
29032 KB |
Output is correct |
10 |
Correct |
74 ms |
30200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23760 KB |
Output is correct |
2 |
Correct |
13 ms |
23812 KB |
Output is correct |
3 |
Correct |
14 ms |
23820 KB |
Output is correct |
4 |
Correct |
14 ms |
23756 KB |
Output is correct |
5 |
Correct |
16 ms |
23812 KB |
Output is correct |
6 |
Correct |
14 ms |
23756 KB |
Output is correct |
7 |
Correct |
16 ms |
23816 KB |
Output is correct |
8 |
Correct |
15 ms |
23756 KB |
Output is correct |
9 |
Correct |
13 ms |
23756 KB |
Output is correct |
10 |
Correct |
13 ms |
23808 KB |
Output is correct |
11 |
Correct |
15 ms |
23952 KB |
Output is correct |
12 |
Correct |
15 ms |
24004 KB |
Output is correct |
13 |
Correct |
16 ms |
24032 KB |
Output is correct |
14 |
Correct |
17 ms |
24264 KB |
Output is correct |
15 |
Correct |
17 ms |
24228 KB |
Output is correct |
16 |
Correct |
16 ms |
24172 KB |
Output is correct |
17 |
Correct |
18 ms |
24184 KB |
Output is correct |
18 |
Correct |
19 ms |
24024 KB |
Output is correct |
19 |
Correct |
203 ms |
41852 KB |
Output is correct |
20 |
Correct |
219 ms |
41928 KB |
Output is correct |
21 |
Correct |
182 ms |
42820 KB |
Output is correct |
22 |
Correct |
174 ms |
42908 KB |
Output is correct |
23 |
Correct |
173 ms |
42744 KB |
Output is correct |
24 |
Correct |
164 ms |
42932 KB |
Output is correct |
25 |
Correct |
157 ms |
42968 KB |
Output is correct |
26 |
Correct |
176 ms |
42684 KB |
Output is correct |
27 |
Correct |
241 ms |
42736 KB |
Output is correct |
28 |
Correct |
191 ms |
42424 KB |
Output is correct |
29 |
Correct |
199 ms |
42100 KB |
Output is correct |
30 |
Correct |
214 ms |
42040 KB |
Output is correct |
31 |
Correct |
206 ms |
42140 KB |
Output is correct |
32 |
Correct |
204 ms |
42136 KB |
Output is correct |
33 |
Correct |
186 ms |
42184 KB |
Output is correct |
34 |
Correct |
145 ms |
41776 KB |
Output is correct |
35 |
Correct |
180 ms |
41868 KB |
Output is correct |
36 |
Correct |
142 ms |
41908 KB |
Output is correct |
37 |
Correct |
140 ms |
41740 KB |
Output is correct |
38 |
Correct |
152 ms |
41904 KB |
Output is correct |
39 |
Correct |
158 ms |
41800 KB |
Output is correct |
40 |
Correct |
145 ms |
38928 KB |
Output is correct |
41 |
Correct |
151 ms |
37940 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23760 KB |
Output is correct |
2 |
Correct |
13 ms |
23812 KB |
Output is correct |
3 |
Correct |
14 ms |
23820 KB |
Output is correct |
4 |
Correct |
14 ms |
23756 KB |
Output is correct |
5 |
Correct |
16 ms |
23812 KB |
Output is correct |
6 |
Correct |
14 ms |
23756 KB |
Output is correct |
7 |
Correct |
16 ms |
23816 KB |
Output is correct |
8 |
Correct |
15 ms |
23756 KB |
Output is correct |
9 |
Correct |
13 ms |
23756 KB |
Output is correct |
10 |
Correct |
13 ms |
23808 KB |
Output is correct |
11 |
Correct |
15 ms |
23952 KB |
Output is correct |
12 |
Correct |
15 ms |
24004 KB |
Output is correct |
13 |
Correct |
16 ms |
24032 KB |
Output is correct |
14 |
Correct |
17 ms |
24264 KB |
Output is correct |
15 |
Correct |
17 ms |
24228 KB |
Output is correct |
16 |
Correct |
16 ms |
24172 KB |
Output is correct |
17 |
Correct |
18 ms |
24184 KB |
Output is correct |
18 |
Correct |
19 ms |
24024 KB |
Output is correct |
19 |
Correct |
1087 ms |
81672 KB |
Output is correct |
20 |
Correct |
1222 ms |
81652 KB |
Output is correct |
21 |
Correct |
1203 ms |
81752 KB |
Output is correct |
22 |
Correct |
1171 ms |
81676 KB |
Output is correct |
23 |
Correct |
1042 ms |
81800 KB |
Output is correct |
24 |
Correct |
89 ms |
29548 KB |
Output is correct |
25 |
Correct |
98 ms |
30048 KB |
Output is correct |
26 |
Correct |
90 ms |
28784 KB |
Output is correct |
27 |
Correct |
83 ms |
28740 KB |
Output is correct |
28 |
Correct |
94 ms |
28740 KB |
Output is correct |
29 |
Correct |
69 ms |
29084 KB |
Output is correct |
30 |
Correct |
76 ms |
28952 KB |
Output is correct |
31 |
Correct |
82 ms |
28508 KB |
Output is correct |
32 |
Correct |
68 ms |
29032 KB |
Output is correct |
33 |
Correct |
74 ms |
30200 KB |
Output is correct |
34 |
Correct |
203 ms |
41852 KB |
Output is correct |
35 |
Correct |
219 ms |
41928 KB |
Output is correct |
36 |
Correct |
182 ms |
42820 KB |
Output is correct |
37 |
Correct |
174 ms |
42908 KB |
Output is correct |
38 |
Correct |
173 ms |
42744 KB |
Output is correct |
39 |
Correct |
164 ms |
42932 KB |
Output is correct |
40 |
Correct |
157 ms |
42968 KB |
Output is correct |
41 |
Correct |
176 ms |
42684 KB |
Output is correct |
42 |
Correct |
241 ms |
42736 KB |
Output is correct |
43 |
Correct |
191 ms |
42424 KB |
Output is correct |
44 |
Correct |
199 ms |
42100 KB |
Output is correct |
45 |
Correct |
214 ms |
42040 KB |
Output is correct |
46 |
Correct |
206 ms |
42140 KB |
Output is correct |
47 |
Correct |
204 ms |
42136 KB |
Output is correct |
48 |
Correct |
186 ms |
42184 KB |
Output is correct |
49 |
Correct |
145 ms |
41776 KB |
Output is correct |
50 |
Correct |
180 ms |
41868 KB |
Output is correct |
51 |
Correct |
142 ms |
41908 KB |
Output is correct |
52 |
Correct |
140 ms |
41740 KB |
Output is correct |
53 |
Correct |
152 ms |
41904 KB |
Output is correct |
54 |
Correct |
158 ms |
41800 KB |
Output is correct |
55 |
Correct |
145 ms |
38928 KB |
Output is correct |
56 |
Correct |
151 ms |
37940 KB |
Output is correct |
57 |
Correct |
1097 ms |
114992 KB |
Output is correct |
58 |
Correct |
1073 ms |
114980 KB |
Output is correct |
59 |
Correct |
1108 ms |
116656 KB |
Output is correct |
60 |
Correct |
1114 ms |
116644 KB |
Output is correct |
61 |
Correct |
1038 ms |
116664 KB |
Output is correct |
62 |
Correct |
1108 ms |
116700 KB |
Output is correct |
63 |
Correct |
714 ms |
113940 KB |
Output is correct |
64 |
Correct |
711 ms |
114160 KB |
Output is correct |
65 |
Correct |
951 ms |
117352 KB |
Output is correct |
66 |
Correct |
1026 ms |
117244 KB |
Output is correct |
67 |
Correct |
1006 ms |
116872 KB |
Output is correct |
68 |
Correct |
1050 ms |
115244 KB |
Output is correct |
69 |
Correct |
1086 ms |
115104 KB |
Output is correct |
70 |
Correct |
1131 ms |
115300 KB |
Output is correct |
71 |
Correct |
1049 ms |
115396 KB |
Output is correct |
72 |
Correct |
1073 ms |
115352 KB |
Output is correct |
73 |
Correct |
665 ms |
110640 KB |
Output is correct |
74 |
Correct |
683 ms |
111332 KB |
Output is correct |
75 |
Correct |
647 ms |
110540 KB |
Output is correct |
76 |
Correct |
644 ms |
110160 KB |
Output is correct |
77 |
Correct |
655 ms |
110368 KB |
Output is correct |
78 |
Correct |
944 ms |
112608 KB |
Output is correct |
79 |
Correct |
727 ms |
96528 KB |
Output is correct |
80 |
Correct |
919 ms |
95716 KB |
Output is correct |