//Dost SEFEROĞLU
#include <bits/stdc++.h>
using namespace std;
//#define int long long
#define pii pair<int,int>
#define ff first
#define ss second
#define sp << " " <<
#define all(cont) cont.begin(),cont.end()
#define vi vector<int>
const int MOD = 1e9+7,inf = 2e7;
const int N = 5001;
struct Query {
int l=0,r=0,k=0,id=0;
};
struct FT
{
int n;
vi bit;
FT(int nn) {
n = nn;
bit.assign(n+1,0);
}
void put(int p,int v) {
for(int i=p;i<=n;i+=i&-i) bit[i]=max(bit[i],v);
}
int get(int p) {
int ans = 0;
for (int i=p;i>0;i-=i&-i) ans=max(ans,bit[i]);
return ans;
}
};
void solve() {
int n,q;
cin >> n >> q;
vi a(n+1);
for (int i=1;i<=n;i++) cin >> a[i];
vector<Query> queries(q+1);
for (int i=1;i<=q;i++) {
Query& Q = queries[i];
cin >> Q.l >> Q.r >> Q.k;
Q.id = i;
}
vector<Query> rq[n+1];
for (int i=1;i<=q;i++) {
rq[queries[i].r].push_back(queries[i]);
}
vi ans(q+1);
a[0] = inf;
FT ft(n);
vi st{0};
for (int i=1;i<=n;i++) {
while (a[st.back()] <= a[i]) st.pop_back();
if (st.back()) ft.put(n-st.back()+1,a[i]+a[st.back()]);
for (auto Q : rq[i]){
ans[Q.id] = ft.get(n-Q.l+1);
}
st.push_back(i);
}
for (int i=1;i<=q;i++) cout << (ans[i]<=queries[i].k) << '\n';
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#ifdef Dodi
freopen("in.txt","r",stdin);
freopen("out.txt","w",stdout);
#endif
int t = 1;
//cin >> t;
while (t --> 0) solve();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
432 ms |
156720 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
8272 KB |
Output is correct |
2 |
Correct |
38 ms |
10064 KB |
Output is correct |
3 |
Correct |
38 ms |
10172 KB |
Output is correct |
4 |
Correct |
33 ms |
10076 KB |
Output is correct |
5 |
Correct |
37 ms |
10072 KB |
Output is correct |
6 |
Correct |
29 ms |
9572 KB |
Output is correct |
7 |
Correct |
30 ms |
9828 KB |
Output is correct |
8 |
Correct |
35 ms |
9588 KB |
Output is correct |
9 |
Correct |
22 ms |
5828 KB |
Output is correct |
10 |
Correct |
35 ms |
9672 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
600 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |