#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];
vector<int> cur[4 * maxn];
int st[4 * maxn];
int cb(int id, int id2) {
int mx = cur[id].back();
int pos = lower_bound(all(cur[id2]), mx) - cur[id2].begin();
if(pos != 0) {
pos --;
return mx + cur[id2][pos];
}
return 0;
}
struct SEGMENTREE {
void build(int id = 1, int l = 1, int r = n) {
if(l == r) {
st[id] = 0, cur[id].clear();
cur[id].push_back(a[l]);
return ;
}
int mid = (l + r) >> 1;
build(_left), build(_right);
st[id] = max({ st[id * 2], st[id * 2 + 1], cb(id * 2, id * 2 + 1) });
cur[id].clear(), merge(all(cur[id * 2]), all(cur[id * 2 + 1]), back_inserter(cur[id]));
}
void get(int u, int v, vector<int>& res, int id = 1, int l = 1, int r = n) {
if(v < l || r < u) return ;
if(u <= l && r <= v) return res.push_back(id), void();
int mid = (l + r) >> 1;
get(u, v, res, _left), get(u, v, res, _right);
}
} ST;
void solve()
{
cin >> n >> Q;
for(int i = 1; i <= n; i ++) cin >> a[i];
// n = GetRandom(5, 5), Q= GetRandom(10, 10);
// cout << n << ' ' << Q << '\n';
// for(int i = 1; i <= n; i ++) a[i] = GetRandom(0, 10), cout << a[i] << ' ';
// cout << '\n';
ST.build();
for(int i = 1; i <= Q; i ++) {
int l, r, k, ans = 0; cin >> l >> r >> k;
// int ans = 0, l = GetRandom(1, n), r = GetRandom(1, n), k = GetRandom(0, 20);
// if(l > r) swap(l, r);
// cout << l << ' ' << r << ' ' << k << '\n';
vector<int> res;
ST.get(l, r, res);
if(res.size()) {
int pre = 0;
for(int id : res) {
ans = max(ans, st[id]);
if(pre) ans = max(ans, cb(pre, id));
if(pre == 0 || cur[pre].back() < cur[id].back()) pre = id;
}
}
cout << (ans <= 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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
94292 KB |
Output is correct |
2 |
Correct |
33 ms |
94300 KB |
Output is correct |
3 |
Correct |
35 ms |
94408 KB |
Output is correct |
4 |
Correct |
35 ms |
94292 KB |
Output is correct |
5 |
Correct |
36 ms |
94296 KB |
Output is correct |
6 |
Correct |
35 ms |
94296 KB |
Output is correct |
7 |
Correct |
35 ms |
94300 KB |
Output is correct |
8 |
Correct |
35 ms |
94324 KB |
Output is correct |
9 |
Correct |
35 ms |
94292 KB |
Output is correct |
10 |
Correct |
34 ms |
94304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
94292 KB |
Output is correct |
2 |
Correct |
33 ms |
94300 KB |
Output is correct |
3 |
Correct |
35 ms |
94408 KB |
Output is correct |
4 |
Correct |
35 ms |
94292 KB |
Output is correct |
5 |
Correct |
36 ms |
94296 KB |
Output is correct |
6 |
Correct |
35 ms |
94296 KB |
Output is correct |
7 |
Correct |
35 ms |
94300 KB |
Output is correct |
8 |
Correct |
35 ms |
94324 KB |
Output is correct |
9 |
Correct |
35 ms |
94292 KB |
Output is correct |
10 |
Correct |
34 ms |
94304 KB |
Output is correct |
11 |
Correct |
36 ms |
94484 KB |
Output is correct |
12 |
Correct |
38 ms |
95068 KB |
Output is correct |
13 |
Correct |
39 ms |
95064 KB |
Output is correct |
14 |
Correct |
39 ms |
95072 KB |
Output is correct |
15 |
Correct |
37 ms |
95304 KB |
Output is correct |
16 |
Correct |
38 ms |
95072 KB |
Output is correct |
17 |
Correct |
37 ms |
94816 KB |
Output is correct |
18 |
Correct |
41 ms |
95200 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1999 ms |
262144 KB |
Output is correct |
2 |
Correct |
1964 ms |
262144 KB |
Output is correct |
3 |
Correct |
2028 ms |
262144 KB |
Output is correct |
4 |
Correct |
1974 ms |
262144 KB |
Output is correct |
5 |
Correct |
1691 ms |
262144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
152 ms |
110796 KB |
Output is correct |
2 |
Correct |
139 ms |
110796 KB |
Output is correct |
3 |
Correct |
137 ms |
110920 KB |
Output is correct |
4 |
Correct |
146 ms |
110364 KB |
Output is correct |
5 |
Correct |
135 ms |
110512 KB |
Output is correct |
6 |
Correct |
121 ms |
110284 KB |
Output is correct |
7 |
Correct |
120 ms |
110284 KB |
Output is correct |
8 |
Correct |
120 ms |
110028 KB |
Output is correct |
9 |
Correct |
72 ms |
95828 KB |
Output is correct |
10 |
Correct |
117 ms |
110024 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
94292 KB |
Output is correct |
2 |
Correct |
33 ms |
94300 KB |
Output is correct |
3 |
Correct |
35 ms |
94408 KB |
Output is correct |
4 |
Correct |
35 ms |
94292 KB |
Output is correct |
5 |
Correct |
36 ms |
94296 KB |
Output is correct |
6 |
Correct |
35 ms |
94296 KB |
Output is correct |
7 |
Correct |
35 ms |
94300 KB |
Output is correct |
8 |
Correct |
35 ms |
94324 KB |
Output is correct |
9 |
Correct |
35 ms |
94292 KB |
Output is correct |
10 |
Correct |
34 ms |
94304 KB |
Output is correct |
11 |
Correct |
36 ms |
94484 KB |
Output is correct |
12 |
Correct |
38 ms |
95068 KB |
Output is correct |
13 |
Correct |
39 ms |
95064 KB |
Output is correct |
14 |
Correct |
39 ms |
95072 KB |
Output is correct |
15 |
Correct |
37 ms |
95304 KB |
Output is correct |
16 |
Correct |
38 ms |
95072 KB |
Output is correct |
17 |
Correct |
37 ms |
94816 KB |
Output is correct |
18 |
Correct |
41 ms |
95200 KB |
Output is correct |
19 |
Correct |
318 ms |
128456 KB |
Output is correct |
20 |
Correct |
314 ms |
128416 KB |
Output is correct |
21 |
Correct |
266 ms |
128220 KB |
Output is correct |
22 |
Correct |
274 ms |
128400 KB |
Output is correct |
23 |
Correct |
265 ms |
128456 KB |
Output is correct |
24 |
Correct |
230 ms |
128048 KB |
Output is correct |
25 |
Correct |
235 ms |
128180 KB |
Output is correct |
26 |
Correct |
263 ms |
128452 KB |
Output is correct |
27 |
Correct |
277 ms |
128460 KB |
Output is correct |
28 |
Correct |
292 ms |
128460 KB |
Output is correct |
29 |
Correct |
275 ms |
128456 KB |
Output is correct |
30 |
Correct |
268 ms |
128548 KB |
Output is correct |
31 |
Correct |
274 ms |
128444 KB |
Output is correct |
32 |
Correct |
270 ms |
128452 KB |
Output is correct |
33 |
Correct |
273 ms |
128456 KB |
Output is correct |
34 |
Correct |
218 ms |
128196 KB |
Output is correct |
35 |
Correct |
228 ms |
128200 KB |
Output is correct |
36 |
Correct |
218 ms |
128148 KB |
Output is correct |
37 |
Correct |
220 ms |
128196 KB |
Output is correct |
38 |
Correct |
220 ms |
128208 KB |
Output is correct |
39 |
Correct |
240 ms |
127472 KB |
Output is correct |
40 |
Correct |
162 ms |
114376 KB |
Output is correct |
41 |
Correct |
227 ms |
127432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
94292 KB |
Output is correct |
2 |
Correct |
33 ms |
94300 KB |
Output is correct |
3 |
Correct |
35 ms |
94408 KB |
Output is correct |
4 |
Correct |
35 ms |
94292 KB |
Output is correct |
5 |
Correct |
36 ms |
94296 KB |
Output is correct |
6 |
Correct |
35 ms |
94296 KB |
Output is correct |
7 |
Correct |
35 ms |
94300 KB |
Output is correct |
8 |
Correct |
35 ms |
94324 KB |
Output is correct |
9 |
Correct |
35 ms |
94292 KB |
Output is correct |
10 |
Correct |
34 ms |
94304 KB |
Output is correct |
11 |
Correct |
36 ms |
94484 KB |
Output is correct |
12 |
Correct |
38 ms |
95068 KB |
Output is correct |
13 |
Correct |
39 ms |
95064 KB |
Output is correct |
14 |
Correct |
39 ms |
95072 KB |
Output is correct |
15 |
Correct |
37 ms |
95304 KB |
Output is correct |
16 |
Correct |
38 ms |
95072 KB |
Output is correct |
17 |
Correct |
37 ms |
94816 KB |
Output is correct |
18 |
Correct |
41 ms |
95200 KB |
Output is correct |
19 |
Correct |
1999 ms |
262144 KB |
Output is correct |
20 |
Correct |
1964 ms |
262144 KB |
Output is correct |
21 |
Correct |
2028 ms |
262144 KB |
Output is correct |
22 |
Correct |
1974 ms |
262144 KB |
Output is correct |
23 |
Correct |
1691 ms |
262144 KB |
Output is correct |
24 |
Correct |
152 ms |
110796 KB |
Output is correct |
25 |
Correct |
139 ms |
110796 KB |
Output is correct |
26 |
Correct |
137 ms |
110920 KB |
Output is correct |
27 |
Correct |
146 ms |
110364 KB |
Output is correct |
28 |
Correct |
135 ms |
110512 KB |
Output is correct |
29 |
Correct |
121 ms |
110284 KB |
Output is correct |
30 |
Correct |
120 ms |
110284 KB |
Output is correct |
31 |
Correct |
120 ms |
110028 KB |
Output is correct |
32 |
Correct |
72 ms |
95828 KB |
Output is correct |
33 |
Correct |
117 ms |
110024 KB |
Output is correct |
34 |
Correct |
318 ms |
128456 KB |
Output is correct |
35 |
Correct |
314 ms |
128416 KB |
Output is correct |
36 |
Correct |
266 ms |
128220 KB |
Output is correct |
37 |
Correct |
274 ms |
128400 KB |
Output is correct |
38 |
Correct |
265 ms |
128456 KB |
Output is correct |
39 |
Correct |
230 ms |
128048 KB |
Output is correct |
40 |
Correct |
235 ms |
128180 KB |
Output is correct |
41 |
Correct |
263 ms |
128452 KB |
Output is correct |
42 |
Correct |
277 ms |
128460 KB |
Output is correct |
43 |
Correct |
292 ms |
128460 KB |
Output is correct |
44 |
Correct |
275 ms |
128456 KB |
Output is correct |
45 |
Correct |
268 ms |
128548 KB |
Output is correct |
46 |
Correct |
274 ms |
128444 KB |
Output is correct |
47 |
Correct |
270 ms |
128452 KB |
Output is correct |
48 |
Correct |
273 ms |
128456 KB |
Output is correct |
49 |
Correct |
218 ms |
128196 KB |
Output is correct |
50 |
Correct |
228 ms |
128200 KB |
Output is correct |
51 |
Correct |
218 ms |
128148 KB |
Output is correct |
52 |
Correct |
220 ms |
128196 KB |
Output is correct |
53 |
Correct |
220 ms |
128208 KB |
Output is correct |
54 |
Correct |
240 ms |
127472 KB |
Output is correct |
55 |
Correct |
162 ms |
114376 KB |
Output is correct |
56 |
Correct |
227 ms |
127432 KB |
Output is correct |
57 |
Correct |
1990 ms |
262144 KB |
Output is correct |
58 |
Correct |
1981 ms |
262144 KB |
Output is correct |
59 |
Correct |
2043 ms |
262144 KB |
Output is correct |
60 |
Correct |
1913 ms |
262144 KB |
Output is correct |
61 |
Correct |
1918 ms |
262144 KB |
Output is correct |
62 |
Correct |
1970 ms |
262144 KB |
Output is correct |
63 |
Correct |
1131 ms |
262144 KB |
Output is correct |
64 |
Correct |
1145 ms |
262144 KB |
Output is correct |
65 |
Correct |
1626 ms |
262144 KB |
Output is correct |
66 |
Correct |
1614 ms |
262144 KB |
Output is correct |
67 |
Correct |
1657 ms |
262144 KB |
Output is correct |
68 |
Correct |
1687 ms |
262144 KB |
Output is correct |
69 |
Correct |
1699 ms |
262144 KB |
Output is correct |
70 |
Correct |
1689 ms |
262144 KB |
Output is correct |
71 |
Correct |
1711 ms |
262144 KB |
Output is correct |
72 |
Correct |
1705 ms |
262144 KB |
Output is correct |
73 |
Correct |
1089 ms |
262144 KB |
Output is correct |
74 |
Correct |
1076 ms |
262144 KB |
Output is correct |
75 |
Correct |
1097 ms |
262144 KB |
Output is correct |
76 |
Correct |
1089 ms |
262144 KB |
Output is correct |
77 |
Runtime error |
1114 ms |
262148 KB |
Memory limit exceeded |
78 |
Halted |
0 ms |
0 KB |
- |