#include<bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int aint[4*N];
/*void build(int nod,int l,int r){
if(l == r){
aint[nod] = INT_MIN;
return;
}
int mid = (l + r)/2;
build(2*nod, l, mid);
build(2*nod + 1, mid+1, r);
aint[nod] = INT_MIN;
}*/
void update(int nod, int l, int r, int upoz,int val){
if(upoz < l || upoz > r)
return;
if(l == r){
aint[nod] = val;
return;
}
int mid = (l + r)/2;
update(2*nod, l, mid, upoz, val);
update(2*nod + 1, mid+1, r, upoz, val);
aint[nod] = max(aint[2*nod], aint[2*nod + 1]);
}
int query(int nod,int l,int r, int ql, int qr){
if(r < ql || l > qr)
return INT_MIN;
if(ql <=l && r <= qr)
return aint[nod];
int mid = (l + r)/2;
int ls = query(2*nod, l, mid, ql, qr);
int rs = query(2*nod + 1, mid+1, r, ql, qr);
return max(ls, rs);
}
struct qry{
int poz, w;
int id;
};
int v[N];
int ans[N];
vector<qry> qu[N];
int st[N];
int main()
{
//freopen(".in","r",stdin);
ios::sync_with_stdio(false);
cin.tie(0),cout.tie(0);
int n, q;
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>v[i];
}
//build(1, 1, n);
for(int i = 1; i<=q;i ++){
int l, r, w;
cin>>l>>r>>w;
qu[r].push_back({l, w, i});
}
int vf =0;
for(int i=1;i<=n;i++){
while(vf > 0 && v[st[vf]] <= v[i])
vf--;
if(vf){
//cout<<st[vf]<<" "<<v[st[vf]]<<" "<<v[i] + v[st[vf]]<<endl;
update(1, 1, n, st[vf], v[i] + v[st[vf]]);
}
st[++vf] = i;
for(auto x:qu[i]){
if(query(1, 1, n, x.poz, i) > x.w)
ans[x.id] = 0;
else
ans[x.id] = 1;
}
}
for(int i=1;i<=q;i++)
cout<<ans[i]<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23916 KB |
Output is correct |
2 |
Correct |
15 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
15 ms |
23916 KB |
Output is correct |
5 |
Correct |
15 ms |
23916 KB |
Output is correct |
6 |
Correct |
15 ms |
23916 KB |
Output is correct |
7 |
Correct |
15 ms |
23916 KB |
Output is correct |
8 |
Correct |
15 ms |
23916 KB |
Output is correct |
9 |
Correct |
15 ms |
23916 KB |
Output is correct |
10 |
Correct |
15 ms |
23916 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23916 KB |
Output is correct |
2 |
Correct |
15 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
15 ms |
23916 KB |
Output is correct |
5 |
Correct |
15 ms |
23916 KB |
Output is correct |
6 |
Correct |
15 ms |
23916 KB |
Output is correct |
7 |
Correct |
15 ms |
23916 KB |
Output is correct |
8 |
Correct |
15 ms |
23916 KB |
Output is correct |
9 |
Correct |
15 ms |
23916 KB |
Output is correct |
10 |
Correct |
15 ms |
23916 KB |
Output is correct |
11 |
Correct |
18 ms |
24044 KB |
Output is correct |
12 |
Correct |
18 ms |
24172 KB |
Output is correct |
13 |
Correct |
19 ms |
24172 KB |
Output is correct |
14 |
Correct |
20 ms |
24320 KB |
Output is correct |
15 |
Correct |
20 ms |
24300 KB |
Output is correct |
16 |
Correct |
19 ms |
24172 KB |
Output is correct |
17 |
Correct |
19 ms |
24172 KB |
Output is correct |
18 |
Correct |
19 ms |
24172 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1833 ms |
64724 KB |
Output is correct |
2 |
Correct |
1837 ms |
66284 KB |
Output is correct |
3 |
Correct |
1845 ms |
66412 KB |
Output is correct |
4 |
Correct |
1833 ms |
66412 KB |
Output is correct |
5 |
Correct |
1417 ms |
58092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
144 ms |
30060 KB |
Output is correct |
2 |
Correct |
131 ms |
29676 KB |
Output is correct |
3 |
Correct |
110 ms |
28908 KB |
Output is correct |
4 |
Correct |
113 ms |
28908 KB |
Output is correct |
5 |
Correct |
112 ms |
28908 KB |
Output is correct |
6 |
Correct |
94 ms |
28396 KB |
Output is correct |
7 |
Correct |
94 ms |
28396 KB |
Output is correct |
8 |
Correct |
125 ms |
28580 KB |
Output is correct |
9 |
Correct |
60 ms |
27300 KB |
Output is correct |
10 |
Correct |
107 ms |
28580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23916 KB |
Output is correct |
2 |
Correct |
15 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
15 ms |
23916 KB |
Output is correct |
5 |
Correct |
15 ms |
23916 KB |
Output is correct |
6 |
Correct |
15 ms |
23916 KB |
Output is correct |
7 |
Correct |
15 ms |
23916 KB |
Output is correct |
8 |
Correct |
15 ms |
23916 KB |
Output is correct |
9 |
Correct |
15 ms |
23916 KB |
Output is correct |
10 |
Correct |
15 ms |
23916 KB |
Output is correct |
11 |
Correct |
18 ms |
24044 KB |
Output is correct |
12 |
Correct |
18 ms |
24172 KB |
Output is correct |
13 |
Correct |
19 ms |
24172 KB |
Output is correct |
14 |
Correct |
20 ms |
24320 KB |
Output is correct |
15 |
Correct |
20 ms |
24300 KB |
Output is correct |
16 |
Correct |
19 ms |
24172 KB |
Output is correct |
17 |
Correct |
19 ms |
24172 KB |
Output is correct |
18 |
Correct |
19 ms |
24172 KB |
Output is correct |
19 |
Correct |
312 ms |
38764 KB |
Output is correct |
20 |
Correct |
309 ms |
38764 KB |
Output is correct |
21 |
Correct |
272 ms |
37996 KB |
Output is correct |
22 |
Correct |
274 ms |
38252 KB |
Output is correct |
23 |
Correct |
267 ms |
38124 KB |
Output is correct |
24 |
Correct |
212 ms |
35820 KB |
Output is correct |
25 |
Correct |
214 ms |
35948 KB |
Output is correct |
26 |
Correct |
234 ms |
36204 KB |
Output is correct |
27 |
Correct |
233 ms |
36204 KB |
Output is correct |
28 |
Correct |
238 ms |
36332 KB |
Output is correct |
29 |
Correct |
250 ms |
36716 KB |
Output is correct |
30 |
Correct |
260 ms |
36652 KB |
Output is correct |
31 |
Correct |
276 ms |
36588 KB |
Output is correct |
32 |
Correct |
267 ms |
36588 KB |
Output is correct |
33 |
Correct |
256 ms |
36716 KB |
Output is correct |
34 |
Correct |
195 ms |
35436 KB |
Output is correct |
35 |
Correct |
197 ms |
35436 KB |
Output is correct |
36 |
Correct |
188 ms |
35308 KB |
Output is correct |
37 |
Correct |
190 ms |
35308 KB |
Output is correct |
38 |
Correct |
193 ms |
35436 KB |
Output is correct |
39 |
Correct |
229 ms |
35620 KB |
Output is correct |
40 |
Correct |
182 ms |
33824 KB |
Output is correct |
41 |
Correct |
228 ms |
34464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
15 ms |
23916 KB |
Output is correct |
2 |
Correct |
15 ms |
23788 KB |
Output is correct |
3 |
Correct |
16 ms |
23916 KB |
Output is correct |
4 |
Correct |
15 ms |
23916 KB |
Output is correct |
5 |
Correct |
15 ms |
23916 KB |
Output is correct |
6 |
Correct |
15 ms |
23916 KB |
Output is correct |
7 |
Correct |
15 ms |
23916 KB |
Output is correct |
8 |
Correct |
15 ms |
23916 KB |
Output is correct |
9 |
Correct |
15 ms |
23916 KB |
Output is correct |
10 |
Correct |
15 ms |
23916 KB |
Output is correct |
11 |
Correct |
18 ms |
24044 KB |
Output is correct |
12 |
Correct |
18 ms |
24172 KB |
Output is correct |
13 |
Correct |
19 ms |
24172 KB |
Output is correct |
14 |
Correct |
20 ms |
24320 KB |
Output is correct |
15 |
Correct |
20 ms |
24300 KB |
Output is correct |
16 |
Correct |
19 ms |
24172 KB |
Output is correct |
17 |
Correct |
19 ms |
24172 KB |
Output is correct |
18 |
Correct |
19 ms |
24172 KB |
Output is correct |
19 |
Correct |
1833 ms |
64724 KB |
Output is correct |
20 |
Correct |
1837 ms |
66284 KB |
Output is correct |
21 |
Correct |
1845 ms |
66412 KB |
Output is correct |
22 |
Correct |
1833 ms |
66412 KB |
Output is correct |
23 |
Correct |
1417 ms |
58092 KB |
Output is correct |
24 |
Correct |
144 ms |
30060 KB |
Output is correct |
25 |
Correct |
131 ms |
29676 KB |
Output is correct |
26 |
Correct |
110 ms |
28908 KB |
Output is correct |
27 |
Correct |
113 ms |
28908 KB |
Output is correct |
28 |
Correct |
112 ms |
28908 KB |
Output is correct |
29 |
Correct |
94 ms |
28396 KB |
Output is correct |
30 |
Correct |
94 ms |
28396 KB |
Output is correct |
31 |
Correct |
125 ms |
28580 KB |
Output is correct |
32 |
Correct |
60 ms |
27300 KB |
Output is correct |
33 |
Correct |
107 ms |
28580 KB |
Output is correct |
34 |
Correct |
312 ms |
38764 KB |
Output is correct |
35 |
Correct |
309 ms |
38764 KB |
Output is correct |
36 |
Correct |
272 ms |
37996 KB |
Output is correct |
37 |
Correct |
274 ms |
38252 KB |
Output is correct |
38 |
Correct |
267 ms |
38124 KB |
Output is correct |
39 |
Correct |
212 ms |
35820 KB |
Output is correct |
40 |
Correct |
214 ms |
35948 KB |
Output is correct |
41 |
Correct |
234 ms |
36204 KB |
Output is correct |
42 |
Correct |
233 ms |
36204 KB |
Output is correct |
43 |
Correct |
238 ms |
36332 KB |
Output is correct |
44 |
Correct |
250 ms |
36716 KB |
Output is correct |
45 |
Correct |
260 ms |
36652 KB |
Output is correct |
46 |
Correct |
276 ms |
36588 KB |
Output is correct |
47 |
Correct |
267 ms |
36588 KB |
Output is correct |
48 |
Correct |
256 ms |
36716 KB |
Output is correct |
49 |
Correct |
195 ms |
35436 KB |
Output is correct |
50 |
Correct |
197 ms |
35436 KB |
Output is correct |
51 |
Correct |
188 ms |
35308 KB |
Output is correct |
52 |
Correct |
190 ms |
35308 KB |
Output is correct |
53 |
Correct |
193 ms |
35436 KB |
Output is correct |
54 |
Correct |
229 ms |
35620 KB |
Output is correct |
55 |
Correct |
182 ms |
33824 KB |
Output is correct |
56 |
Correct |
228 ms |
34464 KB |
Output is correct |
57 |
Correct |
1831 ms |
66324 KB |
Output is correct |
58 |
Correct |
1819 ms |
66028 KB |
Output is correct |
59 |
Correct |
1737 ms |
64520 KB |
Output is correct |
60 |
Correct |
1765 ms |
64628 KB |
Output is correct |
61 |
Correct |
1789 ms |
64488 KB |
Output is correct |
62 |
Correct |
1745 ms |
64548 KB |
Output is correct |
63 |
Correct |
1082 ms |
54636 KB |
Output is correct |
64 |
Correct |
1081 ms |
54684 KB |
Output is correct |
65 |
Correct |
1355 ms |
56172 KB |
Output is correct |
66 |
Correct |
1373 ms |
56172 KB |
Output is correct |
67 |
Correct |
1353 ms |
56428 KB |
Output is correct |
68 |
Correct |
1383 ms |
58156 KB |
Output is correct |
69 |
Correct |
1380 ms |
57836 KB |
Output is correct |
70 |
Correct |
1399 ms |
57580 KB |
Output is correct |
71 |
Correct |
1399 ms |
57560 KB |
Output is correct |
72 |
Correct |
1422 ms |
57472 KB |
Output is correct |
73 |
Correct |
950 ms |
52076 KB |
Output is correct |
74 |
Correct |
980 ms |
52204 KB |
Output is correct |
75 |
Correct |
960 ms |
52332 KB |
Output is correct |
76 |
Correct |
952 ms |
52204 KB |
Output is correct |
77 |
Correct |
947 ms |
51820 KB |
Output is correct |
78 |
Correct |
1254 ms |
58652 KB |
Output is correct |
79 |
Correct |
890 ms |
51460 KB |
Output is correct |
80 |
Correct |
1323 ms |
55488 KB |
Output is correct |