#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 |
14 ms |
23696 KB |
Output is correct |
2 |
Correct |
14 ms |
23688 KB |
Output is correct |
3 |
Correct |
16 ms |
23756 KB |
Output is correct |
4 |
Correct |
16 ms |
23808 KB |
Output is correct |
5 |
Correct |
14 ms |
23776 KB |
Output is correct |
6 |
Correct |
14 ms |
23748 KB |
Output is correct |
7 |
Correct |
16 ms |
23776 KB |
Output is correct |
8 |
Correct |
14 ms |
23756 KB |
Output is correct |
9 |
Correct |
14 ms |
23732 KB |
Output is correct |
10 |
Correct |
14 ms |
23756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23696 KB |
Output is correct |
2 |
Correct |
14 ms |
23688 KB |
Output is correct |
3 |
Correct |
16 ms |
23756 KB |
Output is correct |
4 |
Correct |
16 ms |
23808 KB |
Output is correct |
5 |
Correct |
14 ms |
23776 KB |
Output is correct |
6 |
Correct |
14 ms |
23748 KB |
Output is correct |
7 |
Correct |
16 ms |
23776 KB |
Output is correct |
8 |
Correct |
14 ms |
23756 KB |
Output is correct |
9 |
Correct |
14 ms |
23732 KB |
Output is correct |
10 |
Correct |
14 ms |
23756 KB |
Output is correct |
11 |
Correct |
15 ms |
23884 KB |
Output is correct |
12 |
Correct |
16 ms |
23980 KB |
Output is correct |
13 |
Correct |
16 ms |
23936 KB |
Output is correct |
14 |
Correct |
17 ms |
24012 KB |
Output is correct |
15 |
Correct |
18 ms |
24128 KB |
Output is correct |
16 |
Correct |
20 ms |
23996 KB |
Output is correct |
17 |
Correct |
19 ms |
24012 KB |
Output is correct |
18 |
Correct |
18 ms |
24012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1012 ms |
56300 KB |
Output is correct |
2 |
Correct |
988 ms |
56296 KB |
Output is correct |
3 |
Correct |
997 ms |
56344 KB |
Output is correct |
4 |
Correct |
1040 ms |
56280 KB |
Output is correct |
5 |
Correct |
935 ms |
52452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
78 ms |
26952 KB |
Output is correct |
2 |
Correct |
74 ms |
27272 KB |
Output is correct |
3 |
Correct |
78 ms |
27000 KB |
Output is correct |
4 |
Correct |
75 ms |
27076 KB |
Output is correct |
5 |
Correct |
75 ms |
27116 KB |
Output is correct |
6 |
Correct |
67 ms |
26684 KB |
Output is correct |
7 |
Correct |
66 ms |
26692 KB |
Output is correct |
8 |
Correct |
78 ms |
27068 KB |
Output is correct |
9 |
Correct |
54 ms |
26168 KB |
Output is correct |
10 |
Correct |
73 ms |
27008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23696 KB |
Output is correct |
2 |
Correct |
14 ms |
23688 KB |
Output is correct |
3 |
Correct |
16 ms |
23756 KB |
Output is correct |
4 |
Correct |
16 ms |
23808 KB |
Output is correct |
5 |
Correct |
14 ms |
23776 KB |
Output is correct |
6 |
Correct |
14 ms |
23748 KB |
Output is correct |
7 |
Correct |
16 ms |
23776 KB |
Output is correct |
8 |
Correct |
14 ms |
23756 KB |
Output is correct |
9 |
Correct |
14 ms |
23732 KB |
Output is correct |
10 |
Correct |
14 ms |
23756 KB |
Output is correct |
11 |
Correct |
15 ms |
23884 KB |
Output is correct |
12 |
Correct |
16 ms |
23980 KB |
Output is correct |
13 |
Correct |
16 ms |
23936 KB |
Output is correct |
14 |
Correct |
17 ms |
24012 KB |
Output is correct |
15 |
Correct |
18 ms |
24128 KB |
Output is correct |
16 |
Correct |
20 ms |
23996 KB |
Output is correct |
17 |
Correct |
19 ms |
24012 KB |
Output is correct |
18 |
Correct |
18 ms |
24012 KB |
Output is correct |
19 |
Correct |
197 ms |
30788 KB |
Output is correct |
20 |
Correct |
191 ms |
30712 KB |
Output is correct |
21 |
Correct |
155 ms |
30300 KB |
Output is correct |
22 |
Correct |
162 ms |
30276 KB |
Output is correct |
23 |
Correct |
156 ms |
30220 KB |
Output is correct |
24 |
Correct |
151 ms |
29412 KB |
Output is correct |
25 |
Correct |
152 ms |
29460 KB |
Output is correct |
26 |
Correct |
156 ms |
29636 KB |
Output is correct |
27 |
Correct |
167 ms |
29592 KB |
Output is correct |
28 |
Correct |
165 ms |
29712 KB |
Output is correct |
29 |
Correct |
170 ms |
29940 KB |
Output is correct |
30 |
Correct |
164 ms |
30016 KB |
Output is correct |
31 |
Correct |
197 ms |
29928 KB |
Output is correct |
32 |
Correct |
207 ms |
29956 KB |
Output is correct |
33 |
Correct |
178 ms |
29888 KB |
Output is correct |
34 |
Correct |
150 ms |
29216 KB |
Output is correct |
35 |
Correct |
139 ms |
29096 KB |
Output is correct |
36 |
Correct |
135 ms |
29052 KB |
Output is correct |
37 |
Correct |
162 ms |
29132 KB |
Output is correct |
38 |
Correct |
141 ms |
29132 KB |
Output is correct |
39 |
Correct |
150 ms |
29844 KB |
Output is correct |
40 |
Correct |
134 ms |
28980 KB |
Output is correct |
41 |
Correct |
149 ms |
29740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23696 KB |
Output is correct |
2 |
Correct |
14 ms |
23688 KB |
Output is correct |
3 |
Correct |
16 ms |
23756 KB |
Output is correct |
4 |
Correct |
16 ms |
23808 KB |
Output is correct |
5 |
Correct |
14 ms |
23776 KB |
Output is correct |
6 |
Correct |
14 ms |
23748 KB |
Output is correct |
7 |
Correct |
16 ms |
23776 KB |
Output is correct |
8 |
Correct |
14 ms |
23756 KB |
Output is correct |
9 |
Correct |
14 ms |
23732 KB |
Output is correct |
10 |
Correct |
14 ms |
23756 KB |
Output is correct |
11 |
Correct |
15 ms |
23884 KB |
Output is correct |
12 |
Correct |
16 ms |
23980 KB |
Output is correct |
13 |
Correct |
16 ms |
23936 KB |
Output is correct |
14 |
Correct |
17 ms |
24012 KB |
Output is correct |
15 |
Correct |
18 ms |
24128 KB |
Output is correct |
16 |
Correct |
20 ms |
23996 KB |
Output is correct |
17 |
Correct |
19 ms |
24012 KB |
Output is correct |
18 |
Correct |
18 ms |
24012 KB |
Output is correct |
19 |
Correct |
1012 ms |
56300 KB |
Output is correct |
20 |
Correct |
988 ms |
56296 KB |
Output is correct |
21 |
Correct |
997 ms |
56344 KB |
Output is correct |
22 |
Correct |
1040 ms |
56280 KB |
Output is correct |
23 |
Correct |
935 ms |
52452 KB |
Output is correct |
24 |
Correct |
78 ms |
26952 KB |
Output is correct |
25 |
Correct |
74 ms |
27272 KB |
Output is correct |
26 |
Correct |
78 ms |
27000 KB |
Output is correct |
27 |
Correct |
75 ms |
27076 KB |
Output is correct |
28 |
Correct |
75 ms |
27116 KB |
Output is correct |
29 |
Correct |
67 ms |
26684 KB |
Output is correct |
30 |
Correct |
66 ms |
26692 KB |
Output is correct |
31 |
Correct |
78 ms |
27068 KB |
Output is correct |
32 |
Correct |
54 ms |
26168 KB |
Output is correct |
33 |
Correct |
73 ms |
27008 KB |
Output is correct |
34 |
Correct |
197 ms |
30788 KB |
Output is correct |
35 |
Correct |
191 ms |
30712 KB |
Output is correct |
36 |
Correct |
155 ms |
30300 KB |
Output is correct |
37 |
Correct |
162 ms |
30276 KB |
Output is correct |
38 |
Correct |
156 ms |
30220 KB |
Output is correct |
39 |
Correct |
151 ms |
29412 KB |
Output is correct |
40 |
Correct |
152 ms |
29460 KB |
Output is correct |
41 |
Correct |
156 ms |
29636 KB |
Output is correct |
42 |
Correct |
167 ms |
29592 KB |
Output is correct |
43 |
Correct |
165 ms |
29712 KB |
Output is correct |
44 |
Correct |
170 ms |
29940 KB |
Output is correct |
45 |
Correct |
164 ms |
30016 KB |
Output is correct |
46 |
Correct |
197 ms |
29928 KB |
Output is correct |
47 |
Correct |
207 ms |
29956 KB |
Output is correct |
48 |
Correct |
178 ms |
29888 KB |
Output is correct |
49 |
Correct |
150 ms |
29216 KB |
Output is correct |
50 |
Correct |
139 ms |
29096 KB |
Output is correct |
51 |
Correct |
135 ms |
29052 KB |
Output is correct |
52 |
Correct |
162 ms |
29132 KB |
Output is correct |
53 |
Correct |
141 ms |
29132 KB |
Output is correct |
54 |
Correct |
150 ms |
29844 KB |
Output is correct |
55 |
Correct |
134 ms |
28980 KB |
Output is correct |
56 |
Correct |
149 ms |
29740 KB |
Output is correct |
57 |
Correct |
977 ms |
55928 KB |
Output is correct |
58 |
Correct |
983 ms |
55760 KB |
Output is correct |
59 |
Correct |
935 ms |
54312 KB |
Output is correct |
60 |
Correct |
955 ms |
54356 KB |
Output is correct |
61 |
Correct |
947 ms |
54420 KB |
Output is correct |
62 |
Correct |
928 ms |
54236 KB |
Output is correct |
63 |
Correct |
669 ms |
49052 KB |
Output is correct |
64 |
Correct |
654 ms |
49080 KB |
Output is correct |
65 |
Correct |
957 ms |
50296 KB |
Output is correct |
66 |
Correct |
854 ms |
50240 KB |
Output is correct |
67 |
Correct |
873 ms |
50420 KB |
Output is correct |
68 |
Correct |
922 ms |
51944 KB |
Output is correct |
69 |
Correct |
907 ms |
51888 KB |
Output is correct |
70 |
Correct |
909 ms |
51796 KB |
Output is correct |
71 |
Correct |
920 ms |
51680 KB |
Output is correct |
72 |
Correct |
902 ms |
51524 KB |
Output is correct |
73 |
Correct |
612 ms |
46444 KB |
Output is correct |
74 |
Correct |
637 ms |
46464 KB |
Output is correct |
75 |
Correct |
602 ms |
46508 KB |
Output is correct |
76 |
Correct |
614 ms |
46756 KB |
Output is correct |
77 |
Correct |
600 ms |
46408 KB |
Output is correct |
78 |
Correct |
799 ms |
51436 KB |
Output is correct |
79 |
Correct |
698 ms |
46052 KB |
Output is correct |
80 |
Correct |
786 ms |
50020 KB |
Output is correct |