#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define s second
#define f first
#define pll pair <ll,ll>
#define pii pair <int,int>
#define left h*2,l,(l + r)/2
#define right h*2+1,(l + r)/2 + 1,r
using namespace std;
const int N = 1e6 + 5,inf = 1e9;
int a[N],le[N],ri[N],ans[N],k[N];
int t[4*N];
vector <int> v[N];
void upd(int h,int l,int r,int idx,int val){
if (l == r){
t[h] = max(t[h],val);
return;
}
int mid = (l + r)/2;
if (idx > mid) upd(right,idx,val);
else upd(left,idx,val);
t[h] = max(t[h*2],t[h*2 + 1]);
}
int get(int h,int l,int r,int L,int R){
if (r < L || R < l) return 0;
if (L <= l && r <= R) return t[h];
return max(get(left,L,R),get(right,L,R));
}
int main() {
ios_base::sync_with_stdio(0),cin.tie(NULL),cout.tie(NULL);
int n,Q;
cin>>n>>Q;
for (int i = 1; i <= n; i++){
cin>>a[i];
}
for (int i = 1; i <= Q; i++){
cin>>le[i]>>ri[i]>>k[i];
v[ri[i]].pb(i);
}
deque <int> dq;
for (int i = 1; i <= n; i++){
while (dq.size() && a[dq.back()] < a[i]){
dq.pop_back();
}
if (dq.size()){
upd(1,1,n,dq.back(),a[i] + a[dq.back()]);
}
dq.pb(i);
for (int id: v[i]){
if (get(1,1,n,le[id],i) <= k[id]) ans[id] = 1;
}
}
for (int i = 1; i <= Q; i++)
cout<<ans[i]<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23812 KB |
Output is correct |
2 |
Correct |
11 ms |
23812 KB |
Output is correct |
3 |
Correct |
11 ms |
23824 KB |
Output is correct |
4 |
Correct |
12 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23812 KB |
Output is correct |
6 |
Correct |
12 ms |
23808 KB |
Output is correct |
7 |
Correct |
12 ms |
23828 KB |
Output is correct |
8 |
Correct |
12 ms |
23892 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Incorrect |
13 ms |
23812 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23812 KB |
Output is correct |
2 |
Correct |
11 ms |
23812 KB |
Output is correct |
3 |
Correct |
11 ms |
23824 KB |
Output is correct |
4 |
Correct |
12 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23812 KB |
Output is correct |
6 |
Correct |
12 ms |
23808 KB |
Output is correct |
7 |
Correct |
12 ms |
23828 KB |
Output is correct |
8 |
Correct |
12 ms |
23892 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Incorrect |
13 ms |
23812 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2117 ms |
99548 KB |
Output is correct |
2 |
Correct |
2161 ms |
100456 KB |
Output is correct |
3 |
Correct |
2169 ms |
100320 KB |
Output is correct |
4 |
Correct |
2225 ms |
100488 KB |
Output is correct |
5 |
Incorrect |
2119 ms |
101652 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
185 ms |
30608 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23812 KB |
Output is correct |
2 |
Correct |
11 ms |
23812 KB |
Output is correct |
3 |
Correct |
11 ms |
23824 KB |
Output is correct |
4 |
Correct |
12 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23812 KB |
Output is correct |
6 |
Correct |
12 ms |
23808 KB |
Output is correct |
7 |
Correct |
12 ms |
23828 KB |
Output is correct |
8 |
Correct |
12 ms |
23892 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Incorrect |
13 ms |
23812 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23812 KB |
Output is correct |
2 |
Correct |
11 ms |
23812 KB |
Output is correct |
3 |
Correct |
11 ms |
23824 KB |
Output is correct |
4 |
Correct |
12 ms |
23900 KB |
Output is correct |
5 |
Correct |
11 ms |
23812 KB |
Output is correct |
6 |
Correct |
12 ms |
23808 KB |
Output is correct |
7 |
Correct |
12 ms |
23828 KB |
Output is correct |
8 |
Correct |
12 ms |
23892 KB |
Output is correct |
9 |
Correct |
14 ms |
23764 KB |
Output is correct |
10 |
Incorrect |
13 ms |
23812 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |