#include "bits/stdc++.h"
using namespace std;
const int MAXN = 1e6 + 10;
const int MOD = 1e9 + 7;
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
struct node {
int val;
int ans; // maximum sum inversion in range
int l, r;
vector<int> v; // SORTED!!! crazy memory moment
} st[4*MAXN];
int w[MAXN];
int n, m;
vector<pair<int, int> > v[MAXN];
void bu(int l, int r, int idx) {
st[idx].l = l;
st[idx].r = r;
v[l].push_back({r, idx});
st[idx].v.resize(r-l+1);
if(l == r) {
cin >> w[l];
st[idx].val = w[l];
st[idx].v[0] = w[l];
st[idx].ans = -1;
return;
}
int mid = (l + r) >> 1;
bu(l, mid, 2*idx + 1);
bu(mid+1, r, 2*idx + 2);
int lptr = 0, rptr = 0;
int nxt = 0;
while(!(lptr == st[2*idx + 1].v.size() && rptr == st[2*idx + 2].v.size())) {
if(lptr == st[2*idx+1].v.size()) {
st[idx].v[nxt] = st[2*idx+2].v[rptr];
rptr++;
nxt++;
}
else if(rptr == st[2*idx+2].v.size()) {
st[idx].v[nxt] = st[2*idx+1].v[lptr];
lptr++;
nxt++;
}
else {
if(st[2*idx+1].v[lptr] < st[2*idx+2].v[rptr]) {
st[idx].v[nxt] = st[2*idx+1].v[lptr];
lptr++;
nxt++;
}
else {
st[idx].v[nxt] = st[2*idx+2].v[rptr];
rptr++;
nxt++;
}
}
}
st[idx].ans = max(st[2*idx+1].ans, st[2*idx+2].ans);
int ma = st[2*idx+1].v[st[2*idx+1].v.size() - 1];
int lb = 0, rb = st[2*idx+2].v.size() - 1;
while(lb < rb) {
int mid = (lb + rb + 1) >> 1;
if(st[2*idx+2].v[mid] < ma) lb = mid;
else rb = mid - 1;
}
if(st[2*idx+2].v[lb] < ma) {
st[idx].ans = max(st[idx].ans, st[2*idx+2].v[lb] + ma);
}
}
void build() {
bu(1, n, 0);
}
void solve(int tc) {
cin >> n >> m;
build();
for(int i=1; i<=n; i++) {
sort(v[i].begin(), v[i].end());
}
for(int i=0; i<m; i++) {
int l, r, k;
cin >> l >> r >> k;
int ma = -2e9;
int ans = -2e9;
while(l <= r) {
int lb = 0, rb = v[l].size() - 1;
while(lb < rb) {
int mid = (lb + rb + 1) >> 1;
if(v[l][mid].first <= r) lb = mid;
else rb = mid - 1;
}
int idx = v[l][lb].second;
ans = max(ans, st[idx].ans);
int lb2 = 0, rb2 = st[idx].v.size() - 1;
while(lb2 < rb2) {
int mid = (lb2 + rb2 + 1) >> 1;
if(st[idx].v[mid] < ma) lb2 = mid;
else rb2 = mid - 1;
}
if(st[idx].v[lb2] < ma) ans = max(ans, ma + st[idx].v[lb2]);
ma = max(ma, st[idx].v[st[idx].v.size() - 1]);
l = v[l][lb].first + 1;
}
cout << (ans > k ? "0\n" : "1\n");
}
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
Compilation message
sortbooks.cpp: In function 'void bu(int, int, int)':
sortbooks.cpp:38:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | while(!(lptr == st[2*idx + 1].v.size() && rptr == st[2*idx + 2].v.size())) {
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:38:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | while(!(lptr == st[2*idx + 1].v.size() && rptr == st[2*idx + 2].v.size())) {
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:39:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | if(lptr == st[2*idx+1].v.size()) {
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:44:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
44 | else if(rptr == st[2*idx+2].v.size()) {
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
180336 KB |
Output is correct |
2 |
Correct |
88 ms |
180320 KB |
Output is correct |
3 |
Correct |
89 ms |
180364 KB |
Output is correct |
4 |
Correct |
97 ms |
180280 KB |
Output is correct |
5 |
Correct |
91 ms |
180376 KB |
Output is correct |
6 |
Correct |
84 ms |
180400 KB |
Output is correct |
7 |
Correct |
101 ms |
180416 KB |
Output is correct |
8 |
Correct |
100 ms |
180340 KB |
Output is correct |
9 |
Correct |
93 ms |
180336 KB |
Output is correct |
10 |
Correct |
82 ms |
180416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
180336 KB |
Output is correct |
2 |
Correct |
88 ms |
180320 KB |
Output is correct |
3 |
Correct |
89 ms |
180364 KB |
Output is correct |
4 |
Correct |
97 ms |
180280 KB |
Output is correct |
5 |
Correct |
91 ms |
180376 KB |
Output is correct |
6 |
Correct |
84 ms |
180400 KB |
Output is correct |
7 |
Correct |
101 ms |
180416 KB |
Output is correct |
8 |
Correct |
100 ms |
180340 KB |
Output is correct |
9 |
Correct |
93 ms |
180336 KB |
Output is correct |
10 |
Correct |
82 ms |
180416 KB |
Output is correct |
11 |
Correct |
92 ms |
180552 KB |
Output is correct |
12 |
Correct |
91 ms |
180980 KB |
Output is correct |
13 |
Correct |
89 ms |
180952 KB |
Output is correct |
14 |
Correct |
88 ms |
180944 KB |
Output is correct |
15 |
Correct |
105 ms |
181064 KB |
Output is correct |
16 |
Correct |
89 ms |
181068 KB |
Output is correct |
17 |
Correct |
89 ms |
180872 KB |
Output is correct |
18 |
Correct |
89 ms |
181148 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
281 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
366 ms |
196360 KB |
Output is correct |
2 |
Correct |
324 ms |
198472 KB |
Output is correct |
3 |
Correct |
348 ms |
198360 KB |
Output is correct |
4 |
Correct |
376 ms |
198412 KB |
Output is correct |
5 |
Correct |
349 ms |
198348 KB |
Output is correct |
6 |
Correct |
280 ms |
198184 KB |
Output is correct |
7 |
Correct |
267 ms |
198224 KB |
Output is correct |
8 |
Correct |
291 ms |
198040 KB |
Output is correct |
9 |
Correct |
130 ms |
181944 KB |
Output is correct |
10 |
Correct |
296 ms |
198008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
180336 KB |
Output is correct |
2 |
Correct |
88 ms |
180320 KB |
Output is correct |
3 |
Correct |
89 ms |
180364 KB |
Output is correct |
4 |
Correct |
97 ms |
180280 KB |
Output is correct |
5 |
Correct |
91 ms |
180376 KB |
Output is correct |
6 |
Correct |
84 ms |
180400 KB |
Output is correct |
7 |
Correct |
101 ms |
180416 KB |
Output is correct |
8 |
Correct |
100 ms |
180340 KB |
Output is correct |
9 |
Correct |
93 ms |
180336 KB |
Output is correct |
10 |
Correct |
82 ms |
180416 KB |
Output is correct |
11 |
Correct |
92 ms |
180552 KB |
Output is correct |
12 |
Correct |
91 ms |
180980 KB |
Output is correct |
13 |
Correct |
89 ms |
180952 KB |
Output is correct |
14 |
Correct |
88 ms |
180944 KB |
Output is correct |
15 |
Correct |
105 ms |
181064 KB |
Output is correct |
16 |
Correct |
89 ms |
181068 KB |
Output is correct |
17 |
Correct |
89 ms |
180872 KB |
Output is correct |
18 |
Correct |
89 ms |
181148 KB |
Output is correct |
19 |
Correct |
765 ms |
217524 KB |
Output is correct |
20 |
Correct |
751 ms |
219752 KB |
Output is correct |
21 |
Correct |
593 ms |
219536 KB |
Output is correct |
22 |
Correct |
568 ms |
219612 KB |
Output is correct |
23 |
Correct |
623 ms |
219604 KB |
Output is correct |
24 |
Correct |
563 ms |
219448 KB |
Output is correct |
25 |
Correct |
504 ms |
219448 KB |
Output is correct |
26 |
Correct |
762 ms |
219688 KB |
Output is correct |
27 |
Correct |
797 ms |
219680 KB |
Output is correct |
28 |
Correct |
753 ms |
219696 KB |
Output is correct |
29 |
Correct |
749 ms |
219724 KB |
Output is correct |
30 |
Correct |
739 ms |
219688 KB |
Output is correct |
31 |
Correct |
833 ms |
219824 KB |
Output is correct |
32 |
Correct |
770 ms |
219720 KB |
Output is correct |
33 |
Correct |
771 ms |
219952 KB |
Output is correct |
34 |
Correct |
545 ms |
219284 KB |
Output is correct |
35 |
Correct |
521 ms |
219280 KB |
Output is correct |
36 |
Correct |
510 ms |
219304 KB |
Output is correct |
37 |
Correct |
507 ms |
219080 KB |
Output is correct |
38 |
Correct |
531 ms |
219308 KB |
Output is correct |
39 |
Correct |
653 ms |
218280 KB |
Output is correct |
40 |
Correct |
421 ms |
206088 KB |
Output is correct |
41 |
Correct |
594 ms |
217908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
180336 KB |
Output is correct |
2 |
Correct |
88 ms |
180320 KB |
Output is correct |
3 |
Correct |
89 ms |
180364 KB |
Output is correct |
4 |
Correct |
97 ms |
180280 KB |
Output is correct |
5 |
Correct |
91 ms |
180376 KB |
Output is correct |
6 |
Correct |
84 ms |
180400 KB |
Output is correct |
7 |
Correct |
101 ms |
180416 KB |
Output is correct |
8 |
Correct |
100 ms |
180340 KB |
Output is correct |
9 |
Correct |
93 ms |
180336 KB |
Output is correct |
10 |
Correct |
82 ms |
180416 KB |
Output is correct |
11 |
Correct |
92 ms |
180552 KB |
Output is correct |
12 |
Correct |
91 ms |
180980 KB |
Output is correct |
13 |
Correct |
89 ms |
180952 KB |
Output is correct |
14 |
Correct |
88 ms |
180944 KB |
Output is correct |
15 |
Correct |
105 ms |
181064 KB |
Output is correct |
16 |
Correct |
89 ms |
181068 KB |
Output is correct |
17 |
Correct |
89 ms |
180872 KB |
Output is correct |
18 |
Correct |
89 ms |
181148 KB |
Output is correct |
19 |
Runtime error |
281 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |