#include <bits/stdc++.h>
using namespace std;
#define task ""
#define fi first
#define se second
#define MASK(i) (1LL << (i))
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define BIT(mask, i) ((mask) >> (i) & 1)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (b), _a = (a); i >= _a; --i)
template <typename T1, typename T2> bool minimize(T1 &a, T2 b) {
if (a > b) {a = b; return true;} return false;
}
template <typename T1, typename T2> bool maximize(T1 &a, T2 b) {
if (a < b) {a = b; return true;} return false;
}
const int dx[] = {-1, 0, 0, +1};
const int dy[] = {0, -1, +1, 0};
const int MAX = 1000100;
int n, m;
int w[MAX];
bool ans[MAX];
vector<int> tmp;
#define value(x) (tmp[w[x] - 1])
struct query { int l, k, id; };
vector<query> queries[MAX];
int bit[MAX];
void update(int id, int delta) {
for (; id > 0; id -= id & -id)
bit[id] = max(bit[id], delta);
}
int get(int id) {
int res = 0;
for (; id <= n; id += id & -id)
res = max(res, bit[id]);
return res;
}
int st[MAX << 2];
void update(int id, int l, int r, int pos, int delta) {
if (l == r) st[id] = max(st[id], delta);
else {
int mid = l + r >> 1;
if (pos <= mid) update(id << 1, l, mid, pos, delta);
else update(id << 1 | 1, mid + 1, r, pos, delta);
st[id] = max(st[id << 1], st[id << 1 | 1]);
}
}
int get(int id, int l, int r, int u, int v) {
if (l > v || r < u) return 0;
if (l >= u && r <= v) return st[id];
int mid = l + r >> 1; return max(get(id << 1, l, mid, u, v), get(id << 1 | 1, mid + 1, r, u, v));
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(nullptr);
if (fopen(task".inp", "r")) {
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> w[i];
tmp.push_back(w[i]);
}
sort(all(tmp)); tmp.resize(unique(all(tmp)) - tmp.begin());
for (int i = 1; i <= n; ++i) {
w[i] = upper_bound(all(tmp), w[i]) - tmp.begin();
}
for (int i = 1; i <= m; ++i) {
int l, r, k; cin >> l >> r >> k;
queries[r].push_back({l, k, i});
}
for (int i = 1; i <= n; ++i) {
int id = get(w[i] + 1);
if (id) update(1, 1, n, id, value(i) + value(id));
for (query &x: queries[i]) {
int l = x.l, k = x.k, id = x.id;
int cc = get(1, 1, n, l, i);
ans[id] = k >= cc;
}
update(w[i], i);
}
for (int i = 1; i <= m; ++i) {
cout << ans[i] << '\n';
}
return 0;
}
Compilation message
sortbooks.cpp: In function 'void update(int, int, int, int, int)':
sortbooks.cpp:49:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
49 | int mid = l + r >> 1;
| ~~^~~
sortbooks.cpp: In function 'int get(int, int, int, int, int)':
sortbooks.cpp:58:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
58 | int mid = l + r >> 1; return max(get(id << 1, l, mid, u, v), get(id << 1 | 1, mid + 1, r, u, v));
| ~~^~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:65:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
65 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:66:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23836 KB |
Output is correct |
2 |
Correct |
11 ms |
23824 KB |
Output is correct |
3 |
Correct |
13 ms |
23824 KB |
Output is correct |
4 |
Correct |
11 ms |
23780 KB |
Output is correct |
5 |
Correct |
11 ms |
23820 KB |
Output is correct |
6 |
Correct |
11 ms |
23764 KB |
Output is correct |
7 |
Correct |
11 ms |
23764 KB |
Output is correct |
8 |
Correct |
11 ms |
23756 KB |
Output is correct |
9 |
Correct |
11 ms |
23764 KB |
Output is correct |
10 |
Correct |
11 ms |
23828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23836 KB |
Output is correct |
2 |
Correct |
11 ms |
23824 KB |
Output is correct |
3 |
Correct |
13 ms |
23824 KB |
Output is correct |
4 |
Correct |
11 ms |
23780 KB |
Output is correct |
5 |
Correct |
11 ms |
23820 KB |
Output is correct |
6 |
Correct |
11 ms |
23764 KB |
Output is correct |
7 |
Correct |
11 ms |
23764 KB |
Output is correct |
8 |
Correct |
11 ms |
23756 KB |
Output is correct |
9 |
Correct |
11 ms |
23764 KB |
Output is correct |
10 |
Correct |
11 ms |
23828 KB |
Output is correct |
11 |
Correct |
12 ms |
23944 KB |
Output is correct |
12 |
Correct |
13 ms |
24020 KB |
Output is correct |
13 |
Correct |
18 ms |
24124 KB |
Output is correct |
14 |
Correct |
18 ms |
24216 KB |
Output is correct |
15 |
Correct |
15 ms |
24204 KB |
Output is correct |
16 |
Correct |
14 ms |
24056 KB |
Output is correct |
17 |
Correct |
13 ms |
24092 KB |
Output is correct |
18 |
Correct |
13 ms |
24020 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1470 ms |
68600 KB |
Output is correct |
2 |
Correct |
1390 ms |
101316 KB |
Output is correct |
3 |
Correct |
1453 ms |
101148 KB |
Output is correct |
4 |
Correct |
1454 ms |
101400 KB |
Output is correct |
5 |
Correct |
967 ms |
93076 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
27944 KB |
Output is correct |
2 |
Correct |
95 ms |
29756 KB |
Output is correct |
3 |
Correct |
72 ms |
28828 KB |
Output is correct |
4 |
Correct |
73 ms |
28936 KB |
Output is correct |
5 |
Correct |
74 ms |
28960 KB |
Output is correct |
6 |
Correct |
62 ms |
28436 KB |
Output is correct |
7 |
Correct |
61 ms |
28452 KB |
Output is correct |
8 |
Correct |
66 ms |
28480 KB |
Output is correct |
9 |
Correct |
38 ms |
26912 KB |
Output is correct |
10 |
Correct |
67 ms |
28544 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23836 KB |
Output is correct |
2 |
Correct |
11 ms |
23824 KB |
Output is correct |
3 |
Correct |
13 ms |
23824 KB |
Output is correct |
4 |
Correct |
11 ms |
23780 KB |
Output is correct |
5 |
Correct |
11 ms |
23820 KB |
Output is correct |
6 |
Correct |
11 ms |
23764 KB |
Output is correct |
7 |
Correct |
11 ms |
23764 KB |
Output is correct |
8 |
Correct |
11 ms |
23756 KB |
Output is correct |
9 |
Correct |
11 ms |
23764 KB |
Output is correct |
10 |
Correct |
11 ms |
23828 KB |
Output is correct |
11 |
Correct |
12 ms |
23944 KB |
Output is correct |
12 |
Correct |
13 ms |
24020 KB |
Output is correct |
13 |
Correct |
18 ms |
24124 KB |
Output is correct |
14 |
Correct |
18 ms |
24216 KB |
Output is correct |
15 |
Correct |
15 ms |
24204 KB |
Output is correct |
16 |
Correct |
14 ms |
24056 KB |
Output is correct |
17 |
Correct |
13 ms |
24092 KB |
Output is correct |
18 |
Correct |
13 ms |
24020 KB |
Output is correct |
19 |
Correct |
235 ms |
39580 KB |
Output is correct |
20 |
Correct |
216 ms |
39604 KB |
Output is correct |
21 |
Correct |
195 ms |
39004 KB |
Output is correct |
22 |
Correct |
198 ms |
39008 KB |
Output is correct |
23 |
Correct |
208 ms |
38948 KB |
Output is correct |
24 |
Correct |
140 ms |
36784 KB |
Output is correct |
25 |
Correct |
148 ms |
36804 KB |
Output is correct |
26 |
Correct |
166 ms |
37092 KB |
Output is correct |
27 |
Correct |
155 ms |
37064 KB |
Output is correct |
28 |
Correct |
159 ms |
37144 KB |
Output is correct |
29 |
Correct |
167 ms |
37572 KB |
Output is correct |
30 |
Correct |
216 ms |
37620 KB |
Output is correct |
31 |
Correct |
165 ms |
37580 KB |
Output is correct |
32 |
Correct |
169 ms |
37512 KB |
Output is correct |
33 |
Correct |
181 ms |
37588 KB |
Output is correct |
34 |
Correct |
145 ms |
36400 KB |
Output is correct |
35 |
Correct |
133 ms |
36280 KB |
Output is correct |
36 |
Correct |
136 ms |
36412 KB |
Output is correct |
37 |
Correct |
132 ms |
36152 KB |
Output is correct |
38 |
Correct |
152 ms |
36284 KB |
Output is correct |
39 |
Correct |
165 ms |
36552 KB |
Output is correct |
40 |
Correct |
127 ms |
34072 KB |
Output is correct |
41 |
Correct |
140 ms |
34636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23836 KB |
Output is correct |
2 |
Correct |
11 ms |
23824 KB |
Output is correct |
3 |
Correct |
13 ms |
23824 KB |
Output is correct |
4 |
Correct |
11 ms |
23780 KB |
Output is correct |
5 |
Correct |
11 ms |
23820 KB |
Output is correct |
6 |
Correct |
11 ms |
23764 KB |
Output is correct |
7 |
Correct |
11 ms |
23764 KB |
Output is correct |
8 |
Correct |
11 ms |
23756 KB |
Output is correct |
9 |
Correct |
11 ms |
23764 KB |
Output is correct |
10 |
Correct |
11 ms |
23828 KB |
Output is correct |
11 |
Correct |
12 ms |
23944 KB |
Output is correct |
12 |
Correct |
13 ms |
24020 KB |
Output is correct |
13 |
Correct |
18 ms |
24124 KB |
Output is correct |
14 |
Correct |
18 ms |
24216 KB |
Output is correct |
15 |
Correct |
15 ms |
24204 KB |
Output is correct |
16 |
Correct |
14 ms |
24056 KB |
Output is correct |
17 |
Correct |
13 ms |
24092 KB |
Output is correct |
18 |
Correct |
13 ms |
24020 KB |
Output is correct |
19 |
Correct |
1470 ms |
68600 KB |
Output is correct |
20 |
Correct |
1390 ms |
101316 KB |
Output is correct |
21 |
Correct |
1453 ms |
101148 KB |
Output is correct |
22 |
Correct |
1454 ms |
101400 KB |
Output is correct |
23 |
Correct |
967 ms |
93076 KB |
Output is correct |
24 |
Correct |
91 ms |
27944 KB |
Output is correct |
25 |
Correct |
95 ms |
29756 KB |
Output is correct |
26 |
Correct |
72 ms |
28828 KB |
Output is correct |
27 |
Correct |
73 ms |
28936 KB |
Output is correct |
28 |
Correct |
74 ms |
28960 KB |
Output is correct |
29 |
Correct |
62 ms |
28436 KB |
Output is correct |
30 |
Correct |
61 ms |
28452 KB |
Output is correct |
31 |
Correct |
66 ms |
28480 KB |
Output is correct |
32 |
Correct |
38 ms |
26912 KB |
Output is correct |
33 |
Correct |
67 ms |
28544 KB |
Output is correct |
34 |
Correct |
235 ms |
39580 KB |
Output is correct |
35 |
Correct |
216 ms |
39604 KB |
Output is correct |
36 |
Correct |
195 ms |
39004 KB |
Output is correct |
37 |
Correct |
198 ms |
39008 KB |
Output is correct |
38 |
Correct |
208 ms |
38948 KB |
Output is correct |
39 |
Correct |
140 ms |
36784 KB |
Output is correct |
40 |
Correct |
148 ms |
36804 KB |
Output is correct |
41 |
Correct |
166 ms |
37092 KB |
Output is correct |
42 |
Correct |
155 ms |
37064 KB |
Output is correct |
43 |
Correct |
159 ms |
37144 KB |
Output is correct |
44 |
Correct |
167 ms |
37572 KB |
Output is correct |
45 |
Correct |
216 ms |
37620 KB |
Output is correct |
46 |
Correct |
165 ms |
37580 KB |
Output is correct |
47 |
Correct |
169 ms |
37512 KB |
Output is correct |
48 |
Correct |
181 ms |
37588 KB |
Output is correct |
49 |
Correct |
145 ms |
36400 KB |
Output is correct |
50 |
Correct |
133 ms |
36280 KB |
Output is correct |
51 |
Correct |
136 ms |
36412 KB |
Output is correct |
52 |
Correct |
132 ms |
36152 KB |
Output is correct |
53 |
Correct |
152 ms |
36284 KB |
Output is correct |
54 |
Correct |
165 ms |
36552 KB |
Output is correct |
55 |
Correct |
127 ms |
34072 KB |
Output is correct |
56 |
Correct |
140 ms |
34636 KB |
Output is correct |
57 |
Correct |
1423 ms |
101432 KB |
Output is correct |
58 |
Correct |
1457 ms |
101392 KB |
Output is correct |
59 |
Correct |
1279 ms |
99988 KB |
Output is correct |
60 |
Correct |
1268 ms |
99920 KB |
Output is correct |
61 |
Correct |
1301 ms |
99824 KB |
Output is correct |
62 |
Correct |
1363 ms |
99860 KB |
Output is correct |
63 |
Correct |
746 ms |
88648 KB |
Output is correct |
64 |
Correct |
686 ms |
88552 KB |
Output is correct |
65 |
Correct |
865 ms |
91544 KB |
Output is correct |
66 |
Correct |
895 ms |
91512 KB |
Output is correct |
67 |
Correct |
906 ms |
91652 KB |
Output is correct |
68 |
Correct |
1018 ms |
93372 KB |
Output is correct |
69 |
Correct |
941 ms |
93248 KB |
Output is correct |
70 |
Correct |
955 ms |
92956 KB |
Output is correct |
71 |
Correct |
952 ms |
92968 KB |
Output is correct |
72 |
Correct |
977 ms |
93060 KB |
Output is correct |
73 |
Correct |
652 ms |
84696 KB |
Output is correct |
74 |
Correct |
655 ms |
85416 KB |
Output is correct |
75 |
Correct |
659 ms |
84552 KB |
Output is correct |
76 |
Correct |
705 ms |
84644 KB |
Output is correct |
77 |
Correct |
655 ms |
84324 KB |
Output is correct |
78 |
Correct |
889 ms |
88192 KB |
Output is correct |
79 |
Correct |
659 ms |
72760 KB |
Output is correct |
80 |
Correct |
777 ms |
78756 KB |
Output is correct |