//Dost SEFEROĞLU
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int MOD = 1e9+7,inf = 2e18;
const int N = 5001;
struct Query {
int l=0,r=0,k=0,id=0;
};
struct FT
{
int n;
vi bit;
FT(int nn) {
n = nn;
bit.assign(n+1,0);
}
void put(int p,int v) {
for(int i=p;i<=n;i+=i&-i) bit[i]=max(bit[i],v);
}
int get(int p) {
int ans = 0;
for (int i=p;i>0;i-=i&-i) ans=max(ans,bit[i]);
return ans;
}
};
void solve() {
int n,q;
cin >> n >> q;
vi a(n+1);
for (int i=1;i<=n;i++) cin >> a[i];
vector<Query> queries(q+1);
for (int i=1;i<=q;i++) {
Query& Q = queries[i];
cin >> Q.l >> Q.r >> Q.k;
Q.id = i;
}
vector<Query> rq[n+1];
for (int i=1;i<=q;i++) {
rq[queries[i].r].push_back(queries[i]);
}
vi ans(q+1);
a[0] = inf;
FT ft(n);
vi st{0};
for (int i=1;i<=n;i++) {
while (a[st.back()] <= a[i]) st.pop_back();
if (st.back()) ft.put(n-st.back()+1,a[i]+a[st.back()]);
for (auto Q : rq[i]){
ans[Q.id] = ft.get(n-Q.l+1);
}
st.push_back(i);
}
for (int i=1;i<=q;i++) cout << (ans[i]<=queries[i].k) << '\n';
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
956 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
2 ms |
1116 KB |
Output is correct |
18 |
Correct |
2 ms |
980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
586 ms |
123992 KB |
Output is correct |
2 |
Correct |
633 ms |
156872 KB |
Output is correct |
3 |
Correct |
627 ms |
156744 KB |
Output is correct |
4 |
Correct |
640 ms |
157012 KB |
Output is correct |
5 |
Correct |
594 ms |
156972 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
40 ms |
12776 KB |
Output is correct |
2 |
Correct |
37 ms |
12884 KB |
Output is correct |
3 |
Correct |
36 ms |
12624 KB |
Output is correct |
4 |
Correct |
40 ms |
12628 KB |
Output is correct |
5 |
Correct |
39 ms |
12636 KB |
Output is correct |
6 |
Correct |
29 ms |
12884 KB |
Output is correct |
7 |
Correct |
28 ms |
12880 KB |
Output is correct |
8 |
Correct |
43 ms |
12428 KB |
Output is correct |
9 |
Correct |
22 ms |
8388 KB |
Output is correct |
10 |
Correct |
34 ms |
12228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
956 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
2 ms |
1116 KB |
Output is correct |
18 |
Correct |
2 ms |
980 KB |
Output is correct |
19 |
Correct |
94 ms |
31568 KB |
Output is correct |
20 |
Correct |
91 ms |
31568 KB |
Output is correct |
21 |
Correct |
87 ms |
32200 KB |
Output is correct |
22 |
Correct |
87 ms |
32084 KB |
Output is correct |
23 |
Correct |
82 ms |
32084 KB |
Output is correct |
24 |
Correct |
81 ms |
32188 KB |
Output is correct |
25 |
Correct |
86 ms |
32340 KB |
Output is correct |
26 |
Correct |
89 ms |
31820 KB |
Output is correct |
27 |
Correct |
93 ms |
31824 KB |
Output is correct |
28 |
Correct |
83 ms |
31820 KB |
Output is correct |
29 |
Correct |
90 ms |
31704 KB |
Output is correct |
30 |
Correct |
93 ms |
31580 KB |
Output is correct |
31 |
Correct |
98 ms |
31568 KB |
Output is correct |
32 |
Correct |
97 ms |
31700 KB |
Output is correct |
33 |
Correct |
85 ms |
31580 KB |
Output is correct |
34 |
Correct |
81 ms |
31572 KB |
Output is correct |
35 |
Correct |
72 ms |
31316 KB |
Output is correct |
36 |
Correct |
82 ms |
31332 KB |
Output is correct |
37 |
Correct |
74 ms |
31184 KB |
Output is correct |
38 |
Correct |
82 ms |
31568 KB |
Output is correct |
39 |
Correct |
84 ms |
29628 KB |
Output is correct |
40 |
Correct |
71 ms |
25792 KB |
Output is correct |
41 |
Correct |
75 ms |
29120 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
956 KB |
Output is correct |
13 |
Correct |
2 ms |
860 KB |
Output is correct |
14 |
Correct |
2 ms |
1116 KB |
Output is correct |
15 |
Correct |
2 ms |
1116 KB |
Output is correct |
16 |
Correct |
2 ms |
1112 KB |
Output is correct |
17 |
Correct |
2 ms |
1116 KB |
Output is correct |
18 |
Correct |
2 ms |
980 KB |
Output is correct |
19 |
Correct |
586 ms |
123992 KB |
Output is correct |
20 |
Correct |
633 ms |
156872 KB |
Output is correct |
21 |
Correct |
627 ms |
156744 KB |
Output is correct |
22 |
Correct |
640 ms |
157012 KB |
Output is correct |
23 |
Correct |
594 ms |
156972 KB |
Output is correct |
24 |
Correct |
40 ms |
12776 KB |
Output is correct |
25 |
Correct |
37 ms |
12884 KB |
Output is correct |
26 |
Correct |
36 ms |
12624 KB |
Output is correct |
27 |
Correct |
40 ms |
12628 KB |
Output is correct |
28 |
Correct |
39 ms |
12636 KB |
Output is correct |
29 |
Correct |
29 ms |
12884 KB |
Output is correct |
30 |
Correct |
28 ms |
12880 KB |
Output is correct |
31 |
Correct |
43 ms |
12428 KB |
Output is correct |
32 |
Correct |
22 ms |
8388 KB |
Output is correct |
33 |
Correct |
34 ms |
12228 KB |
Output is correct |
34 |
Correct |
94 ms |
31568 KB |
Output is correct |
35 |
Correct |
91 ms |
31568 KB |
Output is correct |
36 |
Correct |
87 ms |
32200 KB |
Output is correct |
37 |
Correct |
87 ms |
32084 KB |
Output is correct |
38 |
Correct |
82 ms |
32084 KB |
Output is correct |
39 |
Correct |
81 ms |
32188 KB |
Output is correct |
40 |
Correct |
86 ms |
32340 KB |
Output is correct |
41 |
Correct |
89 ms |
31820 KB |
Output is correct |
42 |
Correct |
93 ms |
31824 KB |
Output is correct |
43 |
Correct |
83 ms |
31820 KB |
Output is correct |
44 |
Correct |
90 ms |
31704 KB |
Output is correct |
45 |
Correct |
93 ms |
31580 KB |
Output is correct |
46 |
Correct |
98 ms |
31568 KB |
Output is correct |
47 |
Correct |
97 ms |
31700 KB |
Output is correct |
48 |
Correct |
85 ms |
31580 KB |
Output is correct |
49 |
Correct |
81 ms |
31572 KB |
Output is correct |
50 |
Correct |
72 ms |
31316 KB |
Output is correct |
51 |
Correct |
82 ms |
31332 KB |
Output is correct |
52 |
Correct |
74 ms |
31184 KB |
Output is correct |
53 |
Correct |
82 ms |
31568 KB |
Output is correct |
54 |
Correct |
84 ms |
29628 KB |
Output is correct |
55 |
Correct |
71 ms |
25792 KB |
Output is correct |
56 |
Correct |
75 ms |
29120 KB |
Output is correct |
57 |
Correct |
608 ms |
157780 KB |
Output is correct |
58 |
Correct |
626 ms |
157648 KB |
Output is correct |
59 |
Correct |
590 ms |
158272 KB |
Output is correct |
60 |
Correct |
564 ms |
158416 KB |
Output is correct |
61 |
Correct |
562 ms |
158176 KB |
Output is correct |
62 |
Correct |
542 ms |
158292 KB |
Output is correct |
63 |
Correct |
369 ms |
158668 KB |
Output is correct |
64 |
Correct |
385 ms |
158812 KB |
Output is correct |
65 |
Correct |
562 ms |
158364 KB |
Output is correct |
66 |
Correct |
542 ms |
158500 KB |
Output is correct |
67 |
Correct |
602 ms |
158252 KB |
Output is correct |
68 |
Correct |
621 ms |
157776 KB |
Output is correct |
69 |
Correct |
615 ms |
157672 KB |
Output is correct |
70 |
Correct |
606 ms |
157764 KB |
Output is correct |
71 |
Correct |
634 ms |
157664 KB |
Output is correct |
72 |
Correct |
600 ms |
157876 KB |
Output is correct |
73 |
Correct |
369 ms |
152148 KB |
Output is correct |
74 |
Correct |
393 ms |
152704 KB |
Output is correct |
75 |
Correct |
385 ms |
151764 KB |
Output is correct |
76 |
Correct |
364 ms |
151732 KB |
Output is correct |
77 |
Correct |
355 ms |
151512 KB |
Output is correct |
78 |
Correct |
561 ms |
148516 KB |
Output is correct |
79 |
Correct |
455 ms |
122100 KB |
Output is correct |
80 |
Correct |
565 ms |
144856 KB |
Output is correct |