#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define pb push_back
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ii = pair<int,int>;
using iii = tuple<int,int,int>;
const int inf = 2e9+1;
const int mod = 1e9+7;
const int maxn = 1e6+100;
template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
int v[maxn], bad[maxn];
struct queries{
int l, r, k, idx;
}q[maxn];
ii seg[4*maxn];
vector<int>where[maxn];
void build(int i,int l,int r){
if(l==r){
seg[i] = {bad[l], bad[l]==0?0:v[l]+v[bad[l]]};
return;
}
int md = (l+r)/2;
build(2*i,l,md), build(2*i+1,md+1,r);
if(seg[2*i].second>seg[2*i+1].second)seg[i] = seg[2*i];
else seg[i] = seg[2*i+1];
}
void update(int i,int l,int r,int x){
if(l>x||r<x)return;
if(l==r){
seg[i] = {0,0};
return;
}
int md = (l+r)/2;
update(2*i,l,md,x), update(2*i+1,md+1,r,x);
if(seg[2*i].second>seg[2*i+1].second)seg[i] = seg[2*i];
else seg[i] = seg[2*i+1];
}
int query(int i,int l,int r,int x,int y){
if(l>y||r<x)return 0;
if(x<=l&&r<=y)return seg[i].second;
int md = (l+r)/2;
return max(query(2*i,l,md,x,y),query(2*i+1,md+1,r,x,y));
}
bool sorted(queries a,queries b){
if(a.l==b.l)return a.r<b.r;
return a.l<b.l;
}
bool answer[maxn];
int main(){_
int n, m;cin>>n>>m;
for(int i=1;i<=n;++i)cin>>v[i];
for(int i=1;i<=m;++i){
cin>>q[i].l>>q[i].r>>q[i].k;
q[i].idx = i;
}
stack<ii>st;
for(int i=1;i<=n;++i){
while(!st.empty()&&st.top().first<=v[i])st.pop();
if(!st.empty()){
bad[i] = st.top().second;
where[bad[i]].pb(i);
}
st.push({v[i],i});
}
sort(q+1,q+1+m, sorted);
int leftPointer = 1;
build(1,1,n);
for(int i=1;i<=m;++i){
while(leftPointer<q[i].l){
for(auto x:where[leftPointer]){
update(1,1,n,x);
}
leftPointer++;
}
int mx = query(1,1,n,q[i].l,q[i].r);
answer[q[i].idx] = mx<=q[i].k;
}
for(int i=1;i<=m;++i)cout<<answer[i]<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
15 ms |
23824 KB |
Output is correct |
3 |
Correct |
13 ms |
23756 KB |
Output is correct |
4 |
Correct |
12 ms |
23840 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23892 KB |
Output is correct |
7 |
Correct |
14 ms |
23824 KB |
Output is correct |
8 |
Correct |
13 ms |
23832 KB |
Output is correct |
9 |
Correct |
17 ms |
23800 KB |
Output is correct |
10 |
Correct |
17 ms |
23764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
15 ms |
23824 KB |
Output is correct |
3 |
Correct |
13 ms |
23756 KB |
Output is correct |
4 |
Correct |
12 ms |
23840 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23892 KB |
Output is correct |
7 |
Correct |
14 ms |
23824 KB |
Output is correct |
8 |
Correct |
13 ms |
23832 KB |
Output is correct |
9 |
Correct |
17 ms |
23800 KB |
Output is correct |
10 |
Correct |
17 ms |
23764 KB |
Output is correct |
11 |
Correct |
18 ms |
24028 KB |
Output is correct |
12 |
Correct |
19 ms |
24148 KB |
Output is correct |
13 |
Correct |
16 ms |
24224 KB |
Output is correct |
14 |
Correct |
17 ms |
24276 KB |
Output is correct |
15 |
Correct |
16 ms |
24224 KB |
Output is correct |
16 |
Correct |
17 ms |
24196 KB |
Output is correct |
17 |
Correct |
18 ms |
24160 KB |
Output is correct |
18 |
Correct |
16 ms |
24152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1286 ms |
114796 KB |
Output is correct |
2 |
Correct |
1427 ms |
115788 KB |
Output is correct |
3 |
Correct |
1407 ms |
115572 KB |
Output is correct |
4 |
Correct |
1350 ms |
115756 KB |
Output is correct |
5 |
Correct |
1152 ms |
95524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
111 ms |
32016 KB |
Output is correct |
2 |
Correct |
95 ms |
31996 KB |
Output is correct |
3 |
Correct |
96 ms |
30076 KB |
Output is correct |
4 |
Correct |
127 ms |
30068 KB |
Output is correct |
5 |
Correct |
89 ms |
30096 KB |
Output is correct |
6 |
Correct |
90 ms |
30072 KB |
Output is correct |
7 |
Correct |
108 ms |
30044 KB |
Output is correct |
8 |
Correct |
117 ms |
30544 KB |
Output is correct |
9 |
Correct |
55 ms |
27004 KB |
Output is correct |
10 |
Correct |
84 ms |
30268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
15 ms |
23824 KB |
Output is correct |
3 |
Correct |
13 ms |
23756 KB |
Output is correct |
4 |
Correct |
12 ms |
23840 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23892 KB |
Output is correct |
7 |
Correct |
14 ms |
23824 KB |
Output is correct |
8 |
Correct |
13 ms |
23832 KB |
Output is correct |
9 |
Correct |
17 ms |
23800 KB |
Output is correct |
10 |
Correct |
17 ms |
23764 KB |
Output is correct |
11 |
Correct |
18 ms |
24028 KB |
Output is correct |
12 |
Correct |
19 ms |
24148 KB |
Output is correct |
13 |
Correct |
16 ms |
24224 KB |
Output is correct |
14 |
Correct |
17 ms |
24276 KB |
Output is correct |
15 |
Correct |
16 ms |
24224 KB |
Output is correct |
16 |
Correct |
17 ms |
24196 KB |
Output is correct |
17 |
Correct |
18 ms |
24160 KB |
Output is correct |
18 |
Correct |
16 ms |
24152 KB |
Output is correct |
19 |
Correct |
254 ms |
43044 KB |
Output is correct |
20 |
Correct |
276 ms |
43036 KB |
Output is correct |
21 |
Correct |
213 ms |
42892 KB |
Output is correct |
22 |
Correct |
203 ms |
42968 KB |
Output is correct |
23 |
Correct |
214 ms |
42800 KB |
Output is correct |
24 |
Correct |
199 ms |
38796 KB |
Output is correct |
25 |
Correct |
202 ms |
38676 KB |
Output is correct |
26 |
Correct |
195 ms |
38892 KB |
Output is correct |
27 |
Correct |
228 ms |
38944 KB |
Output is correct |
28 |
Correct |
223 ms |
38952 KB |
Output is correct |
29 |
Correct |
223 ms |
39032 KB |
Output is correct |
30 |
Correct |
282 ms |
39056 KB |
Output is correct |
31 |
Correct |
220 ms |
39032 KB |
Output is correct |
32 |
Correct |
287 ms |
39028 KB |
Output is correct |
33 |
Correct |
207 ms |
39036 KB |
Output is correct |
34 |
Correct |
217 ms |
38732 KB |
Output is correct |
35 |
Correct |
195 ms |
38672 KB |
Output is correct |
36 |
Correct |
185 ms |
38388 KB |
Output is correct |
37 |
Correct |
184 ms |
38456 KB |
Output is correct |
38 |
Correct |
184 ms |
38584 KB |
Output is correct |
39 |
Correct |
205 ms |
38984 KB |
Output is correct |
40 |
Correct |
161 ms |
34872 KB |
Output is correct |
41 |
Correct |
208 ms |
38292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23764 KB |
Output is correct |
2 |
Correct |
15 ms |
23824 KB |
Output is correct |
3 |
Correct |
13 ms |
23756 KB |
Output is correct |
4 |
Correct |
12 ms |
23840 KB |
Output is correct |
5 |
Correct |
13 ms |
23764 KB |
Output is correct |
6 |
Correct |
13 ms |
23892 KB |
Output is correct |
7 |
Correct |
14 ms |
23824 KB |
Output is correct |
8 |
Correct |
13 ms |
23832 KB |
Output is correct |
9 |
Correct |
17 ms |
23800 KB |
Output is correct |
10 |
Correct |
17 ms |
23764 KB |
Output is correct |
11 |
Correct |
18 ms |
24028 KB |
Output is correct |
12 |
Correct |
19 ms |
24148 KB |
Output is correct |
13 |
Correct |
16 ms |
24224 KB |
Output is correct |
14 |
Correct |
17 ms |
24276 KB |
Output is correct |
15 |
Correct |
16 ms |
24224 KB |
Output is correct |
16 |
Correct |
17 ms |
24196 KB |
Output is correct |
17 |
Correct |
18 ms |
24160 KB |
Output is correct |
18 |
Correct |
16 ms |
24152 KB |
Output is correct |
19 |
Correct |
1286 ms |
114796 KB |
Output is correct |
20 |
Correct |
1427 ms |
115788 KB |
Output is correct |
21 |
Correct |
1407 ms |
115572 KB |
Output is correct |
22 |
Correct |
1350 ms |
115756 KB |
Output is correct |
23 |
Correct |
1152 ms |
95524 KB |
Output is correct |
24 |
Correct |
111 ms |
32016 KB |
Output is correct |
25 |
Correct |
95 ms |
31996 KB |
Output is correct |
26 |
Correct |
96 ms |
30076 KB |
Output is correct |
27 |
Correct |
127 ms |
30068 KB |
Output is correct |
28 |
Correct |
89 ms |
30096 KB |
Output is correct |
29 |
Correct |
90 ms |
30072 KB |
Output is correct |
30 |
Correct |
108 ms |
30044 KB |
Output is correct |
31 |
Correct |
117 ms |
30544 KB |
Output is correct |
32 |
Correct |
55 ms |
27004 KB |
Output is correct |
33 |
Correct |
84 ms |
30268 KB |
Output is correct |
34 |
Correct |
254 ms |
43044 KB |
Output is correct |
35 |
Correct |
276 ms |
43036 KB |
Output is correct |
36 |
Correct |
213 ms |
42892 KB |
Output is correct |
37 |
Correct |
203 ms |
42968 KB |
Output is correct |
38 |
Correct |
214 ms |
42800 KB |
Output is correct |
39 |
Correct |
199 ms |
38796 KB |
Output is correct |
40 |
Correct |
202 ms |
38676 KB |
Output is correct |
41 |
Correct |
195 ms |
38892 KB |
Output is correct |
42 |
Correct |
228 ms |
38944 KB |
Output is correct |
43 |
Correct |
223 ms |
38952 KB |
Output is correct |
44 |
Correct |
223 ms |
39032 KB |
Output is correct |
45 |
Correct |
282 ms |
39056 KB |
Output is correct |
46 |
Correct |
220 ms |
39032 KB |
Output is correct |
47 |
Correct |
287 ms |
39028 KB |
Output is correct |
48 |
Correct |
207 ms |
39036 KB |
Output is correct |
49 |
Correct |
217 ms |
38732 KB |
Output is correct |
50 |
Correct |
195 ms |
38672 KB |
Output is correct |
51 |
Correct |
185 ms |
38388 KB |
Output is correct |
52 |
Correct |
184 ms |
38456 KB |
Output is correct |
53 |
Correct |
184 ms |
38584 KB |
Output is correct |
54 |
Correct |
205 ms |
38984 KB |
Output is correct |
55 |
Correct |
161 ms |
34872 KB |
Output is correct |
56 |
Correct |
208 ms |
38292 KB |
Output is correct |
57 |
Correct |
1309 ms |
116396 KB |
Output is correct |
58 |
Correct |
1350 ms |
116464 KB |
Output is correct |
59 |
Correct |
1189 ms |
116396 KB |
Output is correct |
60 |
Correct |
1205 ms |
116304 KB |
Output is correct |
61 |
Correct |
1262 ms |
116324 KB |
Output is correct |
62 |
Correct |
1206 ms |
116388 KB |
Output is correct |
63 |
Correct |
882 ms |
94320 KB |
Output is correct |
64 |
Correct |
888 ms |
94356 KB |
Output is correct |
65 |
Correct |
1068 ms |
96260 KB |
Output is correct |
66 |
Correct |
1076 ms |
96208 KB |
Output is correct |
67 |
Correct |
1107 ms |
96212 KB |
Output is correct |
68 |
Correct |
1185 ms |
96292 KB |
Output is correct |
69 |
Correct |
1206 ms |
96356 KB |
Output is correct |
70 |
Correct |
1067 ms |
96280 KB |
Output is correct |
71 |
Correct |
1070 ms |
96284 KB |
Output is correct |
72 |
Correct |
1031 ms |
96288 KB |
Output is correct |
73 |
Correct |
917 ms |
92852 KB |
Output is correct |
74 |
Correct |
1106 ms |
93860 KB |
Output is correct |
75 |
Correct |
950 ms |
92844 KB |
Output is correct |
76 |
Correct |
920 ms |
92808 KB |
Output is correct |
77 |
Correct |
943 ms |
92852 KB |
Output is correct |
78 |
Correct |
999 ms |
96956 KB |
Output is correct |
79 |
Correct |
749 ms |
76408 KB |
Output is correct |
80 |
Correct |
1006 ms |
94040 KB |
Output is correct |