#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include<bits/extc++.h>
//__gnu_pbds
struct BIT{
vector<int> arr;
int n;
void init(int s){
n = s;
arr.resize(n+1,0);
}
void update(int i,int v){
while(i){
arr[i] = max(arr[i],v);
i-=(i&-i);
}
}
int query(int i){
int r = 0;
while(i<=n){
r = max(r,arr[i]);
i+=(i&-i);
}
return r;
}
} bit;
stack<pair<int,int> > stk;
struct query{
int l;
int r;
int k;
int t;
bool ans;
};
int main(){
ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int n,q;cin>>n>>q;
bit.init(n);
int arr[n+1];
for(int i=1;i<=n;i++) cin>>arr[i];
vector<query> qu(q);
for(int i=0;i<q;i++){
cin>>qu[i].l>>qu[i].r>>qu[i].k;
qu[i].t = i;
}
sort(qu.begin(),qu.end(),[](const query &a,const query &b){return a.r<b.r;});
int p = 0;
for(int i=1;i<=n;i++){
while(stk.size() && stk.top().second<=arr[i]) stk.pop();
if(stk.size()) bit.update(stk.top().first,arr[i]+stk.top().second);
stk.push({i,arr[i]});
while(p<q && qu[p].r==i){
qu[p].ans = bit.query(qu[p].l)<=qu[p].k;
p++;
}
}
sort(qu.begin(),qu.end(),[](const query &a,const query &b){return a.t<b.t;});
for(int i=0;i<q;i++){
cout<<qu[i].ans<<'\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
4 ms |
592 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
642 ms |
29632 KB |
Output is correct |
2 |
Correct |
652 ms |
60240 KB |
Output is correct |
3 |
Correct |
664 ms |
62360 KB |
Output is correct |
4 |
Correct |
662 ms |
60116 KB |
Output is correct |
5 |
Correct |
645 ms |
60080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
3192 KB |
Output is correct |
2 |
Correct |
56 ms |
5168 KB |
Output is correct |
3 |
Correct |
53 ms |
5160 KB |
Output is correct |
4 |
Correct |
52 ms |
5168 KB |
Output is correct |
5 |
Correct |
52 ms |
5228 KB |
Output is correct |
6 |
Correct |
50 ms |
5052 KB |
Output is correct |
7 |
Correct |
50 ms |
5084 KB |
Output is correct |
8 |
Correct |
50 ms |
4840 KB |
Output is correct |
9 |
Correct |
39 ms |
3788 KB |
Output is correct |
10 |
Correct |
54 ms |
4812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
4 ms |
592 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
129 ms |
12780 KB |
Output is correct |
20 |
Correct |
131 ms |
12756 KB |
Output is correct |
21 |
Correct |
133 ms |
12576 KB |
Output is correct |
22 |
Correct |
134 ms |
12620 KB |
Output is correct |
23 |
Correct |
124 ms |
12576 KB |
Output is correct |
24 |
Correct |
125 ms |
12496 KB |
Output is correct |
25 |
Correct |
119 ms |
12436 KB |
Output is correct |
26 |
Correct |
124 ms |
12664 KB |
Output is correct |
27 |
Correct |
125 ms |
12600 KB |
Output is correct |
28 |
Correct |
128 ms |
12704 KB |
Output is correct |
29 |
Correct |
124 ms |
12696 KB |
Output is correct |
30 |
Correct |
124 ms |
12712 KB |
Output is correct |
31 |
Correct |
125 ms |
12676 KB |
Output is correct |
32 |
Correct |
121 ms |
12700 KB |
Output is correct |
33 |
Correct |
130 ms |
12696 KB |
Output is correct |
34 |
Correct |
121 ms |
12360 KB |
Output is correct |
35 |
Correct |
124 ms |
12360 KB |
Output is correct |
36 |
Correct |
113 ms |
12104 KB |
Output is correct |
37 |
Correct |
122 ms |
12208 KB |
Output is correct |
38 |
Correct |
123 ms |
12360 KB |
Output is correct |
39 |
Correct |
115 ms |
11348 KB |
Output is correct |
40 |
Correct |
102 ms |
10060 KB |
Output is correct |
41 |
Correct |
112 ms |
10904 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
468 KB |
Output is correct |
14 |
Correct |
4 ms |
596 KB |
Output is correct |
15 |
Correct |
4 ms |
592 KB |
Output is correct |
16 |
Correct |
3 ms |
468 KB |
Output is correct |
17 |
Correct |
3 ms |
468 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
642 ms |
29632 KB |
Output is correct |
20 |
Correct |
652 ms |
60240 KB |
Output is correct |
21 |
Correct |
664 ms |
62360 KB |
Output is correct |
22 |
Correct |
662 ms |
60116 KB |
Output is correct |
23 |
Correct |
645 ms |
60080 KB |
Output is correct |
24 |
Correct |
52 ms |
3192 KB |
Output is correct |
25 |
Correct |
56 ms |
5168 KB |
Output is correct |
26 |
Correct |
53 ms |
5160 KB |
Output is correct |
27 |
Correct |
52 ms |
5168 KB |
Output is correct |
28 |
Correct |
52 ms |
5228 KB |
Output is correct |
29 |
Correct |
50 ms |
5052 KB |
Output is correct |
30 |
Correct |
50 ms |
5084 KB |
Output is correct |
31 |
Correct |
50 ms |
4840 KB |
Output is correct |
32 |
Correct |
39 ms |
3788 KB |
Output is correct |
33 |
Correct |
54 ms |
4812 KB |
Output is correct |
34 |
Correct |
129 ms |
12780 KB |
Output is correct |
35 |
Correct |
131 ms |
12756 KB |
Output is correct |
36 |
Correct |
133 ms |
12576 KB |
Output is correct |
37 |
Correct |
134 ms |
12620 KB |
Output is correct |
38 |
Correct |
124 ms |
12576 KB |
Output is correct |
39 |
Correct |
125 ms |
12496 KB |
Output is correct |
40 |
Correct |
119 ms |
12436 KB |
Output is correct |
41 |
Correct |
124 ms |
12664 KB |
Output is correct |
42 |
Correct |
125 ms |
12600 KB |
Output is correct |
43 |
Correct |
128 ms |
12704 KB |
Output is correct |
44 |
Correct |
124 ms |
12696 KB |
Output is correct |
45 |
Correct |
124 ms |
12712 KB |
Output is correct |
46 |
Correct |
125 ms |
12676 KB |
Output is correct |
47 |
Correct |
121 ms |
12700 KB |
Output is correct |
48 |
Correct |
130 ms |
12696 KB |
Output is correct |
49 |
Correct |
121 ms |
12360 KB |
Output is correct |
50 |
Correct |
124 ms |
12360 KB |
Output is correct |
51 |
Correct |
113 ms |
12104 KB |
Output is correct |
52 |
Correct |
122 ms |
12208 KB |
Output is correct |
53 |
Correct |
123 ms |
12360 KB |
Output is correct |
54 |
Correct |
115 ms |
11348 KB |
Output is correct |
55 |
Correct |
102 ms |
10060 KB |
Output is correct |
56 |
Correct |
112 ms |
10904 KB |
Output is correct |
57 |
Correct |
684 ms |
52756 KB |
Output is correct |
58 |
Correct |
677 ms |
52880 KB |
Output is correct |
59 |
Correct |
658 ms |
53580 KB |
Output is correct |
60 |
Correct |
663 ms |
53552 KB |
Output is correct |
61 |
Correct |
643 ms |
53580 KB |
Output is correct |
62 |
Correct |
687 ms |
53604 KB |
Output is correct |
63 |
Correct |
620 ms |
61236 KB |
Output is correct |
64 |
Correct |
617 ms |
61372 KB |
Output is correct |
65 |
Correct |
634 ms |
53868 KB |
Output is correct |
66 |
Correct |
640 ms |
53760 KB |
Output is correct |
67 |
Correct |
626 ms |
53848 KB |
Output is correct |
68 |
Correct |
630 ms |
52800 KB |
Output is correct |
69 |
Correct |
625 ms |
52824 KB |
Output is correct |
70 |
Correct |
619 ms |
52796 KB |
Output is correct |
71 |
Correct |
652 ms |
53000 KB |
Output is correct |
72 |
Correct |
648 ms |
52796 KB |
Output is correct |
73 |
Correct |
593 ms |
59692 KB |
Output is correct |
74 |
Correct |
630 ms |
60748 KB |
Output is correct |
75 |
Correct |
597 ms |
59704 KB |
Output is correct |
76 |
Correct |
613 ms |
59692 KB |
Output is correct |
77 |
Correct |
605 ms |
59712 KB |
Output is correct |
78 |
Correct |
597 ms |
57028 KB |
Output is correct |
79 |
Correct |
522 ms |
48544 KB |
Output is correct |
80 |
Correct |
585 ms |
54384 KB |
Output is correct |