#include <bits/stdc++.h>
#define Y8o "Hedgehog Daniyar and Algorithms"
#define maxn (int) 1e6 + 5
#define ll long long
#define pii pair<ll, ll>
#define gb(i, j) ((i >> j) & 1)
#define all(x) x.begin(), x.end()
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
//#define f first
//#define s second
using namespace std;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r) {
return uniform_int_distribution<ll> (l, r) (rng);
}
void iof() {
if(fopen(Y8o".inp", "r"))
{
freopen(Y8o".inp", "r", stdin);
// freopen(Y8o".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(NULL), cout.tie(NULL);
}
void ctime() {
cerr << "\n" << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
}
int n, Q, a[maxn];
struct Node { int val, ma, mi; };
Node operator + (const Node& x, const Node& y) {
Node res = {0, 0, 0};
res.ma = max(x.ma, y.ma);
res.mi = min(x.mi, y.mi);
res.val = max({ 0, x.val, y.val, x.ma - y.mi });
return res;
}
struct SEGMENTREE {
Node st[4 * maxn];
void build(int id = 1, int l = 1, int r = n) {
if(l == r) return st[id] = {0, a[l], a[l]}, void();
int mid = (l + r) >> 1;
build(_left), build(_right);
st[id] = st[id * 2] + st[id * 2 + 1];
}
Node get(int u, int v, int id = 1, int l = 1, int r = n) {
if(v < l || r < u) return { 0, 0, 0 };
if(u <= l && r <= v) return st[id];
int mid = (l + r) >> 1;
return get(u, v, _left) + get(u, v, _right);
}
} ST;
void solve()
{
cin >> n >> Q;
for(int i = 1; i <= n; i ++) cin >> a[i];
assert(n <= 500);
ST.build();
for(int i = 1; i <= Q; i ++) {
int l, r, k, ans = 0; cin >> l >> r >> k;
for(int it1 = l; it1 <= r; it1 ++) {
for(int it2 = l; it2 < it1; it2 ++) {
if(a[it1] < a[it2]) ans = max(ans, a[it2] + a[it1]);
}
}
cout << (ans <= k) << '\n';
// Node lim = ST.get(l, r);
// cout << (lim.val <= k) << '\n';
}
}
int main()
{
iof();
int nTest = 1;
// cin >> nTest;
while(nTest --) {
solve();
}
ctime();
return 0;
}
Compilation message
sortbooks.cpp: In function 'void iof()':
sortbooks.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
23 | freopen(Y8o".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
428 KB |
Output is correct |
6 |
Correct |
11 ms |
504 KB |
Output is correct |
7 |
Correct |
11 ms |
360 KB |
Output is correct |
8 |
Correct |
21 ms |
352 KB |
Output is correct |
9 |
Correct |
6 ms |
360 KB |
Output is correct |
10 |
Correct |
19 ms |
500 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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
428 KB |
Output is correct |
6 |
Correct |
11 ms |
504 KB |
Output is correct |
7 |
Correct |
11 ms |
360 KB |
Output is correct |
8 |
Correct |
21 ms |
352 KB |
Output is correct |
9 |
Correct |
6 ms |
360 KB |
Output is correct |
10 |
Correct |
19 ms |
500 KB |
Output is correct |
11 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
61 ms |
16100 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
6 ms |
1888 KB |
Execution killed with signal 6 |
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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
428 KB |
Output is correct |
6 |
Correct |
11 ms |
504 KB |
Output is correct |
7 |
Correct |
11 ms |
360 KB |
Output is correct |
8 |
Correct |
21 ms |
352 KB |
Output is correct |
9 |
Correct |
6 ms |
360 KB |
Output is correct |
10 |
Correct |
19 ms |
500 KB |
Output is correct |
11 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
12 |
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 |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
428 KB |
Output is correct |
6 |
Correct |
11 ms |
504 KB |
Output is correct |
7 |
Correct |
11 ms |
360 KB |
Output is correct |
8 |
Correct |
21 ms |
352 KB |
Output is correct |
9 |
Correct |
6 ms |
360 KB |
Output is correct |
10 |
Correct |
19 ms |
500 KB |
Output is correct |
11 |
Runtime error |
1 ms |
604 KB |
Execution killed with signal 6 |
12 |
Halted |
0 ms |
0 KB |
- |