#include<bits/stdc++.h>
using namespace std;
long long n,q,a[200001],t[800004],lz[8000004];
long long k;
bool kt;
void build(long long id ,long long l,long long r)
{
if(l==r)
{
t[id]=a[l];
return;
}
long long mid=(l+r)/2;
build(id*2,l,mid);
build(id*2+1,mid+1,r);
t[id]=max(t[id*2],t[id*2+1]);
}
void update(long long id,long long l,long long r,long long pos,long long w)
{
if(l>pos||pos>r) return ;
if(l==r)
{
t[id]=max(t[id],w);
return;
}
long long mid=(l+r)/2;
update(id*2,l,mid,pos,w);
update(id*2+1,mid+1,r,pos,w);
t[id]=max(t[id*2],t[id*2+1]);
}
long long get_max(long long id,long long l,long long r,long long u,long long v)
{
if(l>v||r<u) return -1000000009;
if(u<=l&&r<=v)
{
return t[id];
}
long long mid=(l+r)/2;
return max(get_max(id*2,l,mid,u,v),get_max(id*2+1,mid+1,r,u,v));
}
vector<pair<int,pair<int,int>>> eve[100005];
long long ans[1000005];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>a[i];
}
for(int i=1;i<=q;i++)
{
long long l,r,k;
cin>>l>>r>>k;
eve[r].push_back({i,{l,k}});
}
stack<int> st;
for(int i=1;i<=n;i++)
{
while(!st.empty()&&a[st.top()]<=a[i]) st.pop();
if(st.size()) update(1,1,n,st.top(),a[st.top()]+a[i]);
st.push(i);
for(auto x:eve[i])
{
long long id=x.first,l=x.second.first,k=x.second.second;
if(get_max(1,1,n,l,i)<=k) ans[id]=1;
else ans[id]=0;
}
}
for(int i=1;i<=q;i++)
{
cout<<ans[i]<<"\n";
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
3 ms |
6748 KB |
Output is correct |
15 |
Correct |
3 ms |
6748 KB |
Output is correct |
16 |
Correct |
3 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
16 ms |
13916 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
12976 KB |
Output is correct |
2 |
Correct |
53 ms |
12876 KB |
Output is correct |
3 |
Correct |
49 ms |
10844 KB |
Output is correct |
4 |
Correct |
46 ms |
11088 KB |
Output is correct |
5 |
Correct |
46 ms |
11088 KB |
Output is correct |
6 |
Correct |
36 ms |
10588 KB |
Output is correct |
7 |
Correct |
37 ms |
10596 KB |
Output is correct |
8 |
Correct |
40 ms |
10856 KB |
Output is correct |
9 |
Correct |
20 ms |
10500 KB |
Output is correct |
10 |
Correct |
40 ms |
11060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
3 ms |
6748 KB |
Output is correct |
15 |
Correct |
3 ms |
6748 KB |
Output is correct |
16 |
Correct |
3 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Correct |
119 ms |
20820 KB |
Output is correct |
20 |
Correct |
119 ms |
20816 KB |
Output is correct |
21 |
Correct |
110 ms |
18768 KB |
Output is correct |
22 |
Correct |
108 ms |
18696 KB |
Output is correct |
23 |
Correct |
109 ms |
18676 KB |
Output is correct |
24 |
Correct |
89 ms |
13392 KB |
Output is correct |
25 |
Correct |
84 ms |
13392 KB |
Output is correct |
26 |
Correct |
94 ms |
14928 KB |
Output is correct |
27 |
Correct |
93 ms |
14928 KB |
Output is correct |
28 |
Correct |
102 ms |
15700 KB |
Output is correct |
29 |
Correct |
99 ms |
15972 KB |
Output is correct |
30 |
Correct |
101 ms |
15956 KB |
Output is correct |
31 |
Correct |
102 ms |
15956 KB |
Output is correct |
32 |
Correct |
104 ms |
15956 KB |
Output is correct |
33 |
Correct |
99 ms |
15700 KB |
Output is correct |
34 |
Correct |
80 ms |
15044 KB |
Output is correct |
35 |
Correct |
80 ms |
14932 KB |
Output is correct |
36 |
Correct |
79 ms |
14928 KB |
Output is correct |
37 |
Correct |
92 ms |
14928 KB |
Output is correct |
38 |
Correct |
79 ms |
14932 KB |
Output is correct |
39 |
Correct |
89 ms |
16908 KB |
Output is correct |
40 |
Correct |
71 ms |
13060 KB |
Output is correct |
41 |
Correct |
92 ms |
15492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6488 KB |
Output is correct |
5 |
Correct |
1 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
6748 KB |
Output is correct |
12 |
Correct |
2 ms |
6748 KB |
Output is correct |
13 |
Correct |
2 ms |
6748 KB |
Output is correct |
14 |
Correct |
3 ms |
6748 KB |
Output is correct |
15 |
Correct |
3 ms |
6748 KB |
Output is correct |
16 |
Correct |
3 ms |
6748 KB |
Output is correct |
17 |
Correct |
2 ms |
6748 KB |
Output is correct |
18 |
Correct |
2 ms |
6748 KB |
Output is correct |
19 |
Runtime error |
16 ms |
13916 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |