#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <fstream>
#include <bitset>
typedef long long ll;
using namespace std;
const int N = 1e6 + 10;
struct query {
int l;
int r;
int k;
int ind;
};
bool cmp(query x, query y) {
return x.l > y.l;
}
int a[N], l[N];
int b[N];
int tree[4 * N];
int ans[N];
void update(int v, int tl, int tr, int pos, int val) {
if (tl == tr) {
tree[v] = val;
return;
}
int tm = (tl + tr) / 2;
if (pos <= tm) {
update(2 * v, tl, tm, pos, val);
}
else {
update(2 * v + 1, tm + 1, tr, pos, val);
}
tree[v] = max(tree[2 * v], tree[2 * v + 1]);
}
int MAX(int v, int tl, int tr, int l, int r) {
if (tr < l || tl > r) return 0;
if (tl >= l && tr <= r) return tree[v];
int tm = (tl + tr) / 2;
return max(MAX(2 * v, tl, tm, l, r),
MAX(2 * v + 1, tm + 1, tr, l, r));
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int n, q;
cin >> n >> q;
a[0] = 1e9 + 10;
vector <vector<int>> updates(n);
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
l[i] = i - 1;
while (a[i] >= a[l[i]]) {
l[i] = l[l[i]];
}
b[i] = a[i] + a[l[i]];
updates[l[i]].push_back(i);
}
vector <query> v;
for (int i = 1; i <= q; i++) {
int l, r, k;
cin >> l >> r >> k;
v.push_back({ l, r, k, i });
}
sort(v.begin(), v.end(), cmp);
int prev_ind = n - 1;
for (auto it : v) {
int l = it.l, r = it.r, k = it.k, ind = it.ind;
while (prev_ind >= l) {
for (auto it : updates[prev_ind]) {
update(1, 1, n, it, b[it]);
}
prev_ind--;
}
ans[ind] = (k >= MAX(1, 1, n, l, r))? 1: 0;
}
for (int i = 1; i <= q; i++) {
cout << ans[i] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8536 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8536 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
8796 KB |
Output is correct |
12 |
Correct |
4 ms |
8924 KB |
Output is correct |
13 |
Correct |
4 ms |
9048 KB |
Output is correct |
14 |
Correct |
5 ms |
9052 KB |
Output is correct |
15 |
Correct |
5 ms |
9052 KB |
Output is correct |
16 |
Correct |
4 ms |
7004 KB |
Output is correct |
17 |
Correct |
3 ms |
7004 KB |
Output is correct |
18 |
Correct |
4 ms |
7000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
947 ms |
107992 KB |
Output is correct |
2 |
Correct |
1002 ms |
108156 KB |
Output is correct |
3 |
Correct |
962 ms |
107752 KB |
Output is correct |
4 |
Correct |
962 ms |
108204 KB |
Output is correct |
5 |
Correct |
754 ms |
87768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
77 ms |
19212 KB |
Output is correct |
2 |
Correct |
80 ms |
20440 KB |
Output is correct |
3 |
Correct |
67 ms |
15064 KB |
Output is correct |
4 |
Correct |
62 ms |
15180 KB |
Output is correct |
5 |
Correct |
68 ms |
15176 KB |
Output is correct |
6 |
Correct |
66 ms |
19336 KB |
Output is correct |
7 |
Correct |
56 ms |
19336 KB |
Output is correct |
8 |
Correct |
60 ms |
15880 KB |
Output is correct |
9 |
Correct |
32 ms |
11996 KB |
Output is correct |
10 |
Correct |
59 ms |
15692 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8536 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
8796 KB |
Output is correct |
12 |
Correct |
4 ms |
8924 KB |
Output is correct |
13 |
Correct |
4 ms |
9048 KB |
Output is correct |
14 |
Correct |
5 ms |
9052 KB |
Output is correct |
15 |
Correct |
5 ms |
9052 KB |
Output is correct |
16 |
Correct |
4 ms |
7004 KB |
Output is correct |
17 |
Correct |
3 ms |
7004 KB |
Output is correct |
18 |
Correct |
4 ms |
7000 KB |
Output is correct |
19 |
Correct |
173 ms |
29372 KB |
Output is correct |
20 |
Correct |
178 ms |
29344 KB |
Output is correct |
21 |
Correct |
172 ms |
29784 KB |
Output is correct |
22 |
Correct |
161 ms |
29724 KB |
Output is correct |
23 |
Correct |
163 ms |
30400 KB |
Output is correct |
24 |
Correct |
127 ms |
23372 KB |
Output is correct |
25 |
Correct |
127 ms |
23108 KB |
Output is correct |
26 |
Correct |
142 ms |
23880 KB |
Output is correct |
27 |
Correct |
138 ms |
23368 KB |
Output is correct |
28 |
Correct |
149 ms |
23236 KB |
Output is correct |
29 |
Correct |
140 ms |
23228 KB |
Output is correct |
30 |
Correct |
170 ms |
24188 KB |
Output is correct |
31 |
Correct |
141 ms |
23368 KB |
Output is correct |
32 |
Correct |
141 ms |
23372 KB |
Output is correct |
33 |
Correct |
145 ms |
23512 KB |
Output is correct |
34 |
Correct |
118 ms |
27208 KB |
Output is correct |
35 |
Correct |
121 ms |
27044 KB |
Output is correct |
36 |
Correct |
121 ms |
26864 KB |
Output is correct |
37 |
Correct |
119 ms |
27724 KB |
Output is correct |
38 |
Correct |
119 ms |
27204 KB |
Output is correct |
39 |
Correct |
131 ms |
24132 KB |
Output is correct |
40 |
Correct |
96 ms |
20040 KB |
Output is correct |
41 |
Correct |
124 ms |
23260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8536 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
6492 KB |
Output is correct |
9 |
Correct |
1 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
3 ms |
8796 KB |
Output is correct |
12 |
Correct |
4 ms |
8924 KB |
Output is correct |
13 |
Correct |
4 ms |
9048 KB |
Output is correct |
14 |
Correct |
5 ms |
9052 KB |
Output is correct |
15 |
Correct |
5 ms |
9052 KB |
Output is correct |
16 |
Correct |
4 ms |
7004 KB |
Output is correct |
17 |
Correct |
3 ms |
7004 KB |
Output is correct |
18 |
Correct |
4 ms |
7000 KB |
Output is correct |
19 |
Correct |
947 ms |
107992 KB |
Output is correct |
20 |
Correct |
1002 ms |
108156 KB |
Output is correct |
21 |
Correct |
962 ms |
107752 KB |
Output is correct |
22 |
Correct |
962 ms |
108204 KB |
Output is correct |
23 |
Correct |
754 ms |
87768 KB |
Output is correct |
24 |
Correct |
77 ms |
19212 KB |
Output is correct |
25 |
Correct |
80 ms |
20440 KB |
Output is correct |
26 |
Correct |
67 ms |
15064 KB |
Output is correct |
27 |
Correct |
62 ms |
15180 KB |
Output is correct |
28 |
Correct |
68 ms |
15176 KB |
Output is correct |
29 |
Correct |
66 ms |
19336 KB |
Output is correct |
30 |
Correct |
56 ms |
19336 KB |
Output is correct |
31 |
Correct |
60 ms |
15880 KB |
Output is correct |
32 |
Correct |
32 ms |
11996 KB |
Output is correct |
33 |
Correct |
59 ms |
15692 KB |
Output is correct |
34 |
Correct |
173 ms |
29372 KB |
Output is correct |
35 |
Correct |
178 ms |
29344 KB |
Output is correct |
36 |
Correct |
172 ms |
29784 KB |
Output is correct |
37 |
Correct |
161 ms |
29724 KB |
Output is correct |
38 |
Correct |
163 ms |
30400 KB |
Output is correct |
39 |
Correct |
127 ms |
23372 KB |
Output is correct |
40 |
Correct |
127 ms |
23108 KB |
Output is correct |
41 |
Correct |
142 ms |
23880 KB |
Output is correct |
42 |
Correct |
138 ms |
23368 KB |
Output is correct |
43 |
Correct |
149 ms |
23236 KB |
Output is correct |
44 |
Correct |
140 ms |
23228 KB |
Output is correct |
45 |
Correct |
170 ms |
24188 KB |
Output is correct |
46 |
Correct |
141 ms |
23368 KB |
Output is correct |
47 |
Correct |
141 ms |
23372 KB |
Output is correct |
48 |
Correct |
145 ms |
23512 KB |
Output is correct |
49 |
Correct |
118 ms |
27208 KB |
Output is correct |
50 |
Correct |
121 ms |
27044 KB |
Output is correct |
51 |
Correct |
121 ms |
26864 KB |
Output is correct |
52 |
Correct |
119 ms |
27724 KB |
Output is correct |
53 |
Correct |
119 ms |
27204 KB |
Output is correct |
54 |
Correct |
131 ms |
24132 KB |
Output is correct |
55 |
Correct |
96 ms |
20040 KB |
Output is correct |
56 |
Correct |
124 ms |
23260 KB |
Output is correct |
57 |
Correct |
948 ms |
108536 KB |
Output is correct |
58 |
Correct |
924 ms |
99648 KB |
Output is correct |
59 |
Correct |
966 ms |
99604 KB |
Output is correct |
60 |
Correct |
904 ms |
108236 KB |
Output is correct |
61 |
Correct |
939 ms |
108376 KB |
Output is correct |
62 |
Correct |
932 ms |
108880 KB |
Output is correct |
63 |
Correct |
718 ms |
86616 KB |
Output is correct |
64 |
Correct |
650 ms |
86240 KB |
Output is correct |
65 |
Correct |
736 ms |
87576 KB |
Output is correct |
66 |
Correct |
748 ms |
87392 KB |
Output is correct |
67 |
Correct |
773 ms |
87448 KB |
Output is correct |
68 |
Correct |
754 ms |
88060 KB |
Output is correct |
69 |
Correct |
736 ms |
88040 KB |
Output is correct |
70 |
Correct |
748 ms |
88032 KB |
Output is correct |
71 |
Correct |
743 ms |
87604 KB |
Output is correct |
72 |
Correct |
762 ms |
87432 KB |
Output is correct |
73 |
Correct |
637 ms |
83968 KB |
Output is correct |
74 |
Correct |
633 ms |
84460 KB |
Output is correct |
75 |
Correct |
647 ms |
84420 KB |
Output is correct |
76 |
Correct |
625 ms |
83992 KB |
Output is correct |
77 |
Correct |
620 ms |
84444 KB |
Output is correct |
78 |
Correct |
773 ms |
84596 KB |
Output is correct |
79 |
Correct |
509 ms |
63524 KB |
Output is correct |
80 |
Correct |
690 ms |
82788 KB |
Output is correct |