#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const int MAXN = 1000000;
struct kveri{
int l, val, ind;
};
vector <kveri> queries[MAXN+5];
int bit[MAXN+5];
int a[MAXN+5];
void upd(int x, int val){
while(x <= MAXN){
bit[x] = max(bit[x], val);
x += x & -x;
}
}
int query(int x){
int res = 0;
while(x){
res = max(res, bit[x]);
x -= x & -x;
}
return res;
}
bool res[MAXN+5];
int main(){
ios_base::sync_with_stdio(false), cin.tie(0);
cout.precision(10);
cout << fixed;
int n, m;
cin >> n >> m;
for(int i=1; i<=n; i++) cin >> a[i];
for(int i=1; i<=m; i++){
int l, r, v;
cin >> l >> r >> v;
queries[r].push_back({l, v, i});
}
stack <int> st;
for(int i=1; i<=n; i++){
while(!st.empty() && a[st.top()] <= a[i]) st.pop();
if(!st.empty()){
upd(MAXN+1-st.top(), a[st.top()] + a[i]);
}
for(auto kveri : queries[i]){
res[kveri.ind] = (query(MAXN-kveri.l+1) <= kveri.val);
}
st.push(i);
}
for(int i=1; i<=m; i++) cout << res[i] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23804 KB |
Output is correct |
2 |
Correct |
18 ms |
23804 KB |
Output is correct |
3 |
Correct |
20 ms |
23832 KB |
Output is correct |
4 |
Correct |
19 ms |
23756 KB |
Output is correct |
5 |
Correct |
18 ms |
23700 KB |
Output is correct |
6 |
Correct |
17 ms |
23732 KB |
Output is correct |
7 |
Correct |
18 ms |
23844 KB |
Output is correct |
8 |
Correct |
18 ms |
23756 KB |
Output is correct |
9 |
Correct |
18 ms |
23744 KB |
Output is correct |
10 |
Correct |
16 ms |
23720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23804 KB |
Output is correct |
2 |
Correct |
18 ms |
23804 KB |
Output is correct |
3 |
Correct |
20 ms |
23832 KB |
Output is correct |
4 |
Correct |
19 ms |
23756 KB |
Output is correct |
5 |
Correct |
18 ms |
23700 KB |
Output is correct |
6 |
Correct |
17 ms |
23732 KB |
Output is correct |
7 |
Correct |
18 ms |
23844 KB |
Output is correct |
8 |
Correct |
18 ms |
23756 KB |
Output is correct |
9 |
Correct |
18 ms |
23744 KB |
Output is correct |
10 |
Correct |
16 ms |
23720 KB |
Output is correct |
11 |
Correct |
22 ms |
23900 KB |
Output is correct |
12 |
Correct |
20 ms |
24036 KB |
Output is correct |
13 |
Correct |
19 ms |
23940 KB |
Output is correct |
14 |
Correct |
22 ms |
24028 KB |
Output is correct |
15 |
Correct |
26 ms |
24108 KB |
Output is correct |
16 |
Correct |
20 ms |
24012 KB |
Output is correct |
17 |
Correct |
18 ms |
24004 KB |
Output is correct |
18 |
Correct |
20 ms |
24012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1177 ms |
57716 KB |
Output is correct |
2 |
Correct |
1233 ms |
57396 KB |
Output is correct |
3 |
Correct |
1124 ms |
57280 KB |
Output is correct |
4 |
Correct |
1159 ms |
57360 KB |
Output is correct |
5 |
Correct |
1117 ms |
53552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
28252 KB |
Output is correct |
2 |
Correct |
83 ms |
28004 KB |
Output is correct |
3 |
Correct |
83 ms |
27776 KB |
Output is correct |
4 |
Correct |
91 ms |
27944 KB |
Output is correct |
5 |
Correct |
82 ms |
27904 KB |
Output is correct |
6 |
Correct |
72 ms |
27464 KB |
Output is correct |
7 |
Correct |
72 ms |
27532 KB |
Output is correct |
8 |
Correct |
78 ms |
27764 KB |
Output is correct |
9 |
Correct |
67 ms |
26804 KB |
Output is correct |
10 |
Correct |
87 ms |
27776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23804 KB |
Output is correct |
2 |
Correct |
18 ms |
23804 KB |
Output is correct |
3 |
Correct |
20 ms |
23832 KB |
Output is correct |
4 |
Correct |
19 ms |
23756 KB |
Output is correct |
5 |
Correct |
18 ms |
23700 KB |
Output is correct |
6 |
Correct |
17 ms |
23732 KB |
Output is correct |
7 |
Correct |
18 ms |
23844 KB |
Output is correct |
8 |
Correct |
18 ms |
23756 KB |
Output is correct |
9 |
Correct |
18 ms |
23744 KB |
Output is correct |
10 |
Correct |
16 ms |
23720 KB |
Output is correct |
11 |
Correct |
22 ms |
23900 KB |
Output is correct |
12 |
Correct |
20 ms |
24036 KB |
Output is correct |
13 |
Correct |
19 ms |
23940 KB |
Output is correct |
14 |
Correct |
22 ms |
24028 KB |
Output is correct |
15 |
Correct |
26 ms |
24108 KB |
Output is correct |
16 |
Correct |
20 ms |
24012 KB |
Output is correct |
17 |
Correct |
18 ms |
24004 KB |
Output is correct |
18 |
Correct |
20 ms |
24012 KB |
Output is correct |
19 |
Correct |
196 ms |
31560 KB |
Output is correct |
20 |
Correct |
206 ms |
31476 KB |
Output is correct |
21 |
Correct |
186 ms |
31044 KB |
Output is correct |
22 |
Correct |
165 ms |
30940 KB |
Output is correct |
23 |
Correct |
166 ms |
31004 KB |
Output is correct |
24 |
Correct |
165 ms |
30276 KB |
Output is correct |
25 |
Correct |
152 ms |
30112 KB |
Output is correct |
26 |
Correct |
177 ms |
30292 KB |
Output is correct |
27 |
Correct |
201 ms |
30284 KB |
Output is correct |
28 |
Correct |
192 ms |
30496 KB |
Output is correct |
29 |
Correct |
197 ms |
30656 KB |
Output is correct |
30 |
Correct |
175 ms |
30668 KB |
Output is correct |
31 |
Correct |
179 ms |
30708 KB |
Output is correct |
32 |
Correct |
223 ms |
30660 KB |
Output is correct |
33 |
Correct |
187 ms |
30680 KB |
Output is correct |
34 |
Correct |
172 ms |
29764 KB |
Output is correct |
35 |
Correct |
169 ms |
29720 KB |
Output is correct |
36 |
Correct |
136 ms |
29676 KB |
Output is correct |
37 |
Correct |
140 ms |
29548 KB |
Output is correct |
38 |
Correct |
158 ms |
29636 KB |
Output is correct |
39 |
Correct |
162 ms |
30348 KB |
Output is correct |
40 |
Correct |
180 ms |
29540 KB |
Output is correct |
41 |
Correct |
161 ms |
30076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23804 KB |
Output is correct |
2 |
Correct |
18 ms |
23804 KB |
Output is correct |
3 |
Correct |
20 ms |
23832 KB |
Output is correct |
4 |
Correct |
19 ms |
23756 KB |
Output is correct |
5 |
Correct |
18 ms |
23700 KB |
Output is correct |
6 |
Correct |
17 ms |
23732 KB |
Output is correct |
7 |
Correct |
18 ms |
23844 KB |
Output is correct |
8 |
Correct |
18 ms |
23756 KB |
Output is correct |
9 |
Correct |
18 ms |
23744 KB |
Output is correct |
10 |
Correct |
16 ms |
23720 KB |
Output is correct |
11 |
Correct |
22 ms |
23900 KB |
Output is correct |
12 |
Correct |
20 ms |
24036 KB |
Output is correct |
13 |
Correct |
19 ms |
23940 KB |
Output is correct |
14 |
Correct |
22 ms |
24028 KB |
Output is correct |
15 |
Correct |
26 ms |
24108 KB |
Output is correct |
16 |
Correct |
20 ms |
24012 KB |
Output is correct |
17 |
Correct |
18 ms |
24004 KB |
Output is correct |
18 |
Correct |
20 ms |
24012 KB |
Output is correct |
19 |
Correct |
1177 ms |
57716 KB |
Output is correct |
20 |
Correct |
1233 ms |
57396 KB |
Output is correct |
21 |
Correct |
1124 ms |
57280 KB |
Output is correct |
22 |
Correct |
1159 ms |
57360 KB |
Output is correct |
23 |
Correct |
1117 ms |
53552 KB |
Output is correct |
24 |
Correct |
89 ms |
28252 KB |
Output is correct |
25 |
Correct |
83 ms |
28004 KB |
Output is correct |
26 |
Correct |
83 ms |
27776 KB |
Output is correct |
27 |
Correct |
91 ms |
27944 KB |
Output is correct |
28 |
Correct |
82 ms |
27904 KB |
Output is correct |
29 |
Correct |
72 ms |
27464 KB |
Output is correct |
30 |
Correct |
72 ms |
27532 KB |
Output is correct |
31 |
Correct |
78 ms |
27764 KB |
Output is correct |
32 |
Correct |
67 ms |
26804 KB |
Output is correct |
33 |
Correct |
87 ms |
27776 KB |
Output is correct |
34 |
Correct |
196 ms |
31560 KB |
Output is correct |
35 |
Correct |
206 ms |
31476 KB |
Output is correct |
36 |
Correct |
186 ms |
31044 KB |
Output is correct |
37 |
Correct |
165 ms |
30940 KB |
Output is correct |
38 |
Correct |
166 ms |
31004 KB |
Output is correct |
39 |
Correct |
165 ms |
30276 KB |
Output is correct |
40 |
Correct |
152 ms |
30112 KB |
Output is correct |
41 |
Correct |
177 ms |
30292 KB |
Output is correct |
42 |
Correct |
201 ms |
30284 KB |
Output is correct |
43 |
Correct |
192 ms |
30496 KB |
Output is correct |
44 |
Correct |
197 ms |
30656 KB |
Output is correct |
45 |
Correct |
175 ms |
30668 KB |
Output is correct |
46 |
Correct |
179 ms |
30708 KB |
Output is correct |
47 |
Correct |
223 ms |
30660 KB |
Output is correct |
48 |
Correct |
187 ms |
30680 KB |
Output is correct |
49 |
Correct |
172 ms |
29764 KB |
Output is correct |
50 |
Correct |
169 ms |
29720 KB |
Output is correct |
51 |
Correct |
136 ms |
29676 KB |
Output is correct |
52 |
Correct |
140 ms |
29548 KB |
Output is correct |
53 |
Correct |
158 ms |
29636 KB |
Output is correct |
54 |
Correct |
162 ms |
30348 KB |
Output is correct |
55 |
Correct |
180 ms |
29540 KB |
Output is correct |
56 |
Correct |
161 ms |
30076 KB |
Output is correct |
57 |
Correct |
1104 ms |
56760 KB |
Output is correct |
58 |
Correct |
1093 ms |
56484 KB |
Output is correct |
59 |
Correct |
1041 ms |
54996 KB |
Output is correct |
60 |
Correct |
1018 ms |
55152 KB |
Output is correct |
61 |
Correct |
1034 ms |
54936 KB |
Output is correct |
62 |
Correct |
1093 ms |
55016 KB |
Output is correct |
63 |
Correct |
799 ms |
49732 KB |
Output is correct |
64 |
Correct |
677 ms |
49740 KB |
Output is correct |
65 |
Correct |
1002 ms |
50936 KB |
Output is correct |
66 |
Correct |
953 ms |
51040 KB |
Output is correct |
67 |
Correct |
996 ms |
51188 KB |
Output is correct |
68 |
Correct |
1010 ms |
52588 KB |
Output is correct |
69 |
Correct |
1036 ms |
52512 KB |
Output is correct |
70 |
Correct |
1032 ms |
52184 KB |
Output is correct |
71 |
Correct |
992 ms |
52308 KB |
Output is correct |
72 |
Correct |
982 ms |
52236 KB |
Output is correct |
73 |
Correct |
636 ms |
47168 KB |
Output is correct |
74 |
Correct |
673 ms |
47104 KB |
Output is correct |
75 |
Correct |
699 ms |
47140 KB |
Output is correct |
76 |
Correct |
672 ms |
47420 KB |
Output is correct |
77 |
Correct |
620 ms |
47016 KB |
Output is correct |
78 |
Correct |
944 ms |
52356 KB |
Output is correct |
79 |
Correct |
714 ms |
46080 KB |
Output is correct |
80 |
Correct |
852 ms |
50080 KB |
Output is correct |