#include <bits/stdc++.h>
#define here cerr<<"------------------------------------\n"
#define ll long long
#define pll pair<ll,ll>
#define all(a) a.begin(),a.end()
#define fi first
#define sc second
#define pb push_back
#define popb pop_back
#define sz(x) (ll)(x.size())
#define llinf 100000000000000LL
#define endl '\n'
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 1000005
ll n,q;
ll a[maxn];
ll b[maxn];
ll t[4*maxn];
ll ans[maxn];
struct upit{
ll l,r,x,id;
};
bool cmp(upit a,upit b){return a.r<b.r;}
void upd(ll v,ll tl,ll tr,ll i,ll x){
if(tl==tr){
t[v] = max(t[v],x);
return;
}
ll mid = (tl+tr)/2;
if(i<=mid) upd(2*v,tl,mid,i,x);
else upd(2*v+1,mid+1,tr,i,x);
t[v] = max(t[2*v],t[2*v+1]);
}
ll get(ll v,ll tl,ll tr,ll l,ll r){
if(l>r) return 0;
if(tl==l&&tr==r) return t[v];
ll mid = (tl+tr)/2;
return max(get(2*v,tl,mid,l,min(mid,r)),get(2*v+1,mid+1,tr,max(mid+1,l),r));
}
vector<upit> v;
int main(){
ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
cin >> n >> q;
for(ll i = 1;i<=n;i++) cin >> a[i];
stack<ll> st;
for(ll i = 1;i<=n;i++){
while(sz(st)&&a[i]>a[st.top()]) st.pop();
if(sz(st)) b[i] = st.top();
st.push(i);
}
for(ll i = 1;i<=q;i++){
ll l,r,x;
cin >> l >> r >> x;
v.pb({l,r,x,i});
}
sort(all(v),cmp);
ll j = 1;
for(upit p : v){
ll l = p.l;
ll r = p.r;
ll x = p.x;
ll id = p.id;
while(j<=r){
if(b[j]!=0) upd(1,1,n,b[j],a[j] + a[b[j]]);
j++;
}
ans[id] = get(1,1,n,l,r)<=x;
}
for(ll i = 1;i<=q;i++) cout<<ans[i]<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1278 ms |
105616 KB |
Output is correct |
2 |
Correct |
1202 ms |
106484 KB |
Output is correct |
3 |
Correct |
1208 ms |
106500 KB |
Output is correct |
4 |
Correct |
1262 ms |
106552 KB |
Output is correct |
5 |
Incorrect |
1079 ms |
105716 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
94 ms |
10168 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |