#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ff first
#define ss second
#define ll long long
using namespace std;
const int N=1e6+7, M=1e9+7;
ll a[N], dp[N];
void solve()
{
ll n, m, mn=1e18;
cin >> n >> m;
for (int i=1;i<=n;i++) cin >> a[i], mn=min(mn, a[i]), dp[i]=1;
for (int i=2;i<=n;i++) {
if (a[i] >= a[i-1]) dp[i]+=dp[i-1];
else dp[i]=dp[i-1];
}
while (m--){
ll l, r, k;
cin >> l >> r >> k;
if (mn > k){
if (dp[r]-dp[l-1] == n) cout <<"1\n";
else cout << "0\n";
continue;
}
vector <ll> v;
bool ok=1;
for (int i=l;i<=r;i++) v.push_back(a[i]);
for (int i=0;i<v.size();i++){
for (int j=i;j<v.size();j++){
if (v[i] > v[j] && v[i]+v[j] > k){
ok=0;
break;
}
}
}
cout << ok <<"\n";
}
return ;
}
int main()
{
ios;
int t=1;
// cin >> t;
while (t--){
solve();
cout <<"\n";
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'void solve()':
sortbooks.cpp:33:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | for (int i=0;i<v.size();i++){
| ~^~~~~~~~~
sortbooks.cpp:34:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int j=i;j<v.size();j++){
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
14 ms |
348 KB |
Output is correct |
7 |
Correct |
17 ms |
372 KB |
Output is correct |
8 |
Correct |
26 ms |
340 KB |
Output is correct |
9 |
Correct |
11 ms |
332 KB |
Output is correct |
10 |
Correct |
26 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
14 ms |
348 KB |
Output is correct |
7 |
Correct |
17 ms |
372 KB |
Output is correct |
8 |
Correct |
26 ms |
340 KB |
Output is correct |
9 |
Correct |
11 ms |
332 KB |
Output is correct |
10 |
Correct |
26 ms |
340 KB |
Output is correct |
11 |
Correct |
716 ms |
572 KB |
Output is correct |
12 |
Execution timed out |
3060 ms |
592 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
512 ms |
49784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
3062 ms |
3100 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
14 ms |
348 KB |
Output is correct |
7 |
Correct |
17 ms |
372 KB |
Output is correct |
8 |
Correct |
26 ms |
340 KB |
Output is correct |
9 |
Correct |
11 ms |
332 KB |
Output is correct |
10 |
Correct |
26 ms |
340 KB |
Output is correct |
11 |
Correct |
716 ms |
572 KB |
Output is correct |
12 |
Execution timed out |
3060 ms |
592 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
3 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
14 ms |
348 KB |
Output is correct |
7 |
Correct |
17 ms |
372 KB |
Output is correct |
8 |
Correct |
26 ms |
340 KB |
Output is correct |
9 |
Correct |
11 ms |
332 KB |
Output is correct |
10 |
Correct |
26 ms |
340 KB |
Output is correct |
11 |
Correct |
716 ms |
572 KB |
Output is correct |
12 |
Execution timed out |
3060 ms |
592 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |