#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
#define LINE "----------------------\n"
#define ALL(x) x.begin(),x.end()
using namespace std;
using ll = long long;
using PII = pair <int, int>;
using VI = vector <int>;
using VVI = vector <VI>;
using VPI = vector <PII>;
const int N = 1e6 + 5;
const int M = 4 * N;
const int INF = 1e9+1;
int nums[N], ans[N], node[M];
int n, m;
struct Query {
int l, r, k, id;
Query () {}
Query (int _l, int _r, int _k, int _id) {
l = _l;
r = _r;
k = _k;
id = _id;
}
void init (int _l, int _r, int _k, int _id) {
l = _l;
r = _r;
k = _k;
id = _id;
}
bool operator < (const Query& a) const {
return r < a.r;
}
};
void update(int l, int r, int id, int val, int head) {
if (l == r) {
node[head] = val;
return;
}
int mid = (l+r)>>1;
if (id <= mid) update(l, mid, id, val, head*2+1);
else update(mid+1, r, id, val, head*2+2);
node[head] = max(node[head*2+1], node[head*2+2]);
}
int query(int l, int r, int L, int R, int head) {
if (l > R || L > r) return -1;
if (L <= l && r <= R) return node[head];
int mid = (l+r)>>1;
return max(
query(l, mid, L, R, head*2+1),
query(mid+1, r, L, R, head*2+2)
);
}
signed main() {
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
cin >> n >> m;
nums[0] = 1e9+1;
for (int i = 1; i <= n; i++) cin >> nums[i];
vector <Query> queries;
Query tmp;
for (int i = 1; i <= m; i++) {
int l, r, k; cin >> l >> r >> k;
tmp.init(l, r, k, i);
queries.pb(tmp);
}
sort(ALL(queries));
stack <int> stk;
stk.push(0);
memset(node, -1, sizeof(node));
for (int i = 1, j = 0; i <= n && j < m; i++) {
while (nums[i] >= nums[stk.top()]) stk.pop();
if (stk.size() > 1) update(1, n, stk.top(), nums[stk.top()]+nums[i], 0);
stk.push(i);
while (queries[j].r == i) {
ans[queries[j].id] = (query(1, n, queries[j].l, queries[j].r, 0) > queries[j].k ? 0 : 1);
// cout << "add: " << queries[j].l << ' ' << queries[j].r << ' ' << query(1, n, queries[j].l, queries[j].r, 0) << '\n';
j++;
}
}
for (int i = 1; i <= m; i++) cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15916 KB |
Output is correct |
2 |
Correct |
8 ms |
15920 KB |
Output is correct |
3 |
Correct |
6 ms |
15948 KB |
Output is correct |
4 |
Correct |
6 ms |
15948 KB |
Output is correct |
5 |
Correct |
6 ms |
15948 KB |
Output is correct |
6 |
Correct |
8 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15948 KB |
Output is correct |
8 |
Correct |
7 ms |
15948 KB |
Output is correct |
9 |
Correct |
6 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15916 KB |
Output is correct |
2 |
Correct |
8 ms |
15920 KB |
Output is correct |
3 |
Correct |
6 ms |
15948 KB |
Output is correct |
4 |
Correct |
6 ms |
15948 KB |
Output is correct |
5 |
Correct |
6 ms |
15948 KB |
Output is correct |
6 |
Correct |
8 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15948 KB |
Output is correct |
8 |
Correct |
7 ms |
15948 KB |
Output is correct |
9 |
Correct |
6 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15928 KB |
Output is correct |
11 |
Correct |
9 ms |
16112 KB |
Output is correct |
12 |
Correct |
10 ms |
16188 KB |
Output is correct |
13 |
Correct |
9 ms |
16204 KB |
Output is correct |
14 |
Correct |
10 ms |
16384 KB |
Output is correct |
15 |
Correct |
11 ms |
16380 KB |
Output is correct |
16 |
Correct |
9 ms |
16264 KB |
Output is correct |
17 |
Correct |
9 ms |
16228 KB |
Output is correct |
18 |
Correct |
9 ms |
16212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1084 ms |
55252 KB |
Output is correct |
2 |
Correct |
1106 ms |
55568 KB |
Output is correct |
3 |
Correct |
1092 ms |
55572 KB |
Output is correct |
4 |
Correct |
1026 ms |
55504 KB |
Output is correct |
5 |
Correct |
964 ms |
55508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
20664 KB |
Output is correct |
2 |
Correct |
81 ms |
20552 KB |
Output is correct |
3 |
Correct |
73 ms |
20536 KB |
Output is correct |
4 |
Correct |
90 ms |
20532 KB |
Output is correct |
5 |
Correct |
78 ms |
20620 KB |
Output is correct |
6 |
Correct |
69 ms |
20492 KB |
Output is correct |
7 |
Correct |
71 ms |
20468 KB |
Output is correct |
8 |
Correct |
88 ms |
20324 KB |
Output is correct |
9 |
Correct |
49 ms |
19636 KB |
Output is correct |
10 |
Correct |
68 ms |
20260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15916 KB |
Output is correct |
2 |
Correct |
8 ms |
15920 KB |
Output is correct |
3 |
Correct |
6 ms |
15948 KB |
Output is correct |
4 |
Correct |
6 ms |
15948 KB |
Output is correct |
5 |
Correct |
6 ms |
15948 KB |
Output is correct |
6 |
Correct |
8 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15948 KB |
Output is correct |
8 |
Correct |
7 ms |
15948 KB |
Output is correct |
9 |
Correct |
6 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15928 KB |
Output is correct |
11 |
Correct |
9 ms |
16112 KB |
Output is correct |
12 |
Correct |
10 ms |
16188 KB |
Output is correct |
13 |
Correct |
9 ms |
16204 KB |
Output is correct |
14 |
Correct |
10 ms |
16384 KB |
Output is correct |
15 |
Correct |
11 ms |
16380 KB |
Output is correct |
16 |
Correct |
9 ms |
16264 KB |
Output is correct |
17 |
Correct |
9 ms |
16228 KB |
Output is correct |
18 |
Correct |
9 ms |
16212 KB |
Output is correct |
19 |
Correct |
217 ms |
24724 KB |
Output is correct |
20 |
Correct |
216 ms |
24644 KB |
Output is correct |
21 |
Correct |
203 ms |
24656 KB |
Output is correct |
22 |
Correct |
194 ms |
24736 KB |
Output is correct |
23 |
Correct |
197 ms |
24852 KB |
Output is correct |
24 |
Correct |
172 ms |
24700 KB |
Output is correct |
25 |
Correct |
166 ms |
24824 KB |
Output is correct |
26 |
Correct |
176 ms |
24700 KB |
Output is correct |
27 |
Correct |
225 ms |
24684 KB |
Output is correct |
28 |
Correct |
173 ms |
24660 KB |
Output is correct |
29 |
Correct |
178 ms |
24724 KB |
Output is correct |
30 |
Correct |
177 ms |
24804 KB |
Output is correct |
31 |
Correct |
179 ms |
24660 KB |
Output is correct |
32 |
Correct |
177 ms |
24484 KB |
Output is correct |
33 |
Correct |
172 ms |
24372 KB |
Output is correct |
34 |
Correct |
161 ms |
24124 KB |
Output is correct |
35 |
Correct |
166 ms |
23992 KB |
Output is correct |
36 |
Correct |
154 ms |
24128 KB |
Output is correct |
37 |
Correct |
148 ms |
23808 KB |
Output is correct |
38 |
Correct |
161 ms |
23760 KB |
Output is correct |
39 |
Correct |
152 ms |
23548 KB |
Output is correct |
40 |
Correct |
130 ms |
23368 KB |
Output is correct |
41 |
Correct |
150 ms |
23368 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
15916 KB |
Output is correct |
2 |
Correct |
8 ms |
15920 KB |
Output is correct |
3 |
Correct |
6 ms |
15948 KB |
Output is correct |
4 |
Correct |
6 ms |
15948 KB |
Output is correct |
5 |
Correct |
6 ms |
15948 KB |
Output is correct |
6 |
Correct |
8 ms |
15948 KB |
Output is correct |
7 |
Correct |
7 ms |
15948 KB |
Output is correct |
8 |
Correct |
7 ms |
15948 KB |
Output is correct |
9 |
Correct |
6 ms |
15948 KB |
Output is correct |
10 |
Correct |
8 ms |
15928 KB |
Output is correct |
11 |
Correct |
9 ms |
16112 KB |
Output is correct |
12 |
Correct |
10 ms |
16188 KB |
Output is correct |
13 |
Correct |
9 ms |
16204 KB |
Output is correct |
14 |
Correct |
10 ms |
16384 KB |
Output is correct |
15 |
Correct |
11 ms |
16380 KB |
Output is correct |
16 |
Correct |
9 ms |
16264 KB |
Output is correct |
17 |
Correct |
9 ms |
16228 KB |
Output is correct |
18 |
Correct |
9 ms |
16212 KB |
Output is correct |
19 |
Correct |
1084 ms |
55252 KB |
Output is correct |
20 |
Correct |
1106 ms |
55568 KB |
Output is correct |
21 |
Correct |
1092 ms |
55572 KB |
Output is correct |
22 |
Correct |
1026 ms |
55504 KB |
Output is correct |
23 |
Correct |
964 ms |
55508 KB |
Output is correct |
24 |
Correct |
87 ms |
20664 KB |
Output is correct |
25 |
Correct |
81 ms |
20552 KB |
Output is correct |
26 |
Correct |
73 ms |
20536 KB |
Output is correct |
27 |
Correct |
90 ms |
20532 KB |
Output is correct |
28 |
Correct |
78 ms |
20620 KB |
Output is correct |
29 |
Correct |
69 ms |
20492 KB |
Output is correct |
30 |
Correct |
71 ms |
20468 KB |
Output is correct |
31 |
Correct |
88 ms |
20324 KB |
Output is correct |
32 |
Correct |
49 ms |
19636 KB |
Output is correct |
33 |
Correct |
68 ms |
20260 KB |
Output is correct |
34 |
Correct |
217 ms |
24724 KB |
Output is correct |
35 |
Correct |
216 ms |
24644 KB |
Output is correct |
36 |
Correct |
203 ms |
24656 KB |
Output is correct |
37 |
Correct |
194 ms |
24736 KB |
Output is correct |
38 |
Correct |
197 ms |
24852 KB |
Output is correct |
39 |
Correct |
172 ms |
24700 KB |
Output is correct |
40 |
Correct |
166 ms |
24824 KB |
Output is correct |
41 |
Correct |
176 ms |
24700 KB |
Output is correct |
42 |
Correct |
225 ms |
24684 KB |
Output is correct |
43 |
Correct |
173 ms |
24660 KB |
Output is correct |
44 |
Correct |
178 ms |
24724 KB |
Output is correct |
45 |
Correct |
177 ms |
24804 KB |
Output is correct |
46 |
Correct |
179 ms |
24660 KB |
Output is correct |
47 |
Correct |
177 ms |
24484 KB |
Output is correct |
48 |
Correct |
172 ms |
24372 KB |
Output is correct |
49 |
Correct |
161 ms |
24124 KB |
Output is correct |
50 |
Correct |
166 ms |
23992 KB |
Output is correct |
51 |
Correct |
154 ms |
24128 KB |
Output is correct |
52 |
Correct |
148 ms |
23808 KB |
Output is correct |
53 |
Correct |
161 ms |
23760 KB |
Output is correct |
54 |
Correct |
152 ms |
23548 KB |
Output is correct |
55 |
Correct |
130 ms |
23368 KB |
Output is correct |
56 |
Correct |
150 ms |
23368 KB |
Output is correct |
57 |
Correct |
1157 ms |
75048 KB |
Output is correct |
58 |
Correct |
1124 ms |
75068 KB |
Output is correct |
59 |
Correct |
1108 ms |
74936 KB |
Output is correct |
60 |
Correct |
1079 ms |
75116 KB |
Output is correct |
61 |
Correct |
1106 ms |
74968 KB |
Output is correct |
62 |
Correct |
1035 ms |
75124 KB |
Output is correct |
63 |
Correct |
784 ms |
73192 KB |
Output is correct |
64 |
Correct |
860 ms |
73140 KB |
Output is correct |
65 |
Correct |
934 ms |
74932 KB |
Output is correct |
66 |
Correct |
978 ms |
74940 KB |
Output is correct |
67 |
Correct |
949 ms |
57800 KB |
Output is correct |
68 |
Correct |
923 ms |
75240 KB |
Output is correct |
69 |
Correct |
916 ms |
75160 KB |
Output is correct |
70 |
Correct |
913 ms |
75164 KB |
Output is correct |
71 |
Correct |
916 ms |
75232 KB |
Output is correct |
72 |
Correct |
920 ms |
75016 KB |
Output is correct |
73 |
Correct |
746 ms |
71620 KB |
Output is correct |
74 |
Correct |
776 ms |
72592 KB |
Output is correct |
75 |
Correct |
742 ms |
71632 KB |
Output is correct |
76 |
Correct |
753 ms |
71572 KB |
Output is correct |
77 |
Correct |
745 ms |
71620 KB |
Output is correct |
78 |
Correct |
795 ms |
68888 KB |
Output is correct |
79 |
Correct |
605 ms |
62292 KB |
Output is correct |
80 |
Correct |
793 ms |
66160 KB |
Output is correct |