/*
author: Maksim1744
created: 03.03.2021 16:47:45
*/
#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sum(a) ( accumulate ((a).begin(), (a).end(), 0ll))
#define mine(a) (*min_element((a).begin(), (a).end()))
#define maxe(a) (*max_element((a).begin(), (a).end()))
#define mini(a) ( min_element((a).begin(), (a).end()) - (a).begin())
#define maxi(a) ( max_element((a).begin(), (a).end()) - (a).begin())
#define lowb(a, x) ( lower_bound((a).begin(), (a).end(), (x)) - (a).begin())
#define uppb(a, x) ( upper_bound((a).begin(), (a).end(), (x)) - (a).begin())
template<typename T> vector<T>& operator-- (vector<T>& v){for (auto& i : v) --i; return v;}
template<typename T> vector<T>& operator++ (vector<T>& v){for (auto& i : v) ++i; return v;}
template<typename T> istream& operator>>(istream& is, vector<T>& v){for (auto& i : v) is >> i; return is;}
template<typename T> ostream& operator<<(ostream& os, vector<T>& v){for (auto& i : v) os << i << ' '; return os;}
template<typename T, typename U> pair<T,U>& operator-- (pair<T, U> &p){--p.first; --p.second; return p;}
template<typename T, typename U> pair<T,U>& operator++ (pair<T, U> &p){++p.first; ++p.second; return p;}
template<typename T, typename U> istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second; return is;}
template<typename T, typename U> ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first << ' ' << p.second; return os;}
template<typename T, typename U> pair<T,U> operator-(pair<T,U> a, pair<T,U> b){return mp(a.first-b.first, a.second-b.second);}
template<typename T, typename U> pair<T,U> operator+(pair<T,U> a, pair<T,U> b){return mp(a.first+b.first, a.second+b.second);}
template<typename T, typename U> void umin(T& a, U b){if (a > b) a = b;}
template<typename T, typename U> void umax(T& a, U b){if (a < b) a = b;}
#ifdef HOME
#define SHOW_COLORS
#include "C:/C++ libs/print.cpp"
#else
#define show(...) 42
#define mclock 42
#define shows 42
#define debug if (false)
#endif
template<typename T>
struct fenwick {
vector<T> tree;
int n;
fenwick(int n = 0) : n(n) {
tree.assign(n, 0);
}
void set(int i, T k) {
for (; i < n; i = (i | (i + 1)))
tree[i] = max(tree[i], k);
}
T ask(int r) {
T res = 0;
for (; r >= 0; r = (r & (r + 1)) - 1)
res = max(res, tree[r]);
return res;
}
};
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int n, q;
cin >> n >> q;
vector<ll> w(n);
cin >> w;
struct str {
int l, r;
ll k;
int ind;
};
vector<str> que(q);
for (int i = 0; i < q; ++i) {
cin >> que[i].l >> que[i].r >> que[i].k;
que[i].ind = i;
--que[i].l;
--que[i].r;
}
vector<int> ans(q, -1);
sort(que.begin(), que.end(), [&](const auto &a, const auto &b) {
return a.r < b.r;
});
vector<int> st;
fenwick<int> tree(n);
int ind = 0;
for (auto q : que) {
while (ind <= q.r) {
while (!st.empty() && w[st.back()] <= w[ind])
st.pop_back();
if (!st.empty()) {
tree.set(n - 1 - st.back(), w[ind] + w[st.back()]);
}
st.pb(ind);
++ind;
}
ll val = tree.ask(n - 1 - q.l);
ans[q.ind] = (val <= q.k);
}
for (int k : ans)
cout << k << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
3 ms |
620 KB |
Output is correct |
13 |
Correct |
4 ms |
620 KB |
Output is correct |
14 |
Correct |
4 ms |
748 KB |
Output is correct |
15 |
Correct |
7 ms |
748 KB |
Output is correct |
16 |
Correct |
7 ms |
620 KB |
Output is correct |
17 |
Correct |
3 ms |
620 KB |
Output is correct |
18 |
Correct |
3 ms |
620 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
777 ms |
41632 KB |
Output is correct |
2 |
Correct |
789 ms |
41564 KB |
Output is correct |
3 |
Correct |
728 ms |
41452 KB |
Output is correct |
4 |
Correct |
755 ms |
41452 KB |
Output is correct |
5 |
Correct |
814 ms |
41580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
74 ms |
4460 KB |
Output is correct |
2 |
Correct |
59 ms |
6380 KB |
Output is correct |
3 |
Correct |
61 ms |
6508 KB |
Output is correct |
4 |
Correct |
57 ms |
6380 KB |
Output is correct |
5 |
Correct |
56 ms |
6380 KB |
Output is correct |
6 |
Correct |
66 ms |
6252 KB |
Output is correct |
7 |
Correct |
52 ms |
6252 KB |
Output is correct |
8 |
Correct |
55 ms |
6124 KB |
Output is correct |
9 |
Correct |
42 ms |
4620 KB |
Output is correct |
10 |
Correct |
66 ms |
6252 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
3 ms |
620 KB |
Output is correct |
13 |
Correct |
4 ms |
620 KB |
Output is correct |
14 |
Correct |
4 ms |
748 KB |
Output is correct |
15 |
Correct |
7 ms |
748 KB |
Output is correct |
16 |
Correct |
7 ms |
620 KB |
Output is correct |
17 |
Correct |
3 ms |
620 KB |
Output is correct |
18 |
Correct |
3 ms |
620 KB |
Output is correct |
19 |
Correct |
137 ms |
10988 KB |
Output is correct |
20 |
Correct |
229 ms |
10960 KB |
Output is correct |
21 |
Correct |
177 ms |
10988 KB |
Output is correct |
22 |
Correct |
161 ms |
10960 KB |
Output is correct |
23 |
Correct |
152 ms |
10988 KB |
Output is correct |
24 |
Correct |
129 ms |
11116 KB |
Output is correct |
25 |
Correct |
185 ms |
11060 KB |
Output is correct |
26 |
Correct |
136 ms |
10988 KB |
Output is correct |
27 |
Correct |
141 ms |
10988 KB |
Output is correct |
28 |
Correct |
131 ms |
11004 KB |
Output is correct |
29 |
Correct |
154 ms |
10988 KB |
Output is correct |
30 |
Correct |
132 ms |
10988 KB |
Output is correct |
31 |
Correct |
130 ms |
10988 KB |
Output is correct |
32 |
Correct |
131 ms |
10988 KB |
Output is correct |
33 |
Correct |
158 ms |
10988 KB |
Output is correct |
34 |
Correct |
131 ms |
11116 KB |
Output is correct |
35 |
Correct |
168 ms |
11116 KB |
Output is correct |
36 |
Correct |
123 ms |
10988 KB |
Output is correct |
37 |
Correct |
188 ms |
10988 KB |
Output is correct |
38 |
Correct |
125 ms |
11116 KB |
Output is correct |
39 |
Correct |
125 ms |
11116 KB |
Output is correct |
40 |
Correct |
132 ms |
10476 KB |
Output is correct |
41 |
Correct |
118 ms |
11116 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
2 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
3 ms |
620 KB |
Output is correct |
13 |
Correct |
4 ms |
620 KB |
Output is correct |
14 |
Correct |
4 ms |
748 KB |
Output is correct |
15 |
Correct |
7 ms |
748 KB |
Output is correct |
16 |
Correct |
7 ms |
620 KB |
Output is correct |
17 |
Correct |
3 ms |
620 KB |
Output is correct |
18 |
Correct |
3 ms |
620 KB |
Output is correct |
19 |
Correct |
777 ms |
41632 KB |
Output is correct |
20 |
Correct |
789 ms |
41564 KB |
Output is correct |
21 |
Correct |
728 ms |
41452 KB |
Output is correct |
22 |
Correct |
755 ms |
41452 KB |
Output is correct |
23 |
Correct |
814 ms |
41580 KB |
Output is correct |
24 |
Correct |
74 ms |
4460 KB |
Output is correct |
25 |
Correct |
59 ms |
6380 KB |
Output is correct |
26 |
Correct |
61 ms |
6508 KB |
Output is correct |
27 |
Correct |
57 ms |
6380 KB |
Output is correct |
28 |
Correct |
56 ms |
6380 KB |
Output is correct |
29 |
Correct |
66 ms |
6252 KB |
Output is correct |
30 |
Correct |
52 ms |
6252 KB |
Output is correct |
31 |
Correct |
55 ms |
6124 KB |
Output is correct |
32 |
Correct |
42 ms |
4620 KB |
Output is correct |
33 |
Correct |
66 ms |
6252 KB |
Output is correct |
34 |
Correct |
137 ms |
10988 KB |
Output is correct |
35 |
Correct |
229 ms |
10960 KB |
Output is correct |
36 |
Correct |
177 ms |
10988 KB |
Output is correct |
37 |
Correct |
161 ms |
10960 KB |
Output is correct |
38 |
Correct |
152 ms |
10988 KB |
Output is correct |
39 |
Correct |
129 ms |
11116 KB |
Output is correct |
40 |
Correct |
185 ms |
11060 KB |
Output is correct |
41 |
Correct |
136 ms |
10988 KB |
Output is correct |
42 |
Correct |
141 ms |
10988 KB |
Output is correct |
43 |
Correct |
131 ms |
11004 KB |
Output is correct |
44 |
Correct |
154 ms |
10988 KB |
Output is correct |
45 |
Correct |
132 ms |
10988 KB |
Output is correct |
46 |
Correct |
130 ms |
10988 KB |
Output is correct |
47 |
Correct |
131 ms |
10988 KB |
Output is correct |
48 |
Correct |
158 ms |
10988 KB |
Output is correct |
49 |
Correct |
131 ms |
11116 KB |
Output is correct |
50 |
Correct |
168 ms |
11116 KB |
Output is correct |
51 |
Correct |
123 ms |
10988 KB |
Output is correct |
52 |
Correct |
188 ms |
10988 KB |
Output is correct |
53 |
Correct |
125 ms |
11116 KB |
Output is correct |
54 |
Correct |
125 ms |
11116 KB |
Output is correct |
55 |
Correct |
132 ms |
10476 KB |
Output is correct |
56 |
Correct |
118 ms |
11116 KB |
Output is correct |
57 |
Correct |
791 ms |
43844 KB |
Output is correct |
58 |
Correct |
768 ms |
43904 KB |
Output is correct |
59 |
Correct |
758 ms |
43884 KB |
Output is correct |
60 |
Correct |
740 ms |
43820 KB |
Output is correct |
61 |
Correct |
772 ms |
44012 KB |
Output is correct |
62 |
Correct |
773 ms |
44012 KB |
Output is correct |
63 |
Correct |
633 ms |
43884 KB |
Output is correct |
64 |
Correct |
647 ms |
43828 KB |
Output is correct |
65 |
Correct |
1322 ms |
43884 KB |
Output is correct |
66 |
Correct |
732 ms |
44012 KB |
Output is correct |
67 |
Correct |
689 ms |
43912 KB |
Output is correct |
68 |
Correct |
1201 ms |
43796 KB |
Output is correct |
69 |
Correct |
1198 ms |
43884 KB |
Output is correct |
70 |
Correct |
717 ms |
43924 KB |
Output is correct |
71 |
Correct |
683 ms |
43904 KB |
Output is correct |
72 |
Correct |
711 ms |
43872 KB |
Output is correct |
73 |
Correct |
663 ms |
44012 KB |
Output is correct |
74 |
Correct |
653 ms |
43908 KB |
Output is correct |
75 |
Correct |
648 ms |
43884 KB |
Output is correct |
76 |
Correct |
608 ms |
43756 KB |
Output is correct |
77 |
Correct |
958 ms |
43876 KB |
Output is correct |
78 |
Correct |
656 ms |
43980 KB |
Output is correct |
79 |
Correct |
543 ms |
36972 KB |
Output is correct |
80 |
Correct |
630 ms |
43116 KB |
Output is correct |