#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define int long long
template <class F, class _S>
bool chmin(F &u, const _S &v){
bool flag = false;
if ( u > v ){
u = v; flag |= true;
}
return flag;
}
template <class F, class _S>
bool chmax(F &u, const _S &v){
bool flag = false;
if ( u < v ){
u = v; flag |= true;
}
return flag;
}
const int N = 1e5+50, inf = 1e18+200;
//int mod = 998244353;
//int mod = 1000000007;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//#define rnd(l, r) uniform_int_distribution <int> (l, r)(rng)
void solve(){
auto calc = [&](vector<int> a) -> int{
int sz = a.size(), ans = 0;
for(int i = 0; i < sz; i++){
for(int j = i-1; j >= 0; j--){
if(a[i] < a[j])swap(a[i], a[j]), chmax(ans, a[i] + a[j]);
else break;
}
}
return ans;
};
int n, q;
cin >> n >> q;
vector<int> a(n+1);
for(int i = 1; i <= n; i++)cin >> a[i];
while(q--){
int l, r, k;
cin >> l >> r >> k;
vector<int> res;
for(int i = l; i <= r; i++)res.pb(a[i]);
int ans = calc(res);
//cout << ans << '\n';
cout << (ans <= k) << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int tt = 1;
//cin >> tt;
while(tt--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
8 ms |
604 KB |
Output is correct |
12 |
Correct |
27 ms |
604 KB |
Output is correct |
13 |
Correct |
33 ms |
604 KB |
Output is correct |
14 |
Correct |
55 ms |
600 KB |
Output is correct |
15 |
Correct |
54 ms |
600 KB |
Output is correct |
16 |
Correct |
100 ms |
712 KB |
Output is correct |
17 |
Correct |
86 ms |
600 KB |
Output is correct |
18 |
Correct |
110 ms |
708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3041 ms |
33808 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3059 ms |
3836 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
8 ms |
604 KB |
Output is correct |
12 |
Correct |
27 ms |
604 KB |
Output is correct |
13 |
Correct |
33 ms |
604 KB |
Output is correct |
14 |
Correct |
55 ms |
600 KB |
Output is correct |
15 |
Correct |
54 ms |
600 KB |
Output is correct |
16 |
Correct |
100 ms |
712 KB |
Output is correct |
17 |
Correct |
86 ms |
600 KB |
Output is correct |
18 |
Correct |
110 ms |
708 KB |
Output is correct |
19 |
Execution timed out |
3039 ms |
7856 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
492 KB |
Output is correct |
11 |
Correct |
8 ms |
604 KB |
Output is correct |
12 |
Correct |
27 ms |
604 KB |
Output is correct |
13 |
Correct |
33 ms |
604 KB |
Output is correct |
14 |
Correct |
55 ms |
600 KB |
Output is correct |
15 |
Correct |
54 ms |
600 KB |
Output is correct |
16 |
Correct |
100 ms |
712 KB |
Output is correct |
17 |
Correct |
86 ms |
600 KB |
Output is correct |
18 |
Correct |
110 ms |
708 KB |
Output is correct |
19 |
Execution timed out |
3041 ms |
33808 KB |
Time limit exceeded |
20 |
Halted |
0 ms |
0 KB |
- |