#include<bits/stdc++.h>
using namespace std;
#define int int64_t
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
struct SegTree {
const static int T = 1<<20;
int t[2*T];
void update(int x, int val) {
x+=T;
t[x] = max(t[x], val);
x/=2;
while(x) {
t[x] = max(t[2*x], t[2*x+1]);
x/=2;
}
}
int query(int l, int r) {
l+=T;
r+=T;
int ret = max(t[l], t[r]);
while(l/2!=r/2) {
if(l%2==0) ret = max(ret, t[l+1]);
if(r%2==1) ret = max(ret, t[r-1]);
l/=2;
r/=2;
}
return ret;
}
};
SegTree seg;
vector<pii> v[1000009];
int tab[1000009];
int ans[1000009];
vector<tuple<int, int, int, int>> Q;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, q;
cin >> n >> q;
for(int i=0;i<n;i++) {
cin >> tab[i];
}
vector<pii> s;
for(int i=0;i<n;i++) {
while(sz(s)&&s.back().nd<=tab[i]) {
s.pop_back();
}
if(sz(s)) {
v[s.back().st].pb({i, tab[i]+tab[s.back().st]});
}
s.pb({i, tab[i]});
}
for(int i=0;i<q;i++) {
int l, r, k;
cin >> l >> r >> k;
l--;
r--;
Q.pb({-l, r, k, i});
}
sort(all(Q));
int cnt = n-1;
for(auto [l, r, k, id]:Q) {
l = -l;
while(cnt>=0&&cnt>=l) {
for(pii x:v[cnt]) {
seg.update(x.st, x.nd);
}
cnt--;
}
ans[id] = (k>=seg.query(0, r));
}
for(int i=0;i<q;i++) {
cout << ans[i] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23764 KB |
Output is correct |
3 |
Correct |
15 ms |
23892 KB |
Output is correct |
4 |
Correct |
14 ms |
23892 KB |
Output is correct |
5 |
Correct |
13 ms |
23808 KB |
Output is correct |
6 |
Correct |
15 ms |
23960 KB |
Output is correct |
7 |
Correct |
15 ms |
23892 KB |
Output is correct |
8 |
Correct |
16 ms |
23836 KB |
Output is correct |
9 |
Correct |
14 ms |
23916 KB |
Output is correct |
10 |
Correct |
14 ms |
23952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23764 KB |
Output is correct |
3 |
Correct |
15 ms |
23892 KB |
Output is correct |
4 |
Correct |
14 ms |
23892 KB |
Output is correct |
5 |
Correct |
13 ms |
23808 KB |
Output is correct |
6 |
Correct |
15 ms |
23960 KB |
Output is correct |
7 |
Correct |
15 ms |
23892 KB |
Output is correct |
8 |
Correct |
16 ms |
23836 KB |
Output is correct |
9 |
Correct |
14 ms |
23916 KB |
Output is correct |
10 |
Correct |
14 ms |
23952 KB |
Output is correct |
11 |
Correct |
15 ms |
24216 KB |
Output is correct |
12 |
Correct |
20 ms |
24436 KB |
Output is correct |
13 |
Correct |
17 ms |
24484 KB |
Output is correct |
14 |
Correct |
19 ms |
24528 KB |
Output is correct |
15 |
Correct |
17 ms |
24536 KB |
Output is correct |
16 |
Correct |
17 ms |
24376 KB |
Output is correct |
17 |
Correct |
17 ms |
24292 KB |
Output is correct |
18 |
Correct |
18 ms |
24464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
926 ms |
114180 KB |
Output is correct |
2 |
Correct |
928 ms |
147208 KB |
Output is correct |
3 |
Correct |
939 ms |
147104 KB |
Output is correct |
4 |
Correct |
997 ms |
147244 KB |
Output is correct |
5 |
Correct |
705 ms |
105848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
100 ms |
33000 KB |
Output is correct |
2 |
Correct |
94 ms |
34876 KB |
Output is correct |
3 |
Correct |
71 ms |
30756 KB |
Output is correct |
4 |
Correct |
73 ms |
30752 KB |
Output is correct |
5 |
Correct |
70 ms |
30836 KB |
Output is correct |
6 |
Correct |
70 ms |
31016 KB |
Output is correct |
7 |
Correct |
76 ms |
31032 KB |
Output is correct |
8 |
Correct |
86 ms |
33644 KB |
Output is correct |
9 |
Correct |
55 ms |
29432 KB |
Output is correct |
10 |
Correct |
85 ms |
33208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23764 KB |
Output is correct |
3 |
Correct |
15 ms |
23892 KB |
Output is correct |
4 |
Correct |
14 ms |
23892 KB |
Output is correct |
5 |
Correct |
13 ms |
23808 KB |
Output is correct |
6 |
Correct |
15 ms |
23960 KB |
Output is correct |
7 |
Correct |
15 ms |
23892 KB |
Output is correct |
8 |
Correct |
16 ms |
23836 KB |
Output is correct |
9 |
Correct |
14 ms |
23916 KB |
Output is correct |
10 |
Correct |
14 ms |
23952 KB |
Output is correct |
11 |
Correct |
15 ms |
24216 KB |
Output is correct |
12 |
Correct |
20 ms |
24436 KB |
Output is correct |
13 |
Correct |
17 ms |
24484 KB |
Output is correct |
14 |
Correct |
19 ms |
24528 KB |
Output is correct |
15 |
Correct |
17 ms |
24536 KB |
Output is correct |
16 |
Correct |
17 ms |
24376 KB |
Output is correct |
17 |
Correct |
17 ms |
24292 KB |
Output is correct |
18 |
Correct |
18 ms |
24464 KB |
Output is correct |
19 |
Correct |
184 ms |
48632 KB |
Output is correct |
20 |
Correct |
203 ms |
48556 KB |
Output is correct |
21 |
Correct |
177 ms |
48464 KB |
Output is correct |
22 |
Correct |
180 ms |
48400 KB |
Output is correct |
23 |
Correct |
180 ms |
48472 KB |
Output is correct |
24 |
Correct |
150 ms |
39992 KB |
Output is correct |
25 |
Correct |
147 ms |
40088 KB |
Output is correct |
26 |
Correct |
174 ms |
40400 KB |
Output is correct |
27 |
Correct |
149 ms |
40260 KB |
Output is correct |
28 |
Correct |
167 ms |
40276 KB |
Output is correct |
29 |
Correct |
148 ms |
40360 KB |
Output is correct |
30 |
Correct |
166 ms |
40296 KB |
Output is correct |
31 |
Correct |
156 ms |
40476 KB |
Output is correct |
32 |
Correct |
150 ms |
40260 KB |
Output is correct |
33 |
Correct |
149 ms |
40364 KB |
Output is correct |
34 |
Correct |
148 ms |
40128 KB |
Output is correct |
35 |
Correct |
159 ms |
40060 KB |
Output is correct |
36 |
Correct |
162 ms |
39924 KB |
Output is correct |
37 |
Correct |
134 ms |
39920 KB |
Output is correct |
38 |
Correct |
150 ms |
40028 KB |
Output is correct |
39 |
Correct |
146 ms |
41716 KB |
Output is correct |
40 |
Correct |
131 ms |
38696 KB |
Output is correct |
41 |
Correct |
152 ms |
43952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
14 ms |
23764 KB |
Output is correct |
3 |
Correct |
15 ms |
23892 KB |
Output is correct |
4 |
Correct |
14 ms |
23892 KB |
Output is correct |
5 |
Correct |
13 ms |
23808 KB |
Output is correct |
6 |
Correct |
15 ms |
23960 KB |
Output is correct |
7 |
Correct |
15 ms |
23892 KB |
Output is correct |
8 |
Correct |
16 ms |
23836 KB |
Output is correct |
9 |
Correct |
14 ms |
23916 KB |
Output is correct |
10 |
Correct |
14 ms |
23952 KB |
Output is correct |
11 |
Correct |
15 ms |
24216 KB |
Output is correct |
12 |
Correct |
20 ms |
24436 KB |
Output is correct |
13 |
Correct |
17 ms |
24484 KB |
Output is correct |
14 |
Correct |
19 ms |
24528 KB |
Output is correct |
15 |
Correct |
17 ms |
24536 KB |
Output is correct |
16 |
Correct |
17 ms |
24376 KB |
Output is correct |
17 |
Correct |
17 ms |
24292 KB |
Output is correct |
18 |
Correct |
18 ms |
24464 KB |
Output is correct |
19 |
Correct |
926 ms |
114180 KB |
Output is correct |
20 |
Correct |
928 ms |
147208 KB |
Output is correct |
21 |
Correct |
939 ms |
147104 KB |
Output is correct |
22 |
Correct |
997 ms |
147244 KB |
Output is correct |
23 |
Correct |
705 ms |
105848 KB |
Output is correct |
24 |
Correct |
100 ms |
33000 KB |
Output is correct |
25 |
Correct |
94 ms |
34876 KB |
Output is correct |
26 |
Correct |
71 ms |
30756 KB |
Output is correct |
27 |
Correct |
73 ms |
30752 KB |
Output is correct |
28 |
Correct |
70 ms |
30836 KB |
Output is correct |
29 |
Correct |
70 ms |
31016 KB |
Output is correct |
30 |
Correct |
76 ms |
31032 KB |
Output is correct |
31 |
Correct |
86 ms |
33644 KB |
Output is correct |
32 |
Correct |
55 ms |
29432 KB |
Output is correct |
33 |
Correct |
85 ms |
33208 KB |
Output is correct |
34 |
Correct |
184 ms |
48632 KB |
Output is correct |
35 |
Correct |
203 ms |
48556 KB |
Output is correct |
36 |
Correct |
177 ms |
48464 KB |
Output is correct |
37 |
Correct |
180 ms |
48400 KB |
Output is correct |
38 |
Correct |
180 ms |
48472 KB |
Output is correct |
39 |
Correct |
150 ms |
39992 KB |
Output is correct |
40 |
Correct |
147 ms |
40088 KB |
Output is correct |
41 |
Correct |
174 ms |
40400 KB |
Output is correct |
42 |
Correct |
149 ms |
40260 KB |
Output is correct |
43 |
Correct |
167 ms |
40276 KB |
Output is correct |
44 |
Correct |
148 ms |
40360 KB |
Output is correct |
45 |
Correct |
166 ms |
40296 KB |
Output is correct |
46 |
Correct |
156 ms |
40476 KB |
Output is correct |
47 |
Correct |
150 ms |
40260 KB |
Output is correct |
48 |
Correct |
149 ms |
40364 KB |
Output is correct |
49 |
Correct |
148 ms |
40128 KB |
Output is correct |
50 |
Correct |
159 ms |
40060 KB |
Output is correct |
51 |
Correct |
162 ms |
39924 KB |
Output is correct |
52 |
Correct |
134 ms |
39920 KB |
Output is correct |
53 |
Correct |
150 ms |
40028 KB |
Output is correct |
54 |
Correct |
146 ms |
41716 KB |
Output is correct |
55 |
Correct |
131 ms |
38696 KB |
Output is correct |
56 |
Correct |
152 ms |
43952 KB |
Output is correct |
57 |
Correct |
950 ms |
147836 KB |
Output is correct |
58 |
Correct |
951 ms |
147912 KB |
Output is correct |
59 |
Correct |
907 ms |
147844 KB |
Output is correct |
60 |
Correct |
922 ms |
147624 KB |
Output is correct |
61 |
Correct |
964 ms |
147632 KB |
Output is correct |
62 |
Correct |
918 ms |
147616 KB |
Output is correct |
63 |
Correct |
735 ms |
104420 KB |
Output is correct |
64 |
Correct |
724 ms |
104472 KB |
Output is correct |
65 |
Correct |
757 ms |
106264 KB |
Output is correct |
66 |
Correct |
707 ms |
106300 KB |
Output is correct |
67 |
Correct |
741 ms |
106232 KB |
Output is correct |
68 |
Correct |
725 ms |
106356 KB |
Output is correct |
69 |
Correct |
736 ms |
106464 KB |
Output is correct |
70 |
Correct |
788 ms |
106428 KB |
Output is correct |
71 |
Correct |
754 ms |
106460 KB |
Output is correct |
72 |
Correct |
790 ms |
106408 KB |
Output is correct |
73 |
Correct |
697 ms |
102988 KB |
Output is correct |
74 |
Correct |
813 ms |
103228 KB |
Output is correct |
75 |
Correct |
699 ms |
102204 KB |
Output is correct |
76 |
Correct |
721 ms |
102220 KB |
Output is correct |
77 |
Correct |
755 ms |
102092 KB |
Output is correct |
78 |
Correct |
777 ms |
113200 KB |
Output is correct |
79 |
Correct |
639 ms |
95620 KB |
Output is correct |
80 |
Correct |
799 ms |
127204 KB |
Output is correct |