#include <bits/stdc++.h>
#define INF 1000000021
#define MOD 1000000007
#define pb push_back
#define sqr(a) (a)*(a)
#define M(a, b) make_pair(a,b)
#define int long long
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define deb(x) cerr << #x << " = " << x << '\n'
#define N 222222
using namespace std;
//using namespace __gnu_pbds;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> vi;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const ld pi = 2 * acos(0.0);
//int month[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
int gcd(int a, int b) {
return b ? gcd (b, a % b) : a;
}
int binpow (int a, int n) {
if (n == 0)
return 1LL;
if (n % 2 == 1)
return ((binpow (a, n-1)%MOD) * 1LL * a)%MOD;
else {
int b = binpow (a, n/2)%MOD;
return (b * b)%MOD;
}
}
//void swap(int &a, int &b){
// b = (a+b) - (a=b);
//}
void solve(){
int n, m;
cin >> n >> m;
vi a(N);
for(int i = 0; i < n; i++){
cin >> a[i];
}
while(m--){
int l, r, k;
cin >> l >> r >> k;
int check = 0, temp = 0;
for (size_t i = l - 1; i < r; i++)
{
if(check > k) break;
if(temp > a[i]) check = max(check, temp + a[i]);
temp = max(temp, a[i]);
}
cout << (check <= k) << "\n";
}
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
// cin >> t;
while(t--){
solve();
cout << "\n";
/*
READ IT WHEN YOUR CODE RETURNS WRONG ANSWER, IT CAN HELP YOU
REMEMBER:
1. Array's length can be smaller than you need in your problem
2. Type INT can be smaller than you need in problem so use Long Long
3. Size of string array is smaller than char matrix
*/
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'void solve()':
sortbooks.cpp:59:34: warning: comparison of integer expressions of different signedness: 'size_t' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
59 | for (size_t i = l - 1; i < r; i++)
| ~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1996 KB |
Output is correct |
2 |
Correct |
1 ms |
1976 KB |
Output is correct |
3 |
Correct |
1 ms |
1996 KB |
Output is correct |
4 |
Correct |
1 ms |
1996 KB |
Output is correct |
5 |
Correct |
1 ms |
1996 KB |
Output is correct |
6 |
Correct |
1 ms |
1996 KB |
Output is correct |
7 |
Correct |
1 ms |
1984 KB |
Output is correct |
8 |
Correct |
2 ms |
1996 KB |
Output is correct |
9 |
Correct |
2 ms |
1996 KB |
Output is correct |
10 |
Correct |
1 ms |
1996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1996 KB |
Output is correct |
2 |
Correct |
1 ms |
1976 KB |
Output is correct |
3 |
Correct |
1 ms |
1996 KB |
Output is correct |
4 |
Correct |
1 ms |
1996 KB |
Output is correct |
5 |
Correct |
1 ms |
1996 KB |
Output is correct |
6 |
Correct |
1 ms |
1996 KB |
Output is correct |
7 |
Correct |
1 ms |
1984 KB |
Output is correct |
8 |
Correct |
2 ms |
1996 KB |
Output is correct |
9 |
Correct |
2 ms |
1996 KB |
Output is correct |
10 |
Correct |
1 ms |
1996 KB |
Output is correct |
11 |
Correct |
2 ms |
2124 KB |
Output is correct |
12 |
Correct |
3 ms |
2156 KB |
Output is correct |
13 |
Correct |
3 ms |
2116 KB |
Output is correct |
14 |
Correct |
3 ms |
2124 KB |
Output is correct |
15 |
Correct |
4 ms |
2204 KB |
Output is correct |
16 |
Correct |
13 ms |
2172 KB |
Output is correct |
17 |
Correct |
14 ms |
2172 KB |
Output is correct |
18 |
Correct |
13 ms |
2148 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
29 ms |
4116 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
573 ms |
3136 KB |
Output is correct |
2 |
Correct |
1830 ms |
3608 KB |
Output is correct |
3 |
Execution timed out |
3058 ms |
3268 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1996 KB |
Output is correct |
2 |
Correct |
1 ms |
1976 KB |
Output is correct |
3 |
Correct |
1 ms |
1996 KB |
Output is correct |
4 |
Correct |
1 ms |
1996 KB |
Output is correct |
5 |
Correct |
1 ms |
1996 KB |
Output is correct |
6 |
Correct |
1 ms |
1996 KB |
Output is correct |
7 |
Correct |
1 ms |
1984 KB |
Output is correct |
8 |
Correct |
2 ms |
1996 KB |
Output is correct |
9 |
Correct |
2 ms |
1996 KB |
Output is correct |
10 |
Correct |
1 ms |
1996 KB |
Output is correct |
11 |
Correct |
2 ms |
2124 KB |
Output is correct |
12 |
Correct |
3 ms |
2156 KB |
Output is correct |
13 |
Correct |
3 ms |
2116 KB |
Output is correct |
14 |
Correct |
3 ms |
2124 KB |
Output is correct |
15 |
Correct |
4 ms |
2204 KB |
Output is correct |
16 |
Correct |
13 ms |
2172 KB |
Output is correct |
17 |
Correct |
14 ms |
2172 KB |
Output is correct |
18 |
Correct |
13 ms |
2148 KB |
Output is correct |
19 |
Correct |
2329 ms |
5172 KB |
Output is correct |
20 |
Correct |
2376 ms |
5136 KB |
Output is correct |
21 |
Execution timed out |
3034 ms |
3988 KB |
Time limit exceeded |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1996 KB |
Output is correct |
2 |
Correct |
1 ms |
1976 KB |
Output is correct |
3 |
Correct |
1 ms |
1996 KB |
Output is correct |
4 |
Correct |
1 ms |
1996 KB |
Output is correct |
5 |
Correct |
1 ms |
1996 KB |
Output is correct |
6 |
Correct |
1 ms |
1996 KB |
Output is correct |
7 |
Correct |
1 ms |
1984 KB |
Output is correct |
8 |
Correct |
2 ms |
1996 KB |
Output is correct |
9 |
Correct |
2 ms |
1996 KB |
Output is correct |
10 |
Correct |
1 ms |
1996 KB |
Output is correct |
11 |
Correct |
2 ms |
2124 KB |
Output is correct |
12 |
Correct |
3 ms |
2156 KB |
Output is correct |
13 |
Correct |
3 ms |
2116 KB |
Output is correct |
14 |
Correct |
3 ms |
2124 KB |
Output is correct |
15 |
Correct |
4 ms |
2204 KB |
Output is correct |
16 |
Correct |
13 ms |
2172 KB |
Output is correct |
17 |
Correct |
14 ms |
2172 KB |
Output is correct |
18 |
Correct |
13 ms |
2148 KB |
Output is correct |
19 |
Runtime error |
29 ms |
4116 KB |
Execution killed with signal 11 |
20 |
Halted |
0 ms |
0 KB |
- |