#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 ans; // maximum sum inversion in range
vector<int> v; // SORTED!!! crazy memory moment
} st[4*MAXN];
int n, m;
vector<int> v[MAXN];
void bu(int l, int r, int idx) {
v[l].push_back(idx);
st[idx].v.resize(r-l+1);
if(l == r) {
int w;
cin >> w;
st[idx].v[0] = w;
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);
}
int calc(int idx1) {
return st[idx1].v.size() - 1;
}
bool cmp(int a, int b) {
return calc(a) < calc(b);
}
void solve(int tc) {
cin >> n >> m;
if(n > 200000) {
int s[n+1];
for(int i=1; i<=n; i++) cin >> s[i];
int ps[n+1];
ps[0] = 0;
for(int i=1; i<=n; i++) ps[i] = ps[i-1] + (s[i] > s[i+1]);
for(int i=0; i<m; i++) {
int l, r, k;
cin >> l >> r >> k;
cout << (ps[r-1] - ps[l-1] > 0 ? "0\n" : "1\n");
}
return;
}
build();
for(int i=1; i<=n; i++) sort(v[i].begin(), v[i].end(), cmp);
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;
int idx1 = v[l][mid];
int range = l + st[idx1].v.size() - 1;
if(range <= r) lb = mid;
else rb = mid - 1;
}
int idx = v[l][lb];
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]);
int idx1 = v[l][lb];
int range = l + st[idx1].v.size() - 1;
l = range + 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:32:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | while(!(lptr == st[2*idx + 1].v.size() && rptr == st[2*idx + 2].v.size())) {
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:32:50: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
32 | while(!(lptr == st[2*idx + 1].v.size() && rptr == st[2*idx + 2].v.size())) {
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:33:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
33 | if(lptr == st[2*idx+1].v.size()) {
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:38:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | else if(rptr == st[2*idx+2].v.size()) {
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
149068 KB |
Output is correct |
2 |
Correct |
69 ms |
148948 KB |
Output is correct |
3 |
Correct |
68 ms |
148924 KB |
Output is correct |
4 |
Correct |
67 ms |
148964 KB |
Output is correct |
5 |
Correct |
69 ms |
149040 KB |
Output is correct |
6 |
Correct |
68 ms |
149080 KB |
Output is correct |
7 |
Correct |
69 ms |
149084 KB |
Output is correct |
8 |
Correct |
70 ms |
148996 KB |
Output is correct |
9 |
Correct |
69 ms |
148940 KB |
Output is correct |
10 |
Correct |
71 ms |
149012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
149068 KB |
Output is correct |
2 |
Correct |
69 ms |
148948 KB |
Output is correct |
3 |
Correct |
68 ms |
148924 KB |
Output is correct |
4 |
Correct |
67 ms |
148964 KB |
Output is correct |
5 |
Correct |
69 ms |
149040 KB |
Output is correct |
6 |
Correct |
68 ms |
149080 KB |
Output is correct |
7 |
Correct |
69 ms |
149084 KB |
Output is correct |
8 |
Correct |
70 ms |
148996 KB |
Output is correct |
9 |
Correct |
69 ms |
148940 KB |
Output is correct |
10 |
Correct |
71 ms |
149012 KB |
Output is correct |
11 |
Correct |
78 ms |
149176 KB |
Output is correct |
12 |
Correct |
75 ms |
149724 KB |
Output is correct |
13 |
Correct |
79 ms |
149676 KB |
Output is correct |
14 |
Correct |
75 ms |
149628 KB |
Output is correct |
15 |
Correct |
88 ms |
149640 KB |
Output is correct |
16 |
Correct |
75 ms |
149668 KB |
Output is correct |
17 |
Correct |
72 ms |
149468 KB |
Output is correct |
18 |
Correct |
73 ms |
149668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
471 ms |
158868 KB |
Output is correct |
2 |
Correct |
477 ms |
158836 KB |
Output is correct |
3 |
Correct |
455 ms |
158840 KB |
Output is correct |
4 |
Correct |
450 ms |
158964 KB |
Output is correct |
5 |
Correct |
459 ms |
158824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
340 ms |
163996 KB |
Output is correct |
2 |
Correct |
272 ms |
163916 KB |
Output is correct |
3 |
Correct |
340 ms |
164016 KB |
Output is correct |
4 |
Correct |
361 ms |
163892 KB |
Output is correct |
5 |
Correct |
337 ms |
164128 KB |
Output is correct |
6 |
Correct |
266 ms |
164096 KB |
Output is correct |
7 |
Correct |
250 ms |
163916 KB |
Output is correct |
8 |
Correct |
273 ms |
164004 KB |
Output is correct |
9 |
Correct |
111 ms |
149324 KB |
Output is correct |
10 |
Correct |
275 ms |
164124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
149068 KB |
Output is correct |
2 |
Correct |
69 ms |
148948 KB |
Output is correct |
3 |
Correct |
68 ms |
148924 KB |
Output is correct |
4 |
Correct |
67 ms |
148964 KB |
Output is correct |
5 |
Correct |
69 ms |
149040 KB |
Output is correct |
6 |
Correct |
68 ms |
149080 KB |
Output is correct |
7 |
Correct |
69 ms |
149084 KB |
Output is correct |
8 |
Correct |
70 ms |
148996 KB |
Output is correct |
9 |
Correct |
69 ms |
148940 KB |
Output is correct |
10 |
Correct |
71 ms |
149012 KB |
Output is correct |
11 |
Correct |
78 ms |
149176 KB |
Output is correct |
12 |
Correct |
75 ms |
149724 KB |
Output is correct |
13 |
Correct |
79 ms |
149676 KB |
Output is correct |
14 |
Correct |
75 ms |
149628 KB |
Output is correct |
15 |
Correct |
88 ms |
149640 KB |
Output is correct |
16 |
Correct |
75 ms |
149668 KB |
Output is correct |
17 |
Correct |
72 ms |
149468 KB |
Output is correct |
18 |
Correct |
73 ms |
149668 KB |
Output is correct |
19 |
Correct |
766 ms |
179652 KB |
Output is correct |
20 |
Correct |
758 ms |
179852 KB |
Output is correct |
21 |
Correct |
536 ms |
179672 KB |
Output is correct |
22 |
Correct |
532 ms |
179760 KB |
Output is correct |
23 |
Correct |
540 ms |
179660 KB |
Output is correct |
24 |
Correct |
570 ms |
179760 KB |
Output is correct |
25 |
Correct |
546 ms |
179660 KB |
Output is correct |
26 |
Correct |
773 ms |
179744 KB |
Output is correct |
27 |
Correct |
707 ms |
179772 KB |
Output is correct |
28 |
Correct |
769 ms |
179756 KB |
Output is correct |
29 |
Correct |
767 ms |
179800 KB |
Output is correct |
30 |
Correct |
747 ms |
179720 KB |
Output is correct |
31 |
Correct |
756 ms |
179812 KB |
Output is correct |
32 |
Correct |
830 ms |
179680 KB |
Output is correct |
33 |
Correct |
766 ms |
179728 KB |
Output is correct |
34 |
Correct |
498 ms |
179712 KB |
Output is correct |
35 |
Correct |
511 ms |
179872 KB |
Output is correct |
36 |
Correct |
507 ms |
179768 KB |
Output is correct |
37 |
Correct |
490 ms |
179696 KB |
Output is correct |
38 |
Correct |
496 ms |
179704 KB |
Output is correct |
39 |
Correct |
642 ms |
179788 KB |
Output is correct |
40 |
Correct |
414 ms |
169116 KB |
Output is correct |
41 |
Correct |
609 ms |
179992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
69 ms |
149068 KB |
Output is correct |
2 |
Correct |
69 ms |
148948 KB |
Output is correct |
3 |
Correct |
68 ms |
148924 KB |
Output is correct |
4 |
Correct |
67 ms |
148964 KB |
Output is correct |
5 |
Correct |
69 ms |
149040 KB |
Output is correct |
6 |
Correct |
68 ms |
149080 KB |
Output is correct |
7 |
Correct |
69 ms |
149084 KB |
Output is correct |
8 |
Correct |
70 ms |
148996 KB |
Output is correct |
9 |
Correct |
69 ms |
148940 KB |
Output is correct |
10 |
Correct |
71 ms |
149012 KB |
Output is correct |
11 |
Correct |
78 ms |
149176 KB |
Output is correct |
12 |
Correct |
75 ms |
149724 KB |
Output is correct |
13 |
Correct |
79 ms |
149676 KB |
Output is correct |
14 |
Correct |
75 ms |
149628 KB |
Output is correct |
15 |
Correct |
88 ms |
149640 KB |
Output is correct |
16 |
Correct |
75 ms |
149668 KB |
Output is correct |
17 |
Correct |
72 ms |
149468 KB |
Output is correct |
18 |
Correct |
73 ms |
149668 KB |
Output is correct |
19 |
Correct |
471 ms |
158868 KB |
Output is correct |
20 |
Correct |
477 ms |
158836 KB |
Output is correct |
21 |
Correct |
455 ms |
158840 KB |
Output is correct |
22 |
Correct |
450 ms |
158964 KB |
Output is correct |
23 |
Correct |
459 ms |
158824 KB |
Output is correct |
24 |
Correct |
340 ms |
163996 KB |
Output is correct |
25 |
Correct |
272 ms |
163916 KB |
Output is correct |
26 |
Correct |
340 ms |
164016 KB |
Output is correct |
27 |
Correct |
361 ms |
163892 KB |
Output is correct |
28 |
Correct |
337 ms |
164128 KB |
Output is correct |
29 |
Correct |
266 ms |
164096 KB |
Output is correct |
30 |
Correct |
250 ms |
163916 KB |
Output is correct |
31 |
Correct |
273 ms |
164004 KB |
Output is correct |
32 |
Correct |
111 ms |
149324 KB |
Output is correct |
33 |
Correct |
275 ms |
164124 KB |
Output is correct |
34 |
Correct |
766 ms |
179652 KB |
Output is correct |
35 |
Correct |
758 ms |
179852 KB |
Output is correct |
36 |
Correct |
536 ms |
179672 KB |
Output is correct |
37 |
Correct |
532 ms |
179760 KB |
Output is correct |
38 |
Correct |
540 ms |
179660 KB |
Output is correct |
39 |
Correct |
570 ms |
179760 KB |
Output is correct |
40 |
Correct |
546 ms |
179660 KB |
Output is correct |
41 |
Correct |
773 ms |
179744 KB |
Output is correct |
42 |
Correct |
707 ms |
179772 KB |
Output is correct |
43 |
Correct |
769 ms |
179756 KB |
Output is correct |
44 |
Correct |
767 ms |
179800 KB |
Output is correct |
45 |
Correct |
747 ms |
179720 KB |
Output is correct |
46 |
Correct |
756 ms |
179812 KB |
Output is correct |
47 |
Correct |
830 ms |
179680 KB |
Output is correct |
48 |
Correct |
766 ms |
179728 KB |
Output is correct |
49 |
Correct |
498 ms |
179712 KB |
Output is correct |
50 |
Correct |
511 ms |
179872 KB |
Output is correct |
51 |
Correct |
507 ms |
179768 KB |
Output is correct |
52 |
Correct |
490 ms |
179696 KB |
Output is correct |
53 |
Correct |
496 ms |
179704 KB |
Output is correct |
54 |
Correct |
642 ms |
179788 KB |
Output is correct |
55 |
Correct |
414 ms |
169116 KB |
Output is correct |
56 |
Correct |
609 ms |
179992 KB |
Output is correct |
57 |
Incorrect |
540 ms |
192520 KB |
Output isn't correct |
58 |
Halted |
0 ms |
0 KB |
- |