#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;
int sz = 0;
struct Node {
int left;
int right;
int mx;
};
int a[N], l[N];
int b[N];
int root[N];
Node tree[30 * N];
void build_tree(int v, int tl, int tr) {
tree[v].left = 0;
tree[v].right = 0;
tree[v].mx = 0;
if (tl != tr) {
tree[v].left = ++sz;
tree[v].right = ++sz;
int tm = (tl + tr) / 2;
build_tree(tree[v].left, tl, tm);
build_tree(tree[v].right, tm + 1, tr);
}
}
void update(int v, int prev_v, int tl, int tr, int pos, int val) {
if (tl == tr) {
tree[v].mx = val;
return;
}
int tm = (tl + tr) / 2;
if (pos <= tm) {
tree[v].right = tree[prev_v].right;
tree[v].left = ++sz;
update(tree[v].left, tree[prev_v].left, tl, tm, pos, val);
}
else {
tree[v].left = tree[prev_v].left;
tree[v].right = ++sz;
update(tree[v].right, tree[prev_v].right, tm + 1, tr, pos, val);
}
tree[v].mx = max(tree[tree[v].left].mx, tree[tree[v].right].mx);
}
int MAX(int v, int tl, int tr, int l, int r) {
if (tl > r || tr < l) return 0;
if (tl >= l && tr <= r) return tree[v].mx;
int tm = (tl + tr) / 2;
return max(MAX(tree[v].left, tl, tm, l, r), MAX(tree[v].right, tm + 1, tr, l, r));
}
int main() {
int n, q;
cin >> n >> q;
for (int i = 1; i <= 24 * n; i++) {
tree[i] = { 0, 0, 0 };
}
a[0] = 1e9 + 10;
vector <pair<int, int>> updates;
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.push_back({ l[i], i });
}
updates.push_back({ n, 0 });
sort(updates.begin(), updates.end());
root[n] = ++sz;
build_tree(root[n], 1, n);
for (int i = n - 1; i >= 0; i--) {
root[i] = ++sz;
update(root[i], root[i + 1], 1, n, updates[i].second, b[updates[i].second]);
}
while (q--) {
int l, r, k;
cin >> l >> r >> k;
int ind = lower_bound(updates.begin(), updates.end(), make_pair(l, 0)) - updates.begin();
if (MAX(root[ind], 1, n, l, r) <= k) cout << 1 << "\n";
else cout << 0 << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
8 ms |
10844 KB |
Output is correct |
12 |
Correct |
9 ms |
10840 KB |
Output is correct |
13 |
Correct |
10 ms |
11100 KB |
Output is correct |
14 |
Correct |
14 ms |
11100 KB |
Output is correct |
15 |
Correct |
15 ms |
11100 KB |
Output is correct |
16 |
Correct |
13 ms |
11252 KB |
Output is correct |
17 |
Correct |
12 ms |
10840 KB |
Output is correct |
18 |
Correct |
12 ms |
10844 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
100 ms |
262144 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
283 ms |
40420 KB |
Output is correct |
2 |
Correct |
255 ms |
40452 KB |
Output is correct |
3 |
Correct |
242 ms |
40388 KB |
Output is correct |
4 |
Correct |
246 ms |
40640 KB |
Output is correct |
5 |
Correct |
239 ms |
40528 KB |
Output is correct |
6 |
Correct |
234 ms |
40392 KB |
Output is correct |
7 |
Correct |
239 ms |
40628 KB |
Output is correct |
8 |
Correct |
228 ms |
40128 KB |
Output is correct |
9 |
Correct |
178 ms |
10064 KB |
Output is correct |
10 |
Correct |
228 ms |
40128 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
8 ms |
10844 KB |
Output is correct |
12 |
Correct |
9 ms |
10840 KB |
Output is correct |
13 |
Correct |
10 ms |
11100 KB |
Output is correct |
14 |
Correct |
14 ms |
11100 KB |
Output is correct |
15 |
Correct |
15 ms |
11100 KB |
Output is correct |
16 |
Correct |
13 ms |
11252 KB |
Output is correct |
17 |
Correct |
12 ms |
10840 KB |
Output is correct |
18 |
Correct |
12 ms |
10844 KB |
Output is correct |
19 |
Correct |
674 ms |
74856 KB |
Output is correct |
20 |
Correct |
655 ms |
75120 KB |
Output is correct |
21 |
Correct |
569 ms |
74688 KB |
Output is correct |
22 |
Correct |
567 ms |
74600 KB |
Output is correct |
23 |
Correct |
576 ms |
74836 KB |
Output is correct |
24 |
Correct |
533 ms |
74432 KB |
Output is correct |
25 |
Correct |
533 ms |
74684 KB |
Output is correct |
26 |
Correct |
564 ms |
74820 KB |
Output is correct |
27 |
Correct |
557 ms |
75520 KB |
Output is correct |
28 |
Correct |
542 ms |
74796 KB |
Output is correct |
29 |
Correct |
553 ms |
74920 KB |
Output is correct |
30 |
Correct |
640 ms |
74848 KB |
Output is correct |
31 |
Correct |
557 ms |
74920 KB |
Output is correct |
32 |
Correct |
553 ms |
74944 KB |
Output is correct |
33 |
Correct |
554 ms |
74916 KB |
Output is correct |
34 |
Correct |
526 ms |
74432 KB |
Output is correct |
35 |
Correct |
524 ms |
74372 KB |
Output is correct |
36 |
Correct |
521 ms |
74132 KB |
Output is correct |
37 |
Correct |
594 ms |
74540 KB |
Output is correct |
38 |
Correct |
531 ms |
74684 KB |
Output is correct |
39 |
Correct |
520 ms |
73404 KB |
Output is correct |
40 |
Correct |
456 ms |
51648 KB |
Output is correct |
41 |
Correct |
532 ms |
73060 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
2 ms |
8540 KB |
Output is correct |
4 |
Correct |
2 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
3 ms |
8796 KB |
Output is correct |
7 |
Correct |
2 ms |
8796 KB |
Output is correct |
8 |
Correct |
2 ms |
8796 KB |
Output is correct |
9 |
Correct |
2 ms |
8540 KB |
Output is correct |
10 |
Correct |
2 ms |
8796 KB |
Output is correct |
11 |
Correct |
8 ms |
10844 KB |
Output is correct |
12 |
Correct |
9 ms |
10840 KB |
Output is correct |
13 |
Correct |
10 ms |
11100 KB |
Output is correct |
14 |
Correct |
14 ms |
11100 KB |
Output is correct |
15 |
Correct |
15 ms |
11100 KB |
Output is correct |
16 |
Correct |
13 ms |
11252 KB |
Output is correct |
17 |
Correct |
12 ms |
10840 KB |
Output is correct |
18 |
Correct |
12 ms |
10844 KB |
Output is correct |
19 |
Runtime error |
100 ms |
262144 KB |
Execution killed with signal 9 |
20 |
Halted |
0 ms |
0 KB |
- |