#include <bits/stdc++.h>
#define all(i) (i).begin(), (i).end()
using namespace std;
void Debug(bool _split) {}
template<typename T1, typename ...T2>
void Debug(bool _split, T1 i, T2 ...j) {
if (_split)
cerr << ", ";
cerr << i;
Debug(true, j...);
}
#define debug(args...) cerr << "Line(" << __LINE__ << ") : [" << #args << "] is [", Debug(false, args), cerr << "]" << endl
template<typename T1, typename T2>
ostream& operator << (ostream& i, pair<T1, T2> j) {
return i << '(' << j.first << ", " << j.second << ')';
}
typedef long long ll;
typedef pair<int, int> pi;
const int inf = 0x3f3f3f3f, lg = 20;
const ll mod = 1e9 + 7, INF = 0x3f3f3f3f3f3f3f3f;
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
int a[n];
for (int &i : a)
cin >> i;
vector<int> qry[n];
int l[m], k[m], ans[m];
for (int i = 0, x; i < m; ++i)
cin >> l[i] >> x >> k[i], --l[i], qry[--x].push_back(i);
vector<int> stk;
int bit[n + 1]{};
auto modify = [&](int i, int d) {
i = n - 1 - i;
for (++i; i <= n; i += i & -i)
bit[i] = max(bit[i], d);
};
auto query = [&](int i) {
i = n - 1 - i;
int res = 0;
for (++i; i; i -= i & -i)
res = max(res, bit[i]);
return res;
};
for (int i = 0; i < n; ++i) {
while (!stk.empty() && a[stk.back()] <= a[i]) {
if (stk.size() > 1) {
int x = stk[stk.size() - 2], y = stk.back();
modify(x, a[x] + a[y]);
}
stk.pop_back();
}
stk.push_back(i);
for (int j : qry[i]) {
int x = lower_bound(all(stk), l[j]) - stk.begin();
int tmp = x >= stk.size() - 1 ? 0 : a[stk[x]] + a[stk[x + 1]];
tmp = max(tmp, query(l[j]));
if (tmp <= k[j])
ans[j] = 1;
else
ans[j] = 0;
}
}
for (int i : ans)
cout << i << '\n';
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:59:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | int tmp = x >= stk.size() - 1 ? 0 : a[stk[x]] + a[stk[x + 1]];
| ~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
2 ms |
548 KB |
Output is correct |
13 |
Correct |
2 ms |
584 KB |
Output is correct |
14 |
Correct |
3 ms |
724 KB |
Output is correct |
15 |
Correct |
4 ms |
704 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
3 ms |
680 KB |
Output is correct |
18 |
Correct |
2 ms |
584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
882 ms |
63608 KB |
Output is correct |
2 |
Correct |
924 ms |
90944 KB |
Output is correct |
3 |
Correct |
942 ms |
89144 KB |
Output is correct |
4 |
Correct |
903 ms |
81328 KB |
Output is correct |
5 |
Correct |
862 ms |
88428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
6848 KB |
Output is correct |
2 |
Correct |
51 ms |
7544 KB |
Output is correct |
3 |
Correct |
47 ms |
8128 KB |
Output is correct |
4 |
Correct |
48 ms |
8288 KB |
Output is correct |
5 |
Correct |
50 ms |
8380 KB |
Output is correct |
6 |
Correct |
40 ms |
7172 KB |
Output is correct |
7 |
Correct |
45 ms |
7172 KB |
Output is correct |
8 |
Correct |
52 ms |
7872 KB |
Output is correct |
9 |
Correct |
30 ms |
3420 KB |
Output is correct |
10 |
Correct |
49 ms |
7856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
2 ms |
548 KB |
Output is correct |
13 |
Correct |
2 ms |
584 KB |
Output is correct |
14 |
Correct |
3 ms |
724 KB |
Output is correct |
15 |
Correct |
4 ms |
704 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
3 ms |
680 KB |
Output is correct |
18 |
Correct |
2 ms |
584 KB |
Output is correct |
19 |
Correct |
139 ms |
19140 KB |
Output is correct |
20 |
Correct |
148 ms |
19100 KB |
Output is correct |
21 |
Correct |
122 ms |
17192 KB |
Output is correct |
22 |
Correct |
115 ms |
17184 KB |
Output is correct |
23 |
Correct |
143 ms |
17312 KB |
Output is correct |
24 |
Correct |
111 ms |
16876 KB |
Output is correct |
25 |
Correct |
109 ms |
16964 KB |
Output is correct |
26 |
Correct |
117 ms |
17860 KB |
Output is correct |
27 |
Correct |
119 ms |
17964 KB |
Output is correct |
28 |
Correct |
123 ms |
18116 KB |
Output is correct |
29 |
Correct |
136 ms |
19104 KB |
Output is correct |
30 |
Correct |
146 ms |
19080 KB |
Output is correct |
31 |
Correct |
127 ms |
18988 KB |
Output is correct |
32 |
Correct |
144 ms |
19076 KB |
Output is correct |
33 |
Correct |
141 ms |
18964 KB |
Output is correct |
34 |
Correct |
101 ms |
16560 KB |
Output is correct |
35 |
Correct |
104 ms |
16596 KB |
Output is correct |
36 |
Correct |
97 ms |
16412 KB |
Output is correct |
37 |
Correct |
95 ms |
16352 KB |
Output is correct |
38 |
Correct |
102 ms |
16580 KB |
Output is correct |
39 |
Correct |
115 ms |
17328 KB |
Output is correct |
40 |
Correct |
101 ms |
14140 KB |
Output is correct |
41 |
Correct |
114 ms |
17016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
460 KB |
Output is correct |
12 |
Correct |
2 ms |
548 KB |
Output is correct |
13 |
Correct |
2 ms |
584 KB |
Output is correct |
14 |
Correct |
3 ms |
724 KB |
Output is correct |
15 |
Correct |
4 ms |
704 KB |
Output is correct |
16 |
Correct |
3 ms |
716 KB |
Output is correct |
17 |
Correct |
3 ms |
680 KB |
Output is correct |
18 |
Correct |
2 ms |
584 KB |
Output is correct |
19 |
Correct |
882 ms |
63608 KB |
Output is correct |
20 |
Correct |
924 ms |
90944 KB |
Output is correct |
21 |
Correct |
942 ms |
89144 KB |
Output is correct |
22 |
Correct |
903 ms |
81328 KB |
Output is correct |
23 |
Correct |
862 ms |
88428 KB |
Output is correct |
24 |
Correct |
59 ms |
6848 KB |
Output is correct |
25 |
Correct |
51 ms |
7544 KB |
Output is correct |
26 |
Correct |
47 ms |
8128 KB |
Output is correct |
27 |
Correct |
48 ms |
8288 KB |
Output is correct |
28 |
Correct |
50 ms |
8380 KB |
Output is correct |
29 |
Correct |
40 ms |
7172 KB |
Output is correct |
30 |
Correct |
45 ms |
7172 KB |
Output is correct |
31 |
Correct |
52 ms |
7872 KB |
Output is correct |
32 |
Correct |
30 ms |
3420 KB |
Output is correct |
33 |
Correct |
49 ms |
7856 KB |
Output is correct |
34 |
Correct |
139 ms |
19140 KB |
Output is correct |
35 |
Correct |
148 ms |
19100 KB |
Output is correct |
36 |
Correct |
122 ms |
17192 KB |
Output is correct |
37 |
Correct |
115 ms |
17184 KB |
Output is correct |
38 |
Correct |
143 ms |
17312 KB |
Output is correct |
39 |
Correct |
111 ms |
16876 KB |
Output is correct |
40 |
Correct |
109 ms |
16964 KB |
Output is correct |
41 |
Correct |
117 ms |
17860 KB |
Output is correct |
42 |
Correct |
119 ms |
17964 KB |
Output is correct |
43 |
Correct |
123 ms |
18116 KB |
Output is correct |
44 |
Correct |
136 ms |
19104 KB |
Output is correct |
45 |
Correct |
146 ms |
19080 KB |
Output is correct |
46 |
Correct |
127 ms |
18988 KB |
Output is correct |
47 |
Correct |
144 ms |
19076 KB |
Output is correct |
48 |
Correct |
141 ms |
18964 KB |
Output is correct |
49 |
Correct |
101 ms |
16560 KB |
Output is correct |
50 |
Correct |
104 ms |
16596 KB |
Output is correct |
51 |
Correct |
97 ms |
16412 KB |
Output is correct |
52 |
Correct |
95 ms |
16352 KB |
Output is correct |
53 |
Correct |
102 ms |
16580 KB |
Output is correct |
54 |
Correct |
115 ms |
17328 KB |
Output is correct |
55 |
Correct |
101 ms |
14140 KB |
Output is correct |
56 |
Correct |
114 ms |
17016 KB |
Output is correct |
57 |
Correct |
894 ms |
65976 KB |
Output is correct |
58 |
Correct |
924 ms |
66000 KB |
Output is correct |
59 |
Correct |
814 ms |
62900 KB |
Output is correct |
60 |
Correct |
820 ms |
61956 KB |
Output is correct |
61 |
Correct |
801 ms |
63000 KB |
Output is correct |
62 |
Correct |
815 ms |
62744 KB |
Output is correct |
63 |
Correct |
566 ms |
56764 KB |
Output is correct |
64 |
Correct |
582 ms |
56728 KB |
Output is correct |
65 |
Correct |
750 ms |
62444 KB |
Output is correct |
66 |
Correct |
764 ms |
62480 KB |
Output is correct |
67 |
Correct |
815 ms |
62536 KB |
Output is correct |
68 |
Correct |
836 ms |
66980 KB |
Output is correct |
69 |
Correct |
832 ms |
66928 KB |
Output is correct |
70 |
Correct |
826 ms |
66336 KB |
Output is correct |
71 |
Correct |
818 ms |
65844 KB |
Output is correct |
72 |
Correct |
835 ms |
64620 KB |
Output is correct |
73 |
Correct |
501 ms |
54464 KB |
Output is correct |
74 |
Correct |
546 ms |
54388 KB |
Output is correct |
75 |
Correct |
513 ms |
54128 KB |
Output is correct |
76 |
Correct |
523 ms |
54104 KB |
Output is correct |
77 |
Correct |
510 ms |
53612 KB |
Output is correct |
78 |
Correct |
718 ms |
61872 KB |
Output is correct |
79 |
Correct |
544 ms |
44148 KB |
Output is correct |
80 |
Correct |
708 ms |
61868 KB |
Output is correct |