#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ii pair<int, int>
#define all(x) x.begin(), x.end()
#define fo(i, a, b) for (int i = (a), b_ = (b); i <= b_; ++i)
#define fd(i, a, b) for (int i = (a), b_ = (b); i >= b_; --i)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define fi first
#define se second
const int N = 1e6+5;
int n, m, a[N], l[N], ans[N], k[N];
ll t[N];
vector<ii> g[N];
void upd(int p, ll v) {
for (; p; p -= p & -p)
chmax(t[p], v);
}
ll get(int p) {
ll tot = 0;
for (; p <= n; p += p & -p)
chmax(tot, t[p]);
return tot;
}
void sol() {
cin >> n >> m;
fo(i,1,n) cin >> a[i];
fo(i,1,m) {
static int l, r;
cin >> l >> r >> k[i];
g[r].pb({l, i});
}
fo(i,1,n) {
l[i] = i-1;
while (l[i] && a[i] >= a[l[i]]) l[i] = l[l[i]];
if (l[i]) upd(l[i], a[l[i]] + a[i]);
for (ii q : g[i]) ans[q.se] = (get(q.fi) <= k[q.se]);
}
fo(i,1,m) cout << ans[i] << '\n';
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin);
int tc = 1, test = 0; // cin >> tc;
while (++test <= tc) sol();
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:51:37: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
51 | if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23852 KB |
Output is correct |
3 |
Correct |
9 ms |
23900 KB |
Output is correct |
4 |
Correct |
9 ms |
23788 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
24008 KB |
Output is correct |
7 |
Correct |
9 ms |
23812 KB |
Output is correct |
8 |
Correct |
13 ms |
23988 KB |
Output is correct |
9 |
Correct |
9 ms |
23996 KB |
Output is correct |
10 |
Correct |
9 ms |
24152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23852 KB |
Output is correct |
3 |
Correct |
9 ms |
23900 KB |
Output is correct |
4 |
Correct |
9 ms |
23788 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
24008 KB |
Output is correct |
7 |
Correct |
9 ms |
23812 KB |
Output is correct |
8 |
Correct |
13 ms |
23988 KB |
Output is correct |
9 |
Correct |
9 ms |
23996 KB |
Output is correct |
10 |
Correct |
9 ms |
24152 KB |
Output is correct |
11 |
Correct |
15 ms |
24060 KB |
Output is correct |
12 |
Correct |
12 ms |
24152 KB |
Output is correct |
13 |
Correct |
12 ms |
24152 KB |
Output is correct |
14 |
Correct |
12 ms |
24296 KB |
Output is correct |
15 |
Correct |
11 ms |
24220 KB |
Output is correct |
16 |
Correct |
11 ms |
24156 KB |
Output is correct |
17 |
Correct |
12 ms |
24156 KB |
Output is correct |
18 |
Correct |
16 ms |
24152 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
641 ms |
100948 KB |
Output is correct |
2 |
Correct |
613 ms |
101972 KB |
Output is correct |
3 |
Correct |
643 ms |
101740 KB |
Output is correct |
4 |
Correct |
635 ms |
101968 KB |
Output is correct |
5 |
Correct |
602 ms |
94176 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
30292 KB |
Output is correct |
2 |
Correct |
45 ms |
29776 KB |
Output is correct |
3 |
Correct |
45 ms |
29404 KB |
Output is correct |
4 |
Correct |
57 ms |
29524 KB |
Output is correct |
5 |
Correct |
46 ms |
29524 KB |
Output is correct |
6 |
Correct |
40 ms |
28496 KB |
Output is correct |
7 |
Correct |
38 ms |
28508 KB |
Output is correct |
8 |
Correct |
41 ms |
29000 KB |
Output is correct |
9 |
Correct |
33 ms |
27080 KB |
Output is correct |
10 |
Correct |
44 ms |
29128 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23852 KB |
Output is correct |
3 |
Correct |
9 ms |
23900 KB |
Output is correct |
4 |
Correct |
9 ms |
23788 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
24008 KB |
Output is correct |
7 |
Correct |
9 ms |
23812 KB |
Output is correct |
8 |
Correct |
13 ms |
23988 KB |
Output is correct |
9 |
Correct |
9 ms |
23996 KB |
Output is correct |
10 |
Correct |
9 ms |
24152 KB |
Output is correct |
11 |
Correct |
15 ms |
24060 KB |
Output is correct |
12 |
Correct |
12 ms |
24152 KB |
Output is correct |
13 |
Correct |
12 ms |
24152 KB |
Output is correct |
14 |
Correct |
12 ms |
24296 KB |
Output is correct |
15 |
Correct |
11 ms |
24220 KB |
Output is correct |
16 |
Correct |
11 ms |
24156 KB |
Output is correct |
17 |
Correct |
12 ms |
24156 KB |
Output is correct |
18 |
Correct |
16 ms |
24152 KB |
Output is correct |
19 |
Correct |
100 ms |
39388 KB |
Output is correct |
20 |
Correct |
103 ms |
39304 KB |
Output is correct |
21 |
Correct |
85 ms |
38224 KB |
Output is correct |
22 |
Correct |
87 ms |
38068 KB |
Output is correct |
23 |
Correct |
92 ms |
38068 KB |
Output is correct |
24 |
Correct |
81 ms |
36180 KB |
Output is correct |
25 |
Correct |
82 ms |
36156 KB |
Output is correct |
26 |
Correct |
89 ms |
36944 KB |
Output is correct |
27 |
Correct |
85 ms |
36760 KB |
Output is correct |
28 |
Correct |
88 ms |
36944 KB |
Output is correct |
29 |
Correct |
92 ms |
37676 KB |
Output is correct |
30 |
Correct |
99 ms |
37712 KB |
Output is correct |
31 |
Correct |
96 ms |
37740 KB |
Output is correct |
32 |
Correct |
102 ms |
37712 KB |
Output is correct |
33 |
Correct |
91 ms |
37668 KB |
Output is correct |
34 |
Correct |
78 ms |
35900 KB |
Output is correct |
35 |
Correct |
76 ms |
35924 KB |
Output is correct |
36 |
Correct |
75 ms |
35608 KB |
Output is correct |
37 |
Correct |
75 ms |
35764 KB |
Output is correct |
38 |
Correct |
80 ms |
35916 KB |
Output is correct |
39 |
Correct |
81 ms |
36328 KB |
Output is correct |
40 |
Correct |
73 ms |
34424 KB |
Output is correct |
41 |
Correct |
108 ms |
35520 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
23900 KB |
Output is correct |
2 |
Correct |
10 ms |
23852 KB |
Output is correct |
3 |
Correct |
9 ms |
23900 KB |
Output is correct |
4 |
Correct |
9 ms |
23788 KB |
Output is correct |
5 |
Correct |
10 ms |
23900 KB |
Output is correct |
6 |
Correct |
10 ms |
24008 KB |
Output is correct |
7 |
Correct |
9 ms |
23812 KB |
Output is correct |
8 |
Correct |
13 ms |
23988 KB |
Output is correct |
9 |
Correct |
9 ms |
23996 KB |
Output is correct |
10 |
Correct |
9 ms |
24152 KB |
Output is correct |
11 |
Correct |
15 ms |
24060 KB |
Output is correct |
12 |
Correct |
12 ms |
24152 KB |
Output is correct |
13 |
Correct |
12 ms |
24152 KB |
Output is correct |
14 |
Correct |
12 ms |
24296 KB |
Output is correct |
15 |
Correct |
11 ms |
24220 KB |
Output is correct |
16 |
Correct |
11 ms |
24156 KB |
Output is correct |
17 |
Correct |
12 ms |
24156 KB |
Output is correct |
18 |
Correct |
16 ms |
24152 KB |
Output is correct |
19 |
Correct |
641 ms |
100948 KB |
Output is correct |
20 |
Correct |
613 ms |
101972 KB |
Output is correct |
21 |
Correct |
643 ms |
101740 KB |
Output is correct |
22 |
Correct |
635 ms |
101968 KB |
Output is correct |
23 |
Correct |
602 ms |
94176 KB |
Output is correct |
24 |
Correct |
52 ms |
30292 KB |
Output is correct |
25 |
Correct |
45 ms |
29776 KB |
Output is correct |
26 |
Correct |
45 ms |
29404 KB |
Output is correct |
27 |
Correct |
57 ms |
29524 KB |
Output is correct |
28 |
Correct |
46 ms |
29524 KB |
Output is correct |
29 |
Correct |
40 ms |
28496 KB |
Output is correct |
30 |
Correct |
38 ms |
28508 KB |
Output is correct |
31 |
Correct |
41 ms |
29000 KB |
Output is correct |
32 |
Correct |
33 ms |
27080 KB |
Output is correct |
33 |
Correct |
44 ms |
29128 KB |
Output is correct |
34 |
Correct |
100 ms |
39388 KB |
Output is correct |
35 |
Correct |
103 ms |
39304 KB |
Output is correct |
36 |
Correct |
85 ms |
38224 KB |
Output is correct |
37 |
Correct |
87 ms |
38068 KB |
Output is correct |
38 |
Correct |
92 ms |
38068 KB |
Output is correct |
39 |
Correct |
81 ms |
36180 KB |
Output is correct |
40 |
Correct |
82 ms |
36156 KB |
Output is correct |
41 |
Correct |
89 ms |
36944 KB |
Output is correct |
42 |
Correct |
85 ms |
36760 KB |
Output is correct |
43 |
Correct |
88 ms |
36944 KB |
Output is correct |
44 |
Correct |
92 ms |
37676 KB |
Output is correct |
45 |
Correct |
99 ms |
37712 KB |
Output is correct |
46 |
Correct |
96 ms |
37740 KB |
Output is correct |
47 |
Correct |
102 ms |
37712 KB |
Output is correct |
48 |
Correct |
91 ms |
37668 KB |
Output is correct |
49 |
Correct |
78 ms |
35900 KB |
Output is correct |
50 |
Correct |
76 ms |
35924 KB |
Output is correct |
51 |
Correct |
75 ms |
35608 KB |
Output is correct |
52 |
Correct |
75 ms |
35764 KB |
Output is correct |
53 |
Correct |
80 ms |
35916 KB |
Output is correct |
54 |
Correct |
81 ms |
36328 KB |
Output is correct |
55 |
Correct |
73 ms |
34424 KB |
Output is correct |
56 |
Correct |
108 ms |
35520 KB |
Output is correct |
57 |
Correct |
536 ms |
101416 KB |
Output is correct |
58 |
Correct |
551 ms |
101524 KB |
Output is correct |
59 |
Correct |
502 ms |
98640 KB |
Output is correct |
60 |
Correct |
484 ms |
98760 KB |
Output is correct |
61 |
Correct |
553 ms |
98644 KB |
Output is correct |
62 |
Correct |
537 ms |
98684 KB |
Output is correct |
63 |
Correct |
391 ms |
85588 KB |
Output is correct |
64 |
Correct |
393 ms |
85588 KB |
Output is correct |
65 |
Correct |
501 ms |
90740 KB |
Output is correct |
66 |
Correct |
521 ms |
90532 KB |
Output is correct |
67 |
Correct |
497 ms |
90708 KB |
Output is correct |
68 |
Correct |
578 ms |
93776 KB |
Output is correct |
69 |
Correct |
557 ms |
93820 KB |
Output is correct |
70 |
Correct |
532 ms |
93120 KB |
Output is correct |
71 |
Correct |
555 ms |
93268 KB |
Output is correct |
72 |
Correct |
566 ms |
93064 KB |
Output is correct |
73 |
Correct |
378 ms |
82460 KB |
Output is correct |
74 |
Correct |
400 ms |
83152 KB |
Output is correct |
75 |
Correct |
353 ms |
82516 KB |
Output is correct |
76 |
Correct |
363 ms |
82516 KB |
Output is correct |
77 |
Correct |
427 ms |
82356 KB |
Output is correct |
78 |
Correct |
465 ms |
88356 KB |
Output is correct |
79 |
Correct |
411 ms |
74872 KB |
Output is correct |
80 |
Correct |
475 ms |
83128 KB |
Output is correct |