#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define pb push_back
#define all(a) a.begin(), a.end()
#define int long long
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const int N = 1e6 + 99;
int w[N], k[N], a[N], t[N * 4], ans[N];
vi cur[N];
vpii v[N];
void build(int v, int l, int r)
{
if (l == r) {
t[v] = a[l];
return;
}
int V = v << 1LL, mid = (l + r) >> 1LL;
build(V, l, mid);
build(V + 1, mid + 1, r);
t[v] = max(t[V], t[V + 1]);
}
void upd(int v, int l, int r, int pos, int val)
{
if (l == r) {
t[v] = val;
return;
}
int V = v << 1LL, mid = (l + r) >> 1LL;
if (pos <= mid) {
upd(V, l, mid, pos, val);
}
else {
upd(V + 1, mid + 1, r, pos, val);
}
t[v] = max(t[V], t[V + 1]);
}
int get(int v, int l, int r, int L, int R)
{
if (l == L && r == R) {
return t[v];
}
int V = v << 1LL, mid = (l + r) >> 1LL;
if (R <= mid) {
return get(V, l, mid, L, R);
}
if (L > mid) {
return get(V + 1, mid + 1, r, L, R);
}
return max(get(V, l, mid, L, mid), get(V + 1, mid + 1, r, mid + 1, R));
}
signed main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, m;
cin >> n >> m;
for (int i = 1; i <= n; ++i) {
cin >> w[i];
}
vpii st;
st.pb({ w[1], 1 });
a[1] = -1;
for (int i = 2; i <= n; ++i) {
while (!st.empty() && st.back().x <= w[i]) {
st.pop_back();
}
if (!st.size()) {
a[i] = -1;
}
else {
a[i] = st.back().x + w[i];
cur[st.back().y].pb(i);
}
st.pb({ w[i], i });
}
build(1, 1, n);
for (int i = 1; i <= m; ++i) {
int l, r;
cin >> l >> r >> k[i];
v[l].pb({ r, i });
}
for (int l = 1; l <= n; ++l) {
for (auto[r, i] : v[l]) {
if (get(1, 1, n, l, r) <= k[i]) {
ans[i] = 1;
}
}
for (int pos : cur[l]) {
upd(1, 1, n, pos, -1);
}
}
for (int i = 1; i <= m; ++i) {
cout << ans[i] << "\n";
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
47300 KB |
Output is correct |
2 |
Correct |
23 ms |
47248 KB |
Output is correct |
3 |
Correct |
26 ms |
47312 KB |
Output is correct |
4 |
Correct |
23 ms |
47292 KB |
Output is correct |
5 |
Correct |
26 ms |
47240 KB |
Output is correct |
6 |
Correct |
24 ms |
47308 KB |
Output is correct |
7 |
Correct |
24 ms |
47304 KB |
Output is correct |
8 |
Correct |
25 ms |
47300 KB |
Output is correct |
9 |
Correct |
24 ms |
47308 KB |
Output is correct |
10 |
Correct |
25 ms |
47300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
47300 KB |
Output is correct |
2 |
Correct |
23 ms |
47248 KB |
Output is correct |
3 |
Correct |
26 ms |
47312 KB |
Output is correct |
4 |
Correct |
23 ms |
47292 KB |
Output is correct |
5 |
Correct |
26 ms |
47240 KB |
Output is correct |
6 |
Correct |
24 ms |
47308 KB |
Output is correct |
7 |
Correct |
24 ms |
47304 KB |
Output is correct |
8 |
Correct |
25 ms |
47300 KB |
Output is correct |
9 |
Correct |
24 ms |
47308 KB |
Output is correct |
10 |
Correct |
25 ms |
47300 KB |
Output is correct |
11 |
Correct |
25 ms |
47580 KB |
Output is correct |
12 |
Correct |
26 ms |
47776 KB |
Output is correct |
13 |
Correct |
27 ms |
47948 KB |
Output is correct |
14 |
Correct |
29 ms |
47948 KB |
Output is correct |
15 |
Correct |
28 ms |
47872 KB |
Output is correct |
16 |
Correct |
28 ms |
47820 KB |
Output is correct |
17 |
Correct |
27 ms |
47732 KB |
Output is correct |
18 |
Correct |
29 ms |
47812 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1299 ms |
140008 KB |
Output is correct |
2 |
Correct |
1343 ms |
140212 KB |
Output is correct |
3 |
Correct |
1282 ms |
136128 KB |
Output is correct |
4 |
Correct |
1290 ms |
136324 KB |
Output is correct |
5 |
Correct |
1115 ms |
131080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
59216 KB |
Output is correct |
2 |
Correct |
112 ms |
59076 KB |
Output is correct |
3 |
Correct |
100 ms |
57304 KB |
Output is correct |
4 |
Correct |
100 ms |
57288 KB |
Output is correct |
5 |
Correct |
94 ms |
57264 KB |
Output is correct |
6 |
Correct |
86 ms |
55992 KB |
Output is correct |
7 |
Correct |
87 ms |
56120 KB |
Output is correct |
8 |
Correct |
93 ms |
57132 KB |
Output is correct |
9 |
Correct |
57 ms |
52392 KB |
Output is correct |
10 |
Correct |
92 ms |
57084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
47300 KB |
Output is correct |
2 |
Correct |
23 ms |
47248 KB |
Output is correct |
3 |
Correct |
26 ms |
47312 KB |
Output is correct |
4 |
Correct |
23 ms |
47292 KB |
Output is correct |
5 |
Correct |
26 ms |
47240 KB |
Output is correct |
6 |
Correct |
24 ms |
47308 KB |
Output is correct |
7 |
Correct |
24 ms |
47304 KB |
Output is correct |
8 |
Correct |
25 ms |
47300 KB |
Output is correct |
9 |
Correct |
24 ms |
47308 KB |
Output is correct |
10 |
Correct |
25 ms |
47300 KB |
Output is correct |
11 |
Correct |
25 ms |
47580 KB |
Output is correct |
12 |
Correct |
26 ms |
47776 KB |
Output is correct |
13 |
Correct |
27 ms |
47948 KB |
Output is correct |
14 |
Correct |
29 ms |
47948 KB |
Output is correct |
15 |
Correct |
28 ms |
47872 KB |
Output is correct |
16 |
Correct |
28 ms |
47820 KB |
Output is correct |
17 |
Correct |
27 ms |
47732 KB |
Output is correct |
18 |
Correct |
29 ms |
47812 KB |
Output is correct |
19 |
Correct |
239 ms |
73732 KB |
Output is correct |
20 |
Correct |
242 ms |
73668 KB |
Output is correct |
21 |
Correct |
217 ms |
73532 KB |
Output is correct |
22 |
Correct |
218 ms |
73512 KB |
Output is correct |
23 |
Correct |
218 ms |
73476 KB |
Output is correct |
24 |
Correct |
177 ms |
69564 KB |
Output is correct |
25 |
Correct |
174 ms |
69668 KB |
Output is correct |
26 |
Correct |
207 ms |
69892 KB |
Output is correct |
27 |
Correct |
201 ms |
69920 KB |
Output is correct |
28 |
Correct |
205 ms |
69796 KB |
Output is correct |
29 |
Correct |
208 ms |
70084 KB |
Output is correct |
30 |
Correct |
209 ms |
69976 KB |
Output is correct |
31 |
Correct |
206 ms |
69956 KB |
Output is correct |
32 |
Correct |
213 ms |
70060 KB |
Output is correct |
33 |
Correct |
207 ms |
69956 KB |
Output is correct |
34 |
Correct |
166 ms |
68744 KB |
Output is correct |
35 |
Correct |
170 ms |
68720 KB |
Output is correct |
36 |
Correct |
172 ms |
68504 KB |
Output is correct |
37 |
Correct |
163 ms |
68428 KB |
Output is correct |
38 |
Correct |
169 ms |
68872 KB |
Output is correct |
39 |
Correct |
185 ms |
69092 KB |
Output is correct |
40 |
Correct |
145 ms |
63796 KB |
Output is correct |
41 |
Correct |
182 ms |
68212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
47300 KB |
Output is correct |
2 |
Correct |
23 ms |
47248 KB |
Output is correct |
3 |
Correct |
26 ms |
47312 KB |
Output is correct |
4 |
Correct |
23 ms |
47292 KB |
Output is correct |
5 |
Correct |
26 ms |
47240 KB |
Output is correct |
6 |
Correct |
24 ms |
47308 KB |
Output is correct |
7 |
Correct |
24 ms |
47304 KB |
Output is correct |
8 |
Correct |
25 ms |
47300 KB |
Output is correct |
9 |
Correct |
24 ms |
47308 KB |
Output is correct |
10 |
Correct |
25 ms |
47300 KB |
Output is correct |
11 |
Correct |
25 ms |
47580 KB |
Output is correct |
12 |
Correct |
26 ms |
47776 KB |
Output is correct |
13 |
Correct |
27 ms |
47948 KB |
Output is correct |
14 |
Correct |
29 ms |
47948 KB |
Output is correct |
15 |
Correct |
28 ms |
47872 KB |
Output is correct |
16 |
Correct |
28 ms |
47820 KB |
Output is correct |
17 |
Correct |
27 ms |
47732 KB |
Output is correct |
18 |
Correct |
29 ms |
47812 KB |
Output is correct |
19 |
Correct |
1299 ms |
140008 KB |
Output is correct |
20 |
Correct |
1343 ms |
140212 KB |
Output is correct |
21 |
Correct |
1282 ms |
136128 KB |
Output is correct |
22 |
Correct |
1290 ms |
136324 KB |
Output is correct |
23 |
Correct |
1115 ms |
131080 KB |
Output is correct |
24 |
Correct |
113 ms |
59216 KB |
Output is correct |
25 |
Correct |
112 ms |
59076 KB |
Output is correct |
26 |
Correct |
100 ms |
57304 KB |
Output is correct |
27 |
Correct |
100 ms |
57288 KB |
Output is correct |
28 |
Correct |
94 ms |
57264 KB |
Output is correct |
29 |
Correct |
86 ms |
55992 KB |
Output is correct |
30 |
Correct |
87 ms |
56120 KB |
Output is correct |
31 |
Correct |
93 ms |
57132 KB |
Output is correct |
32 |
Correct |
57 ms |
52392 KB |
Output is correct |
33 |
Correct |
92 ms |
57084 KB |
Output is correct |
34 |
Correct |
239 ms |
73732 KB |
Output is correct |
35 |
Correct |
242 ms |
73668 KB |
Output is correct |
36 |
Correct |
217 ms |
73532 KB |
Output is correct |
37 |
Correct |
218 ms |
73512 KB |
Output is correct |
38 |
Correct |
218 ms |
73476 KB |
Output is correct |
39 |
Correct |
177 ms |
69564 KB |
Output is correct |
40 |
Correct |
174 ms |
69668 KB |
Output is correct |
41 |
Correct |
207 ms |
69892 KB |
Output is correct |
42 |
Correct |
201 ms |
69920 KB |
Output is correct |
43 |
Correct |
205 ms |
69796 KB |
Output is correct |
44 |
Correct |
208 ms |
70084 KB |
Output is correct |
45 |
Correct |
209 ms |
69976 KB |
Output is correct |
46 |
Correct |
206 ms |
69956 KB |
Output is correct |
47 |
Correct |
213 ms |
70060 KB |
Output is correct |
48 |
Correct |
207 ms |
69956 KB |
Output is correct |
49 |
Correct |
166 ms |
68744 KB |
Output is correct |
50 |
Correct |
170 ms |
68720 KB |
Output is correct |
51 |
Correct |
172 ms |
68504 KB |
Output is correct |
52 |
Correct |
163 ms |
68428 KB |
Output is correct |
53 |
Correct |
169 ms |
68872 KB |
Output is correct |
54 |
Correct |
185 ms |
69092 KB |
Output is correct |
55 |
Correct |
145 ms |
63796 KB |
Output is correct |
56 |
Correct |
182 ms |
68212 KB |
Output is correct |
57 |
Correct |
1327 ms |
149876 KB |
Output is correct |
58 |
Correct |
1311 ms |
149696 KB |
Output is correct |
59 |
Correct |
1284 ms |
149076 KB |
Output is correct |
60 |
Correct |
1275 ms |
149068 KB |
Output is correct |
61 |
Correct |
1310 ms |
149036 KB |
Output is correct |
62 |
Correct |
1271 ms |
149128 KB |
Output is correct |
63 |
Correct |
850 ms |
126192 KB |
Output is correct |
64 |
Correct |
840 ms |
125892 KB |
Output is correct |
65 |
Correct |
1090 ms |
130344 KB |
Output is correct |
66 |
Correct |
1093 ms |
130296 KB |
Output is correct |
67 |
Correct |
1073 ms |
130248 KB |
Output is correct |
68 |
Correct |
1107 ms |
130792 KB |
Output is correct |
69 |
Correct |
1094 ms |
130820 KB |
Output is correct |
70 |
Correct |
1098 ms |
130408 KB |
Output is correct |
71 |
Correct |
1102 ms |
130404 KB |
Output is correct |
72 |
Correct |
1106 ms |
130228 KB |
Output is correct |
73 |
Correct |
784 ms |
123892 KB |
Output is correct |
74 |
Correct |
816 ms |
124012 KB |
Output is correct |
75 |
Correct |
780 ms |
123968 KB |
Output is correct |
76 |
Correct |
784 ms |
123640 KB |
Output is correct |
77 |
Correct |
778 ms |
123460 KB |
Output is correct |
78 |
Correct |
982 ms |
131176 KB |
Output is correct |
79 |
Correct |
653 ms |
106916 KB |
Output is correct |
80 |
Correct |
951 ms |
129196 KB |
Output is correct |