#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (int)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 1e6 + 100;
ll w[N];
vector <pair <ll, ll>> save[N];
vector <vector <ll>> ask[N];
ll seg[N * 4];
void upd(int id, int l, int r, int p, ll x) {
if (l > p || r < p)
return;
if (l == r) {
seg[id] = x;
return;
}
int m = (l + r) / 2;
upd(id * 2, l, m, p, x);
upd(id * 2 + 1, m + 1, r, p, x);
seg[id] = max(seg[id * 2], seg[id * 2 + 1]);
}
ll get(int id, int l, int r, int u, int v) {
if (l > v || r < u)
return 0;
if (l >= u && r <= v)
return seg[id];
int m = (l + r) / 2;
return max(get(id * 2, l, m, u, v), get(id * 2 + 1, m + 1, r, u, v));
}
int ans[N];
ll solve() {
int n, m;
cin >> n >> m;
vector <pair <int, int>> st;
for (int i = 1; i <= n; i++) {
int x;
cin >> x;
st.pb({x, i});
w[i] = x;
}
sort(all(st), greater <pair <int, int>> ());
set <int> pos;
int j = 0;
for (int i = 0; i < n; i++) {
int v = st[i].s;
while (st[j].f > st[i].f) {
pos.insert(st[j].s);
j++;
}
auto it = pos.lower_bound(v);
if (it != pos.begin()) {
it = prev(it);
save[*it].pb({v, w[v] + w[*it]});
}
}
for (int i = 1; i <= m; i++) {
int l, r, k;
cin >> l >> r >> k;
ask[l].pb({r, k, i});
}
for (int i = n; i >= 1; i--) {
for (auto x : save[i]) {
upd(1, 1, n, x.f, x.s);
}
for (auto x : ask[i]) {
if (get(1, 1, n, i, x[0]) <= x[1]) {
ans[x[2]] = 1;
}
}
}
for (int i = 1; i <= m; i++)
cout << ans[i] << '\n';
return 0;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t = 1;
//cin >> t;
while (t--) {
solve();
//cout << solve() << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
49500 KB |
Output is correct |
2 |
Correct |
10 ms |
47452 KB |
Output is correct |
3 |
Correct |
11 ms |
49756 KB |
Output is correct |
4 |
Correct |
11 ms |
49500 KB |
Output is correct |
5 |
Correct |
12 ms |
49704 KB |
Output is correct |
6 |
Correct |
12 ms |
49800 KB |
Output is correct |
7 |
Correct |
12 ms |
49752 KB |
Output is correct |
8 |
Correct |
11 ms |
47704 KB |
Output is correct |
9 |
Correct |
11 ms |
47708 KB |
Output is correct |
10 |
Correct |
11 ms |
47708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
49500 KB |
Output is correct |
2 |
Correct |
10 ms |
47452 KB |
Output is correct |
3 |
Correct |
11 ms |
49756 KB |
Output is correct |
4 |
Correct |
11 ms |
49500 KB |
Output is correct |
5 |
Correct |
12 ms |
49704 KB |
Output is correct |
6 |
Correct |
12 ms |
49800 KB |
Output is correct |
7 |
Correct |
12 ms |
49752 KB |
Output is correct |
8 |
Correct |
11 ms |
47704 KB |
Output is correct |
9 |
Correct |
11 ms |
47708 KB |
Output is correct |
10 |
Correct |
11 ms |
47708 KB |
Output is correct |
11 |
Correct |
13 ms |
49876 KB |
Output is correct |
12 |
Correct |
16 ms |
50264 KB |
Output is correct |
13 |
Correct |
15 ms |
50268 KB |
Output is correct |
14 |
Correct |
17 ms |
50524 KB |
Output is correct |
15 |
Correct |
19 ms |
50392 KB |
Output is correct |
16 |
Correct |
16 ms |
48476 KB |
Output is correct |
17 |
Correct |
14 ms |
48220 KB |
Output is correct |
18 |
Correct |
14 ms |
48128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2755 ms |
254024 KB |
Output is correct |
2 |
Correct |
2719 ms |
254948 KB |
Output is correct |
3 |
Correct |
2770 ms |
255328 KB |
Output is correct |
4 |
Correct |
2753 ms |
254952 KB |
Output is correct |
5 |
Correct |
1477 ms |
213012 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
164 ms |
72144 KB |
Output is correct |
2 |
Correct |
155 ms |
72544 KB |
Output is correct |
3 |
Correct |
133 ms |
65820 KB |
Output is correct |
4 |
Correct |
112 ms |
65828 KB |
Output is correct |
5 |
Correct |
107 ms |
65756 KB |
Output is correct |
6 |
Correct |
100 ms |
67524 KB |
Output is correct |
7 |
Correct |
95 ms |
67676 KB |
Output is correct |
8 |
Correct |
96 ms |
63944 KB |
Output is correct |
9 |
Correct |
47 ms |
57376 KB |
Output is correct |
10 |
Correct |
96 ms |
63292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
49500 KB |
Output is correct |
2 |
Correct |
10 ms |
47452 KB |
Output is correct |
3 |
Correct |
11 ms |
49756 KB |
Output is correct |
4 |
Correct |
11 ms |
49500 KB |
Output is correct |
5 |
Correct |
12 ms |
49704 KB |
Output is correct |
6 |
Correct |
12 ms |
49800 KB |
Output is correct |
7 |
Correct |
12 ms |
49752 KB |
Output is correct |
8 |
Correct |
11 ms |
47704 KB |
Output is correct |
9 |
Correct |
11 ms |
47708 KB |
Output is correct |
10 |
Correct |
11 ms |
47708 KB |
Output is correct |
11 |
Correct |
13 ms |
49876 KB |
Output is correct |
12 |
Correct |
16 ms |
50264 KB |
Output is correct |
13 |
Correct |
15 ms |
50268 KB |
Output is correct |
14 |
Correct |
17 ms |
50524 KB |
Output is correct |
15 |
Correct |
19 ms |
50392 KB |
Output is correct |
16 |
Correct |
16 ms |
48476 KB |
Output is correct |
17 |
Correct |
14 ms |
48220 KB |
Output is correct |
18 |
Correct |
14 ms |
48128 KB |
Output is correct |
19 |
Correct |
419 ms |
93412 KB |
Output is correct |
20 |
Correct |
383 ms |
93636 KB |
Output is correct |
21 |
Correct |
328 ms |
94016 KB |
Output is correct |
22 |
Correct |
343 ms |
94080 KB |
Output is correct |
23 |
Correct |
386 ms |
94088 KB |
Output is correct |
24 |
Correct |
221 ms |
82888 KB |
Output is correct |
25 |
Correct |
222 ms |
82800 KB |
Output is correct |
26 |
Correct |
248 ms |
82632 KB |
Output is correct |
27 |
Correct |
239 ms |
82608 KB |
Output is correct |
28 |
Correct |
274 ms |
82632 KB |
Output is correct |
29 |
Correct |
247 ms |
82460 KB |
Output is correct |
30 |
Correct |
271 ms |
82376 KB |
Output is correct |
31 |
Correct |
241 ms |
82632 KB |
Output is correct |
32 |
Correct |
257 ms |
82576 KB |
Output is correct |
33 |
Correct |
241 ms |
82460 KB |
Output is correct |
34 |
Correct |
224 ms |
88008 KB |
Output is correct |
35 |
Correct |
205 ms |
88000 KB |
Output is correct |
36 |
Correct |
236 ms |
87828 KB |
Output is correct |
37 |
Correct |
206 ms |
87824 KB |
Output is correct |
38 |
Correct |
206 ms |
87964 KB |
Output is correct |
39 |
Correct |
245 ms |
83788 KB |
Output is correct |
40 |
Correct |
180 ms |
76764 KB |
Output is correct |
41 |
Correct |
230 ms |
77168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
49500 KB |
Output is correct |
2 |
Correct |
10 ms |
47452 KB |
Output is correct |
3 |
Correct |
11 ms |
49756 KB |
Output is correct |
4 |
Correct |
11 ms |
49500 KB |
Output is correct |
5 |
Correct |
12 ms |
49704 KB |
Output is correct |
6 |
Correct |
12 ms |
49800 KB |
Output is correct |
7 |
Correct |
12 ms |
49752 KB |
Output is correct |
8 |
Correct |
11 ms |
47704 KB |
Output is correct |
9 |
Correct |
11 ms |
47708 KB |
Output is correct |
10 |
Correct |
11 ms |
47708 KB |
Output is correct |
11 |
Correct |
13 ms |
49876 KB |
Output is correct |
12 |
Correct |
16 ms |
50264 KB |
Output is correct |
13 |
Correct |
15 ms |
50268 KB |
Output is correct |
14 |
Correct |
17 ms |
50524 KB |
Output is correct |
15 |
Correct |
19 ms |
50392 KB |
Output is correct |
16 |
Correct |
16 ms |
48476 KB |
Output is correct |
17 |
Correct |
14 ms |
48220 KB |
Output is correct |
18 |
Correct |
14 ms |
48128 KB |
Output is correct |
19 |
Correct |
2755 ms |
254024 KB |
Output is correct |
20 |
Correct |
2719 ms |
254948 KB |
Output is correct |
21 |
Correct |
2770 ms |
255328 KB |
Output is correct |
22 |
Correct |
2753 ms |
254952 KB |
Output is correct |
23 |
Correct |
1477 ms |
213012 KB |
Output is correct |
24 |
Correct |
164 ms |
72144 KB |
Output is correct |
25 |
Correct |
155 ms |
72544 KB |
Output is correct |
26 |
Correct |
133 ms |
65820 KB |
Output is correct |
27 |
Correct |
112 ms |
65828 KB |
Output is correct |
28 |
Correct |
107 ms |
65756 KB |
Output is correct |
29 |
Correct |
100 ms |
67524 KB |
Output is correct |
30 |
Correct |
95 ms |
67676 KB |
Output is correct |
31 |
Correct |
96 ms |
63944 KB |
Output is correct |
32 |
Correct |
47 ms |
57376 KB |
Output is correct |
33 |
Correct |
96 ms |
63292 KB |
Output is correct |
34 |
Correct |
419 ms |
93412 KB |
Output is correct |
35 |
Correct |
383 ms |
93636 KB |
Output is correct |
36 |
Correct |
328 ms |
94016 KB |
Output is correct |
37 |
Correct |
343 ms |
94080 KB |
Output is correct |
38 |
Correct |
386 ms |
94088 KB |
Output is correct |
39 |
Correct |
221 ms |
82888 KB |
Output is correct |
40 |
Correct |
222 ms |
82800 KB |
Output is correct |
41 |
Correct |
248 ms |
82632 KB |
Output is correct |
42 |
Correct |
239 ms |
82608 KB |
Output is correct |
43 |
Correct |
274 ms |
82632 KB |
Output is correct |
44 |
Correct |
247 ms |
82460 KB |
Output is correct |
45 |
Correct |
271 ms |
82376 KB |
Output is correct |
46 |
Correct |
241 ms |
82632 KB |
Output is correct |
47 |
Correct |
257 ms |
82576 KB |
Output is correct |
48 |
Correct |
241 ms |
82460 KB |
Output is correct |
49 |
Correct |
224 ms |
88008 KB |
Output is correct |
50 |
Correct |
205 ms |
88000 KB |
Output is correct |
51 |
Correct |
236 ms |
87828 KB |
Output is correct |
52 |
Correct |
206 ms |
87824 KB |
Output is correct |
53 |
Correct |
206 ms |
87964 KB |
Output is correct |
54 |
Correct |
245 ms |
83788 KB |
Output is correct |
55 |
Correct |
180 ms |
76764 KB |
Output is correct |
56 |
Correct |
230 ms |
77168 KB |
Output is correct |
57 |
Correct |
2820 ms |
255588 KB |
Output is correct |
58 |
Correct |
2697 ms |
255100 KB |
Output is correct |
59 |
Correct |
2708 ms |
256288 KB |
Output is correct |
60 |
Correct |
2666 ms |
256100 KB |
Output is correct |
61 |
Correct |
2631 ms |
256324 KB |
Output is correct |
62 |
Correct |
2684 ms |
256412 KB |
Output is correct |
63 |
Correct |
1369 ms |
209732 KB |
Output is correct |
64 |
Correct |
1433 ms |
209920 KB |
Output is correct |
65 |
Correct |
1571 ms |
214008 KB |
Output is correct |
66 |
Correct |
1488 ms |
214040 KB |
Output is correct |
67 |
Correct |
1483 ms |
213716 KB |
Output is correct |
68 |
Correct |
1579 ms |
213412 KB |
Output is correct |
69 |
Correct |
1558 ms |
213624 KB |
Output is correct |
70 |
Correct |
1538 ms |
213464 KB |
Output is correct |
71 |
Correct |
1545 ms |
213168 KB |
Output is correct |
72 |
Correct |
1533 ms |
213692 KB |
Output is correct |
73 |
Correct |
1202 ms |
214508 KB |
Output is correct |
74 |
Correct |
1228 ms |
214900 KB |
Output is correct |
75 |
Correct |
1229 ms |
213992 KB |
Output is correct |
76 |
Correct |
1166 ms |
213900 KB |
Output is correct |
77 |
Correct |
1227 ms |
214428 KB |
Output is correct |
78 |
Correct |
1750 ms |
220644 KB |
Output is correct |
79 |
Correct |
1108 ms |
173004 KB |
Output is correct |
80 |
Correct |
1350 ms |
185404 KB |
Output is correct |