#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define tp3 tuple<int, int, int>
const int N = 1e6, L = 20, inf = INT_MAX;
int n, m, mnA, mxK, a[N], b[N], mxL[N], lg[N], st[L][N], seg[N*4];
vector<int> lf[N];
vector<tp3> q[N];
bitset<N> ans;
void build(int p=1, int l=0, int r=n-1) {
if (l == r) {
seg[p] = (b[l] == -1 ? 0 : (a[l] + a[b[l]]));
return;
}
int mid = (l+r) >> 1;
build(p*2, l, mid);
build(p*2+1, mid+1, r);
seg[p] = max(seg[p*2], seg[p*2+1]);
}
void update(int x, int p=1, int l=0, int r=n-1) {
if (l == r) {
seg[p] = 0;
return;
}
int mid = (l+r) >> 1;
if (x <= mid) update(x, p*2, l, mid);
else update(x, p*2+1, mid+1, r);
seg[p] = max(seg[p*2], seg[p*2+1]);
}
int query(int x, int y, int p=1, int l=0, int r=n-1) {
if (x <= l && r <= y) {
return seg[p];
}
int mid = (l+r) >> 1;
if (y <= mid) {
return query(x, y, p*2, l, mid);
}
else if(mid+1 <= x) {
return query(x, y, p*2+1, mid+1, r);
}
else {
return max(query(x, y, p*2, l, mid), query(x, y, p*2+1, mid+1, r));
}
}
int querySt(int l, int r) {
int x = lg[r-l+1];
return max(st[x][l], st[x][r - (1 << x) + 1]);
}
signed main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
lg[1] = 0;
for (int i = 2; i < N; i++) {
lg[i] = lg[i >> 1] + 1;
}
cin >> n >> m;
mnA = inf;
for (int i = 0; i < n; i++) {
cin >> a[i];
mnA = min(mnA, a[i]);
st[0][i] = a[i];
}
mxK = -inf;
for (int i = 0; i < m; i++) {
int l, r, k;
cin >> l >> r >> k;
l--; r--;
mxK = max(mxK, k);
q[l].push_back(make_tuple(r, k, i));
}
if (mxK < mnA) {
int curr = 0;
mxL[0] = 0;
for (int i = 1; i < n; i++) {
if (a[i-1] > a[i]) {
curr = i;
}
mxL[i] = curr;
}
for (int l = 0; l < n; l++) {
for (auto& [r, k, idx] : q[l]) {
ans[idx] = (mxL[r] <= l);
}
}
}
else {
for (int j = 1; j < L; j++) {
for (int i = 0; i < n; i++) {
st[j][i] = max(st[j-1][i], st[j-1][i + (1 << (j-1))]);
}
}
for (int i = 0; i < n; i++) {
int l = -1;
int r = i-1;
while (l < r) {
int mid = (l+r+1)/2;
int x = querySt(mid, i-1);
if (x > a[i]) l = mid;
else r = mid-1;
}
b[i] = l;
lf[l].push_back(i);
}
build();
for (int l = 0; l < n; l++) {
for (auto& [r, k, idx] : q[l]) {
ans[idx] = (query(0, r) <= k);
}
for (int& i : lf[l]) {
update(i);
}
}
}
for (int i = 0; i < m; i++) {
cout << ans[i] << "\n";
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
98920 KB |
Output is correct |
2 |
Correct |
18 ms |
98908 KB |
Output is correct |
3 |
Correct |
19 ms |
98908 KB |
Output is correct |
4 |
Correct |
18 ms |
98908 KB |
Output is correct |
5 |
Correct |
18 ms |
98908 KB |
Output is correct |
6 |
Correct |
19 ms |
99108 KB |
Output is correct |
7 |
Correct |
20 ms |
98908 KB |
Output is correct |
8 |
Correct |
19 ms |
98844 KB |
Output is correct |
9 |
Correct |
19 ms |
98896 KB |
Output is correct |
10 |
Correct |
19 ms |
98904 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
98920 KB |
Output is correct |
2 |
Correct |
18 ms |
98908 KB |
Output is correct |
3 |
Correct |
19 ms |
98908 KB |
Output is correct |
4 |
Correct |
18 ms |
98908 KB |
Output is correct |
5 |
Correct |
18 ms |
98908 KB |
Output is correct |
6 |
Correct |
19 ms |
99108 KB |
Output is correct |
7 |
Correct |
20 ms |
98908 KB |
Output is correct |
8 |
Correct |
19 ms |
98844 KB |
Output is correct |
9 |
Correct |
19 ms |
98896 KB |
Output is correct |
10 |
Correct |
19 ms |
98904 KB |
Output is correct |
11 |
Correct |
20 ms |
99164 KB |
Output is correct |
12 |
Correct |
22 ms |
99184 KB |
Output is correct |
13 |
Correct |
22 ms |
99252 KB |
Output is correct |
14 |
Correct |
22 ms |
99288 KB |
Output is correct |
15 |
Correct |
22 ms |
99160 KB |
Output is correct |
16 |
Correct |
21 ms |
99164 KB |
Output is correct |
17 |
Correct |
21 ms |
99164 KB |
Output is correct |
18 |
Correct |
21 ms |
99164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
542 ms |
92768 KB |
Output is correct |
2 |
Correct |
623 ms |
92404 KB |
Output is correct |
3 |
Correct |
590 ms |
92944 KB |
Output is correct |
4 |
Correct |
594 ms |
92580 KB |
Output is correct |
5 |
Correct |
610 ms |
92500 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
84 ms |
113236 KB |
Output is correct |
2 |
Correct |
104 ms |
114640 KB |
Output is correct |
3 |
Correct |
88 ms |
113920 KB |
Output is correct |
4 |
Correct |
73 ms |
114124 KB |
Output is correct |
5 |
Correct |
74 ms |
114032 KB |
Output is correct |
6 |
Correct |
61 ms |
113360 KB |
Output is correct |
7 |
Correct |
60 ms |
113396 KB |
Output is correct |
8 |
Correct |
71 ms |
113416 KB |
Output is correct |
9 |
Correct |
61 ms |
101896 KB |
Output is correct |
10 |
Correct |
93 ms |
113420 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
98920 KB |
Output is correct |
2 |
Correct |
18 ms |
98908 KB |
Output is correct |
3 |
Correct |
19 ms |
98908 KB |
Output is correct |
4 |
Correct |
18 ms |
98908 KB |
Output is correct |
5 |
Correct |
18 ms |
98908 KB |
Output is correct |
6 |
Correct |
19 ms |
99108 KB |
Output is correct |
7 |
Correct |
20 ms |
98908 KB |
Output is correct |
8 |
Correct |
19 ms |
98844 KB |
Output is correct |
9 |
Correct |
19 ms |
98896 KB |
Output is correct |
10 |
Correct |
19 ms |
98904 KB |
Output is correct |
11 |
Correct |
20 ms |
99164 KB |
Output is correct |
12 |
Correct |
22 ms |
99184 KB |
Output is correct |
13 |
Correct |
22 ms |
99252 KB |
Output is correct |
14 |
Correct |
22 ms |
99288 KB |
Output is correct |
15 |
Correct |
22 ms |
99160 KB |
Output is correct |
16 |
Correct |
21 ms |
99164 KB |
Output is correct |
17 |
Correct |
21 ms |
99164 KB |
Output is correct |
18 |
Correct |
21 ms |
99164 KB |
Output is correct |
19 |
Correct |
171 ms |
130132 KB |
Output is correct |
20 |
Correct |
171 ms |
129996 KB |
Output is correct |
21 |
Correct |
167 ms |
128852 KB |
Output is correct |
22 |
Correct |
150 ms |
128988 KB |
Output is correct |
23 |
Correct |
177 ms |
128944 KB |
Output is correct |
24 |
Correct |
121 ms |
126868 KB |
Output is correct |
25 |
Correct |
132 ms |
126944 KB |
Output is correct |
26 |
Correct |
137 ms |
127196 KB |
Output is correct |
27 |
Correct |
137 ms |
127304 KB |
Output is correct |
28 |
Correct |
133 ms |
127180 KB |
Output is correct |
29 |
Correct |
140 ms |
127828 KB |
Output is correct |
30 |
Correct |
144 ms |
127680 KB |
Output is correct |
31 |
Correct |
144 ms |
127688 KB |
Output is correct |
32 |
Correct |
146 ms |
127684 KB |
Output is correct |
33 |
Correct |
156 ms |
127560 KB |
Output is correct |
34 |
Correct |
116 ms |
126280 KB |
Output is correct |
35 |
Correct |
115 ms |
126088 KB |
Output is correct |
36 |
Correct |
118 ms |
126148 KB |
Output is correct |
37 |
Correct |
114 ms |
125896 KB |
Output is correct |
38 |
Correct |
113 ms |
126152 KB |
Output is correct |
39 |
Correct |
131 ms |
126220 KB |
Output is correct |
40 |
Correct |
106 ms |
120324 KB |
Output is correct |
41 |
Correct |
133 ms |
125352 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
98920 KB |
Output is correct |
2 |
Correct |
18 ms |
98908 KB |
Output is correct |
3 |
Correct |
19 ms |
98908 KB |
Output is correct |
4 |
Correct |
18 ms |
98908 KB |
Output is correct |
5 |
Correct |
18 ms |
98908 KB |
Output is correct |
6 |
Correct |
19 ms |
99108 KB |
Output is correct |
7 |
Correct |
20 ms |
98908 KB |
Output is correct |
8 |
Correct |
19 ms |
98844 KB |
Output is correct |
9 |
Correct |
19 ms |
98896 KB |
Output is correct |
10 |
Correct |
19 ms |
98904 KB |
Output is correct |
11 |
Correct |
20 ms |
99164 KB |
Output is correct |
12 |
Correct |
22 ms |
99184 KB |
Output is correct |
13 |
Correct |
22 ms |
99252 KB |
Output is correct |
14 |
Correct |
22 ms |
99288 KB |
Output is correct |
15 |
Correct |
22 ms |
99160 KB |
Output is correct |
16 |
Correct |
21 ms |
99164 KB |
Output is correct |
17 |
Correct |
21 ms |
99164 KB |
Output is correct |
18 |
Correct |
21 ms |
99164 KB |
Output is correct |
19 |
Correct |
542 ms |
92768 KB |
Output is correct |
20 |
Correct |
623 ms |
92404 KB |
Output is correct |
21 |
Correct |
590 ms |
92944 KB |
Output is correct |
22 |
Correct |
594 ms |
92580 KB |
Output is correct |
23 |
Correct |
610 ms |
92500 KB |
Output is correct |
24 |
Correct |
84 ms |
113236 KB |
Output is correct |
25 |
Correct |
104 ms |
114640 KB |
Output is correct |
26 |
Correct |
88 ms |
113920 KB |
Output is correct |
27 |
Correct |
73 ms |
114124 KB |
Output is correct |
28 |
Correct |
74 ms |
114032 KB |
Output is correct |
29 |
Correct |
61 ms |
113360 KB |
Output is correct |
30 |
Correct |
60 ms |
113396 KB |
Output is correct |
31 |
Correct |
71 ms |
113416 KB |
Output is correct |
32 |
Correct |
61 ms |
101896 KB |
Output is correct |
33 |
Correct |
93 ms |
113420 KB |
Output is correct |
34 |
Correct |
171 ms |
130132 KB |
Output is correct |
35 |
Correct |
171 ms |
129996 KB |
Output is correct |
36 |
Correct |
167 ms |
128852 KB |
Output is correct |
37 |
Correct |
150 ms |
128988 KB |
Output is correct |
38 |
Correct |
177 ms |
128944 KB |
Output is correct |
39 |
Correct |
121 ms |
126868 KB |
Output is correct |
40 |
Correct |
132 ms |
126944 KB |
Output is correct |
41 |
Correct |
137 ms |
127196 KB |
Output is correct |
42 |
Correct |
137 ms |
127304 KB |
Output is correct |
43 |
Correct |
133 ms |
127180 KB |
Output is correct |
44 |
Correct |
140 ms |
127828 KB |
Output is correct |
45 |
Correct |
144 ms |
127680 KB |
Output is correct |
46 |
Correct |
144 ms |
127688 KB |
Output is correct |
47 |
Correct |
146 ms |
127684 KB |
Output is correct |
48 |
Correct |
156 ms |
127560 KB |
Output is correct |
49 |
Correct |
116 ms |
126280 KB |
Output is correct |
50 |
Correct |
115 ms |
126088 KB |
Output is correct |
51 |
Correct |
118 ms |
126148 KB |
Output is correct |
52 |
Correct |
114 ms |
125896 KB |
Output is correct |
53 |
Correct |
113 ms |
126152 KB |
Output is correct |
54 |
Correct |
131 ms |
126220 KB |
Output is correct |
55 |
Correct |
106 ms |
120324 KB |
Output is correct |
56 |
Correct |
133 ms |
125352 KB |
Output is correct |
57 |
Execution timed out |
3061 ms |
262144 KB |
Time limit exceeded |
58 |
Halted |
0 ms |
0 KB |
- |