#include <bits/stdc++.h>
#define sz(x) (int)((x).size())
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fr first
#define sc second
#define pw(x) (1ll << x)
#define bcnt(x) (__builtin_popcount(x))
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
template <typename T> inline bool umax (T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool umin (T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
const int inf = 2e9 + 127;
struct seg1 {
int n; vector <int> t;
seg1 (int n = 0) : n(n), t(4 * n, -inf) {}
inline void upd (int v, int tl, int tr, int pos, int x) {
if (tl == tr) return void(t[v] = x);
int tm = (tl + tr) >> 1;
if (pos <= tm) upd(v << 1, tl, tm, pos, x);
else upd(v << 1 | 1, tm + 1, tr, pos, x);
t[v] = max(t[v << 1], t[v << 1 | 1]);
}
inline int getp (int v, int tl, int tr, int x) {
if (t[v] < x) return -1;
if (tl == tr) return tl;
int tm = (tl + tr) >> 1;
if (t[v << 1 | 1] > x) return getp(v << 1 | 1, tm + 1, tr, x);
return getp(v << 1, tl, tm, x);
}
inline void upd (int pos, int x) { upd(1, 0, n - 1, pos, x); }
inline int getp (int x) { return getp(1, 0, n - 1, x); }
};
struct seg2 {
int n; vector <int> t;
seg2 (int n = 0) : n(n), t(4 * n) {}
inline void upd (int v, int tl, int tr, int pos, int x) {
if (tl == tr) return void(umax(t[v], x));
int tm = (tl + tr) >> 1;
if (pos <= tm) upd(v << 1, tl, tm, pos, x);
else upd(v << 1 | 1, tm + 1, tr, pos, x);
t[v] = max(t[v << 1], t[v << 1 | 1]);
}
inline int get (int v, int tl, int tr, int l, int r) {
if (tl > r || l > tr) return 0;
if (l <= tl && tr <= r) return t[v];
int tm = (tl + tr) >> 1;
return max(get(v << 1, tl, tm, l, r), get(v << 1 | 1, tm + 1, tr, l, r));
}
inline void upd (int pos, int x) { upd(1, 0, n - 1, pos, x); }
inline int get (int l, int r) { return get(1, 0, n - 1, l, r); }
};
inline void solve () {
int n, q; cin >> n >> q;
vector <int> a (n);
for (auto &i : a) cin >> i;
vector <vector <array <int, 3>>> qry (n);
for (int i = 0; i < q; ++i) {
int l, r, w; cin >> l >> r >> w; --l, --r;
qry[r].pb({l, w, i});
}
seg1 mx (n);
seg2 answ (n);
vector <bool> ans (q);
for (int r = 0; r < n; ++r) {
int pos = mx.getp(a[r]);
mx.upd(r, a[r]);
if (~pos) answ.upd(pos, a[pos] + a[r]);
for (auto [l, w, i] : qry[r]) ans[i] = (answ.get(l, r) <= w);
}
for (auto i : ans) cout << i << endl;
}
signed main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif // LOCAL
int t = 1; // cin >> t;
while (t--) solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
7 ms |
536 KB |
Output is correct |
12 |
Correct |
9 ms |
724 KB |
Output is correct |
13 |
Correct |
10 ms |
724 KB |
Output is correct |
14 |
Correct |
14 ms |
852 KB |
Output is correct |
15 |
Correct |
14 ms |
852 KB |
Output is correct |
16 |
Correct |
9 ms |
724 KB |
Output is correct |
17 |
Correct |
9 ms |
724 KB |
Output is correct |
18 |
Correct |
10 ms |
800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2771 ms |
114688 KB |
Output is correct |
2 |
Correct |
2621 ms |
115764 KB |
Output is correct |
3 |
Correct |
2493 ms |
115664 KB |
Output is correct |
4 |
Correct |
2812 ms |
115788 KB |
Output is correct |
5 |
Correct |
2368 ms |
115668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
10444 KB |
Output is correct |
2 |
Correct |
201 ms |
10240 KB |
Output is correct |
3 |
Correct |
196 ms |
10428 KB |
Output is correct |
4 |
Correct |
216 ms |
10476 KB |
Output is correct |
5 |
Correct |
236 ms |
10484 KB |
Output is correct |
6 |
Correct |
198 ms |
10028 KB |
Output is correct |
7 |
Correct |
179 ms |
9948 KB |
Output is correct |
8 |
Correct |
203 ms |
10008 KB |
Output is correct |
9 |
Correct |
189 ms |
3492 KB |
Output is correct |
10 |
Correct |
186 ms |
9928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
7 ms |
536 KB |
Output is correct |
12 |
Correct |
9 ms |
724 KB |
Output is correct |
13 |
Correct |
10 ms |
724 KB |
Output is correct |
14 |
Correct |
14 ms |
852 KB |
Output is correct |
15 |
Correct |
14 ms |
852 KB |
Output is correct |
16 |
Correct |
9 ms |
724 KB |
Output is correct |
17 |
Correct |
9 ms |
724 KB |
Output is correct |
18 |
Correct |
10 ms |
800 KB |
Output is correct |
19 |
Correct |
443 ms |
23248 KB |
Output is correct |
20 |
Correct |
519 ms |
23288 KB |
Output is correct |
21 |
Correct |
480 ms |
22668 KB |
Output is correct |
22 |
Correct |
440 ms |
22640 KB |
Output is correct |
23 |
Correct |
399 ms |
22684 KB |
Output is correct |
24 |
Correct |
417 ms |
22420 KB |
Output is correct |
25 |
Correct |
413 ms |
22464 KB |
Output is correct |
26 |
Correct |
431 ms |
22976 KB |
Output is correct |
27 |
Correct |
410 ms |
22860 KB |
Output is correct |
28 |
Correct |
446 ms |
22872 KB |
Output is correct |
29 |
Correct |
448 ms |
23280 KB |
Output is correct |
30 |
Correct |
425 ms |
23264 KB |
Output is correct |
31 |
Correct |
446 ms |
23176 KB |
Output is correct |
32 |
Correct |
434 ms |
23224 KB |
Output is correct |
33 |
Correct |
444 ms |
23292 KB |
Output is correct |
34 |
Correct |
406 ms |
22056 KB |
Output is correct |
35 |
Correct |
391 ms |
21940 KB |
Output is correct |
36 |
Correct |
425 ms |
21764 KB |
Output is correct |
37 |
Correct |
388 ms |
21900 KB |
Output is correct |
38 |
Correct |
403 ms |
21964 KB |
Output is correct |
39 |
Correct |
459 ms |
21564 KB |
Output is correct |
40 |
Correct |
367 ms |
16400 KB |
Output is correct |
41 |
Correct |
418 ms |
21096 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
2 ms |
324 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
324 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
340 KB |
Output is correct |
9 |
Correct |
2 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
340 KB |
Output is correct |
11 |
Correct |
7 ms |
536 KB |
Output is correct |
12 |
Correct |
9 ms |
724 KB |
Output is correct |
13 |
Correct |
10 ms |
724 KB |
Output is correct |
14 |
Correct |
14 ms |
852 KB |
Output is correct |
15 |
Correct |
14 ms |
852 KB |
Output is correct |
16 |
Correct |
9 ms |
724 KB |
Output is correct |
17 |
Correct |
9 ms |
724 KB |
Output is correct |
18 |
Correct |
10 ms |
800 KB |
Output is correct |
19 |
Correct |
2771 ms |
114688 KB |
Output is correct |
20 |
Correct |
2621 ms |
115764 KB |
Output is correct |
21 |
Correct |
2493 ms |
115664 KB |
Output is correct |
22 |
Correct |
2812 ms |
115788 KB |
Output is correct |
23 |
Correct |
2368 ms |
115668 KB |
Output is correct |
24 |
Correct |
206 ms |
10444 KB |
Output is correct |
25 |
Correct |
201 ms |
10240 KB |
Output is correct |
26 |
Correct |
196 ms |
10428 KB |
Output is correct |
27 |
Correct |
216 ms |
10476 KB |
Output is correct |
28 |
Correct |
236 ms |
10484 KB |
Output is correct |
29 |
Correct |
198 ms |
10028 KB |
Output is correct |
30 |
Correct |
179 ms |
9948 KB |
Output is correct |
31 |
Correct |
203 ms |
10008 KB |
Output is correct |
32 |
Correct |
189 ms |
3492 KB |
Output is correct |
33 |
Correct |
186 ms |
9928 KB |
Output is correct |
34 |
Correct |
443 ms |
23248 KB |
Output is correct |
35 |
Correct |
519 ms |
23288 KB |
Output is correct |
36 |
Correct |
480 ms |
22668 KB |
Output is correct |
37 |
Correct |
440 ms |
22640 KB |
Output is correct |
38 |
Correct |
399 ms |
22684 KB |
Output is correct |
39 |
Correct |
417 ms |
22420 KB |
Output is correct |
40 |
Correct |
413 ms |
22464 KB |
Output is correct |
41 |
Correct |
431 ms |
22976 KB |
Output is correct |
42 |
Correct |
410 ms |
22860 KB |
Output is correct |
43 |
Correct |
446 ms |
22872 KB |
Output is correct |
44 |
Correct |
448 ms |
23280 KB |
Output is correct |
45 |
Correct |
425 ms |
23264 KB |
Output is correct |
46 |
Correct |
446 ms |
23176 KB |
Output is correct |
47 |
Correct |
434 ms |
23224 KB |
Output is correct |
48 |
Correct |
444 ms |
23292 KB |
Output is correct |
49 |
Correct |
406 ms |
22056 KB |
Output is correct |
50 |
Correct |
391 ms |
21940 KB |
Output is correct |
51 |
Correct |
425 ms |
21764 KB |
Output is correct |
52 |
Correct |
388 ms |
21900 KB |
Output is correct |
53 |
Correct |
403 ms |
21964 KB |
Output is correct |
54 |
Correct |
459 ms |
21564 KB |
Output is correct |
55 |
Correct |
367 ms |
16400 KB |
Output is correct |
56 |
Correct |
418 ms |
21096 KB |
Output is correct |
57 |
Correct |
2609 ms |
116008 KB |
Output is correct |
58 |
Correct |
2467 ms |
115980 KB |
Output is correct |
59 |
Correct |
2461 ms |
114356 KB |
Output is correct |
60 |
Correct |
2413 ms |
114276 KB |
Output is correct |
61 |
Correct |
2629 ms |
114404 KB |
Output is correct |
62 |
Correct |
2542 ms |
114276 KB |
Output is correct |
63 |
Correct |
1864 ms |
111208 KB |
Output is correct |
64 |
Correct |
1908 ms |
111092 KB |
Output is correct |
65 |
Correct |
2106 ms |
114188 KB |
Output is correct |
66 |
Correct |
2121 ms |
114104 KB |
Output is correct |
67 |
Correct |
2081 ms |
114288 KB |
Output is correct |
68 |
Correct |
2172 ms |
115952 KB |
Output is correct |
69 |
Correct |
2180 ms |
115888 KB |
Output is correct |
70 |
Correct |
2254 ms |
115596 KB |
Output is correct |
71 |
Correct |
2125 ms |
115524 KB |
Output is correct |
72 |
Correct |
2144 ms |
115504 KB |
Output is correct |
73 |
Correct |
1777 ms |
106976 KB |
Output is correct |
74 |
Correct |
1760 ms |
107864 KB |
Output is correct |
75 |
Correct |
1781 ms |
107048 KB |
Output is correct |
76 |
Correct |
1762 ms |
107376 KB |
Output is correct |
77 |
Correct |
1818 ms |
106824 KB |
Output is correct |
78 |
Correct |
2047 ms |
107880 KB |
Output is correct |
79 |
Correct |
1745 ms |
72992 KB |
Output is correct |
80 |
Correct |
2019 ms |
105272 KB |
Output is correct |