#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[3*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;
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()) {
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
117620 KB |
Output is correct |
2 |
Correct |
55 ms |
117696 KB |
Output is correct |
3 |
Correct |
62 ms |
117676 KB |
Output is correct |
4 |
Correct |
55 ms |
117628 KB |
Output is correct |
5 |
Correct |
54 ms |
117708 KB |
Output is correct |
6 |
Correct |
78 ms |
117776 KB |
Output is correct |
7 |
Correct |
74 ms |
117680 KB |
Output is correct |
8 |
Correct |
71 ms |
117780 KB |
Output is correct |
9 |
Correct |
62 ms |
117728 KB |
Output is correct |
10 |
Correct |
54 ms |
117708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
117620 KB |
Output is correct |
2 |
Correct |
55 ms |
117696 KB |
Output is correct |
3 |
Correct |
62 ms |
117676 KB |
Output is correct |
4 |
Correct |
55 ms |
117628 KB |
Output is correct |
5 |
Correct |
54 ms |
117708 KB |
Output is correct |
6 |
Correct |
78 ms |
117776 KB |
Output is correct |
7 |
Correct |
74 ms |
117680 KB |
Output is correct |
8 |
Correct |
71 ms |
117780 KB |
Output is correct |
9 |
Correct |
62 ms |
117728 KB |
Output is correct |
10 |
Correct |
54 ms |
117708 KB |
Output is correct |
11 |
Correct |
78 ms |
117904 KB |
Output is correct |
12 |
Correct |
76 ms |
118360 KB |
Output is correct |
13 |
Correct |
61 ms |
118256 KB |
Output is correct |
14 |
Correct |
61 ms |
118348 KB |
Output is correct |
15 |
Correct |
62 ms |
118300 KB |
Output is correct |
16 |
Correct |
87 ms |
118268 KB |
Output is correct |
17 |
Correct |
73 ms |
118268 KB |
Output is correct |
18 |
Correct |
66 ms |
118352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
527 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
398 ms |
132628 KB |
Output is correct |
2 |
Correct |
310 ms |
132684 KB |
Output is correct |
3 |
Correct |
372 ms |
132728 KB |
Output is correct |
4 |
Correct |
357 ms |
132800 KB |
Output is correct |
5 |
Correct |
359 ms |
132784 KB |
Output is correct |
6 |
Correct |
250 ms |
132620 KB |
Output is correct |
7 |
Correct |
263 ms |
132708 KB |
Output is correct |
8 |
Correct |
269 ms |
132692 KB |
Output is correct |
9 |
Correct |
113 ms |
117956 KB |
Output is correct |
10 |
Correct |
307 ms |
132768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
117620 KB |
Output is correct |
2 |
Correct |
55 ms |
117696 KB |
Output is correct |
3 |
Correct |
62 ms |
117676 KB |
Output is correct |
4 |
Correct |
55 ms |
117628 KB |
Output is correct |
5 |
Correct |
54 ms |
117708 KB |
Output is correct |
6 |
Correct |
78 ms |
117776 KB |
Output is correct |
7 |
Correct |
74 ms |
117680 KB |
Output is correct |
8 |
Correct |
71 ms |
117780 KB |
Output is correct |
9 |
Correct |
62 ms |
117728 KB |
Output is correct |
10 |
Correct |
54 ms |
117708 KB |
Output is correct |
11 |
Correct |
78 ms |
117904 KB |
Output is correct |
12 |
Correct |
76 ms |
118360 KB |
Output is correct |
13 |
Correct |
61 ms |
118256 KB |
Output is correct |
14 |
Correct |
61 ms |
118348 KB |
Output is correct |
15 |
Correct |
62 ms |
118300 KB |
Output is correct |
16 |
Correct |
87 ms |
118268 KB |
Output is correct |
17 |
Correct |
73 ms |
118268 KB |
Output is correct |
18 |
Correct |
66 ms |
118352 KB |
Output is correct |
19 |
Correct |
828 ms |
148564 KB |
Output is correct |
20 |
Correct |
878 ms |
148420 KB |
Output is correct |
21 |
Correct |
593 ms |
148364 KB |
Output is correct |
22 |
Correct |
575 ms |
148380 KB |
Output is correct |
23 |
Correct |
648 ms |
148480 KB |
Output is correct |
24 |
Correct |
545 ms |
148424 KB |
Output is correct |
25 |
Correct |
561 ms |
148452 KB |
Output is correct |
26 |
Correct |
811 ms |
148572 KB |
Output is correct |
27 |
Correct |
823 ms |
148448 KB |
Output is correct |
28 |
Correct |
819 ms |
148348 KB |
Output is correct |
29 |
Correct |
816 ms |
148612 KB |
Output is correct |
30 |
Correct |
796 ms |
148516 KB |
Output is correct |
31 |
Correct |
822 ms |
148416 KB |
Output is correct |
32 |
Correct |
853 ms |
148420 KB |
Output is correct |
33 |
Correct |
847 ms |
148444 KB |
Output is correct |
34 |
Correct |
525 ms |
148436 KB |
Output is correct |
35 |
Correct |
506 ms |
148380 KB |
Output is correct |
36 |
Correct |
497 ms |
148532 KB |
Output is correct |
37 |
Correct |
503 ms |
148312 KB |
Output is correct |
38 |
Correct |
532 ms |
148388 KB |
Output is correct |
39 |
Correct |
708 ms |
148344 KB |
Output is correct |
40 |
Correct |
439 ms |
137684 KB |
Output is correct |
41 |
Correct |
686 ms |
148372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
117620 KB |
Output is correct |
2 |
Correct |
55 ms |
117696 KB |
Output is correct |
3 |
Correct |
62 ms |
117676 KB |
Output is correct |
4 |
Correct |
55 ms |
117628 KB |
Output is correct |
5 |
Correct |
54 ms |
117708 KB |
Output is correct |
6 |
Correct |
78 ms |
117776 KB |
Output is correct |
7 |
Correct |
74 ms |
117680 KB |
Output is correct |
8 |
Correct |
71 ms |
117780 KB |
Output is correct |
9 |
Correct |
62 ms |
117728 KB |
Output is correct |
10 |
Correct |
54 ms |
117708 KB |
Output is correct |
11 |
Correct |
78 ms |
117904 KB |
Output is correct |
12 |
Correct |
76 ms |
118360 KB |
Output is correct |
13 |
Correct |
61 ms |
118256 KB |
Output is correct |
14 |
Correct |
61 ms |
118348 KB |
Output is correct |
15 |
Correct |
62 ms |
118300 KB |
Output is correct |
16 |
Correct |
87 ms |
118268 KB |
Output is correct |
17 |
Correct |
73 ms |
118268 KB |
Output is correct |
18 |
Correct |
66 ms |
118352 KB |
Output is correct |
19 |
Runtime error |
527 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |