#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
vector<ll> fenwick; // for max
void print()
{
cout << "Fenwick:\n";
for (int i=0; i<=n; i++) cout << fenwick[i] << ' ';
cout << '\n';
}
void upd(int i, ll val)
{
while (i > 0)
{
fenwick[i] = max(fenwick[i], val);
i -= -i&i;
}
//print();
}
ll get(int r)
{
ll mx = 0;
while (r <= n)
{
mx = max(mx, fenwick[r]);
r += -r&r;
}
//print();
return mx;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
int m;
cin >> n >> m;
fenwick.assign(n, 0);
//print();
ll w[n];
for (int i=1; i<=n; i++)
cin >> w[i];
vector< pair< pair <ll, ll>, ll > > que[n+1];
for (int i=0; i<m; i++)
{
ll l, r, k;
cin >> l >> r >> k;
que[r].push_back({{l, k}, i});
}
ll ans[m];
stack<int> st;
st.push(0);
for (int i=1; i<=n; i++)
{
while (!st.empty() and w[i] >= w[st.top()])
st.pop();
if (!st.empty())
upd(st.top(), w[st.top()]+w[i]);
for (auto q : que[i])
{
ans[q.second] = get(q.first.first)<=q.first.second;
}
st.push(i);
}
for (int i=0; i<m; i++) cout << ans[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
624 KB |
Output is correct |
13 |
Correct |
2 ms |
712 KB |
Output is correct |
14 |
Correct |
3 ms |
844 KB |
Output is correct |
15 |
Correct |
3 ms |
852 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
18 |
Correct |
3 ms |
724 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
816 ms |
96608 KB |
Output is correct |
2 |
Correct |
826 ms |
82576 KB |
Output is correct |
3 |
Correct |
805 ms |
82312 KB |
Output is correct |
4 |
Correct |
844 ms |
94128 KB |
Output is correct |
5 |
Correct |
875 ms |
114596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
49 ms |
10356 KB |
Output is correct |
2 |
Correct |
47 ms |
10588 KB |
Output is correct |
3 |
Correct |
47 ms |
10452 KB |
Output is correct |
4 |
Correct |
47 ms |
10444 KB |
Output is correct |
5 |
Correct |
48 ms |
10388 KB |
Output is correct |
6 |
Correct |
43 ms |
10316 KB |
Output is correct |
7 |
Correct |
41 ms |
10316 KB |
Output is correct |
8 |
Correct |
44 ms |
9736 KB |
Output is correct |
9 |
Correct |
29 ms |
5456 KB |
Output is correct |
10 |
Correct |
49 ms |
9712 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
624 KB |
Output is correct |
13 |
Correct |
2 ms |
712 KB |
Output is correct |
14 |
Correct |
3 ms |
844 KB |
Output is correct |
15 |
Correct |
3 ms |
852 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
18 |
Correct |
3 ms |
724 KB |
Output is correct |
19 |
Correct |
131 ms |
23224 KB |
Output is correct |
20 |
Correct |
136 ms |
23136 KB |
Output is correct |
21 |
Correct |
114 ms |
23652 KB |
Output is correct |
22 |
Correct |
122 ms |
23524 KB |
Output is correct |
23 |
Correct |
111 ms |
23520 KB |
Output is correct |
24 |
Correct |
105 ms |
23612 KB |
Output is correct |
25 |
Correct |
103 ms |
23664 KB |
Output is correct |
26 |
Correct |
113 ms |
23372 KB |
Output is correct |
27 |
Correct |
113 ms |
23328 KB |
Output is correct |
28 |
Correct |
122 ms |
23304 KB |
Output is correct |
29 |
Correct |
120 ms |
23148 KB |
Output is correct |
30 |
Correct |
125 ms |
23168 KB |
Output is correct |
31 |
Correct |
123 ms |
23156 KB |
Output is correct |
32 |
Correct |
123 ms |
23144 KB |
Output is correct |
33 |
Correct |
129 ms |
23252 KB |
Output is correct |
34 |
Correct |
99 ms |
22880 KB |
Output is correct |
35 |
Correct |
103 ms |
22860 KB |
Output is correct |
36 |
Correct |
91 ms |
22640 KB |
Output is correct |
37 |
Correct |
97 ms |
22744 KB |
Output is correct |
38 |
Correct |
102 ms |
22876 KB |
Output is correct |
39 |
Correct |
143 ms |
21260 KB |
Output is correct |
40 |
Correct |
91 ms |
17372 KB |
Output is correct |
41 |
Correct |
113 ms |
20668 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
328 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
468 KB |
Output is correct |
12 |
Correct |
2 ms |
624 KB |
Output is correct |
13 |
Correct |
2 ms |
712 KB |
Output is correct |
14 |
Correct |
3 ms |
844 KB |
Output is correct |
15 |
Correct |
3 ms |
852 KB |
Output is correct |
16 |
Correct |
3 ms |
724 KB |
Output is correct |
17 |
Correct |
3 ms |
724 KB |
Output is correct |
18 |
Correct |
3 ms |
724 KB |
Output is correct |
19 |
Correct |
816 ms |
96608 KB |
Output is correct |
20 |
Correct |
826 ms |
82576 KB |
Output is correct |
21 |
Correct |
805 ms |
82312 KB |
Output is correct |
22 |
Correct |
844 ms |
94128 KB |
Output is correct |
23 |
Correct |
875 ms |
114596 KB |
Output is correct |
24 |
Correct |
49 ms |
10356 KB |
Output is correct |
25 |
Correct |
47 ms |
10588 KB |
Output is correct |
26 |
Correct |
47 ms |
10452 KB |
Output is correct |
27 |
Correct |
47 ms |
10444 KB |
Output is correct |
28 |
Correct |
48 ms |
10388 KB |
Output is correct |
29 |
Correct |
43 ms |
10316 KB |
Output is correct |
30 |
Correct |
41 ms |
10316 KB |
Output is correct |
31 |
Correct |
44 ms |
9736 KB |
Output is correct |
32 |
Correct |
29 ms |
5456 KB |
Output is correct |
33 |
Correct |
49 ms |
9712 KB |
Output is correct |
34 |
Correct |
131 ms |
23224 KB |
Output is correct |
35 |
Correct |
136 ms |
23136 KB |
Output is correct |
36 |
Correct |
114 ms |
23652 KB |
Output is correct |
37 |
Correct |
122 ms |
23524 KB |
Output is correct |
38 |
Correct |
111 ms |
23520 KB |
Output is correct |
39 |
Correct |
105 ms |
23612 KB |
Output is correct |
40 |
Correct |
103 ms |
23664 KB |
Output is correct |
41 |
Correct |
113 ms |
23372 KB |
Output is correct |
42 |
Correct |
113 ms |
23328 KB |
Output is correct |
43 |
Correct |
122 ms |
23304 KB |
Output is correct |
44 |
Correct |
120 ms |
23148 KB |
Output is correct |
45 |
Correct |
125 ms |
23168 KB |
Output is correct |
46 |
Correct |
123 ms |
23156 KB |
Output is correct |
47 |
Correct |
123 ms |
23144 KB |
Output is correct |
48 |
Correct |
129 ms |
23252 KB |
Output is correct |
49 |
Correct |
99 ms |
22880 KB |
Output is correct |
50 |
Correct |
103 ms |
22860 KB |
Output is correct |
51 |
Correct |
91 ms |
22640 KB |
Output is correct |
52 |
Correct |
97 ms |
22744 KB |
Output is correct |
53 |
Correct |
102 ms |
22876 KB |
Output is correct |
54 |
Correct |
143 ms |
21260 KB |
Output is correct |
55 |
Correct |
91 ms |
17372 KB |
Output is correct |
56 |
Correct |
113 ms |
20668 KB |
Output is correct |
57 |
Correct |
809 ms |
115392 KB |
Output is correct |
58 |
Correct |
800 ms |
115420 KB |
Output is correct |
59 |
Correct |
753 ms |
116260 KB |
Output is correct |
60 |
Correct |
752 ms |
116276 KB |
Output is correct |
61 |
Correct |
751 ms |
116176 KB |
Output is correct |
62 |
Correct |
757 ms |
116108 KB |
Output is correct |
63 |
Correct |
523 ms |
116364 KB |
Output is correct |
64 |
Correct |
522 ms |
116292 KB |
Output is correct |
65 |
Correct |
719 ms |
116280 KB |
Output is correct |
66 |
Correct |
729 ms |
116240 KB |
Output is correct |
67 |
Correct |
738 ms |
116248 KB |
Output is correct |
68 |
Correct |
808 ms |
115360 KB |
Output is correct |
69 |
Correct |
810 ms |
115460 KB |
Output is correct |
70 |
Correct |
782 ms |
115480 KB |
Output is correct |
71 |
Correct |
778 ms |
115488 KB |
Output is correct |
72 |
Correct |
772 ms |
115524 KB |
Output is correct |
73 |
Correct |
472 ms |
110212 KB |
Output is correct |
74 |
Correct |
506 ms |
111260 KB |
Output is correct |
75 |
Correct |
493 ms |
110032 KB |
Output is correct |
76 |
Correct |
474 ms |
110584 KB |
Output is correct |
77 |
Correct |
486 ms |
110236 KB |
Output is correct |
78 |
Correct |
693 ms |
106760 KB |
Output is correct |
79 |
Correct |
534 ms |
80992 KB |
Output is correct |
80 |
Correct |
686 ms |
102428 KB |
Output is correct |