#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 1e6 + 5;
const int mod = 1e9 + 7;
int t[4 * maxn], a[maxn];
int d[5005][5005];
void build(int v, int tl, int tr) {
if (tl == tr) {
t[v] = a[tl];
return;
}
int mid = tl + tr >> 1;
build(v + v, tl, mid);
build(v + v + 1, mid + 1, tr);
t[v] = min(t[v + v], t[v + v + 1]);
}
int get(int v, int tl, int tr, int l, int r) {
if (l > tr || r < tl) return (int)1e9 + 5;
if (l <= tl && tr <= r) {
return t[v];
}
int mid = tl + tr >> 1;
return min(get(v + v, tl, mid, l, r), get(v + v + 1, mid + 1, tr, l, r));
}
signed main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
if (n <= 5000 && m <= 5000) {
for (int i = 1; i <= n; i++) {
int x = a[i];
for (int j = i + 1; j <= n; j++) {
d[i][j] = d[i][j - 1];
x = max(x, a[j]);
if (x > a[j]) {
d[i][j] = max(d[i][j], x + a[j]);
}
}
}
while (m--) {
int l, r, k;
cin >> l >> r >> k;
cout << (d[l][r] <= k) << '\n';
}
}
}
Compilation message
sortbooks.cpp: In function 'void build(long long int, long long int, long long int)':
sortbooks.cpp:20:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
20 | int mid = tl + tr >> 1;
| ~~~^~~~
sortbooks.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
sortbooks.cpp:31:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
31 | int mid = tl + tr >> 1;
| ~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
3 ms |
7260 KB |
Output is correct |
7 |
Correct |
2 ms |
7000 KB |
Output is correct |
8 |
Correct |
2 ms |
7000 KB |
Output is correct |
9 |
Correct |
1 ms |
5464 KB |
Output is correct |
10 |
Correct |
2 ms |
7004 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
3 ms |
7260 KB |
Output is correct |
7 |
Correct |
2 ms |
7000 KB |
Output is correct |
8 |
Correct |
2 ms |
7000 KB |
Output is correct |
9 |
Correct |
1 ms |
5464 KB |
Output is correct |
10 |
Correct |
2 ms |
7004 KB |
Output is correct |
11 |
Correct |
10 ms |
20568 KB |
Output is correct |
12 |
Correct |
86 ms |
136832 KB |
Output is correct |
13 |
Correct |
65 ms |
136532 KB |
Output is correct |
14 |
Correct |
73 ms |
142572 KB |
Output is correct |
15 |
Correct |
69 ms |
142436 KB |
Output is correct |
16 |
Correct |
60 ms |
142420 KB |
Output is correct |
17 |
Correct |
45 ms |
107452 KB |
Output is correct |
18 |
Correct |
68 ms |
142508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
75 ms |
10944 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
5 ms |
2396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
3 ms |
7260 KB |
Output is correct |
7 |
Correct |
2 ms |
7000 KB |
Output is correct |
8 |
Correct |
2 ms |
7000 KB |
Output is correct |
9 |
Correct |
1 ms |
5464 KB |
Output is correct |
10 |
Correct |
2 ms |
7004 KB |
Output is correct |
11 |
Correct |
10 ms |
20568 KB |
Output is correct |
12 |
Correct |
86 ms |
136832 KB |
Output is correct |
13 |
Correct |
65 ms |
136532 KB |
Output is correct |
14 |
Correct |
73 ms |
142572 KB |
Output is correct |
15 |
Correct |
69 ms |
142436 KB |
Output is correct |
16 |
Correct |
60 ms |
142420 KB |
Output is correct |
17 |
Correct |
45 ms |
107452 KB |
Output is correct |
18 |
Correct |
68 ms |
142508 KB |
Output is correct |
19 |
Incorrect |
19 ms |
6728 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2392 KB |
Output is correct |
3 |
Correct |
2 ms |
2908 KB |
Output is correct |
4 |
Correct |
1 ms |
2652 KB |
Output is correct |
5 |
Correct |
1 ms |
3420 KB |
Output is correct |
6 |
Correct |
3 ms |
7260 KB |
Output is correct |
7 |
Correct |
2 ms |
7000 KB |
Output is correct |
8 |
Correct |
2 ms |
7000 KB |
Output is correct |
9 |
Correct |
1 ms |
5464 KB |
Output is correct |
10 |
Correct |
2 ms |
7004 KB |
Output is correct |
11 |
Correct |
10 ms |
20568 KB |
Output is correct |
12 |
Correct |
86 ms |
136832 KB |
Output is correct |
13 |
Correct |
65 ms |
136532 KB |
Output is correct |
14 |
Correct |
73 ms |
142572 KB |
Output is correct |
15 |
Correct |
69 ms |
142436 KB |
Output is correct |
16 |
Correct |
60 ms |
142420 KB |
Output is correct |
17 |
Correct |
45 ms |
107452 KB |
Output is correct |
18 |
Correct |
68 ms |
142508 KB |
Output is correct |
19 |
Incorrect |
75 ms |
10944 KB |
Output isn't correct |
20 |
Halted |
0 ms |
0 KB |
- |