#include <bits/stdc++.h>
//#define int long long
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int mod = 1e9 + 7;
const int LOG = 20;
const int maxn = 1e6 + 5;
int tree[4*maxn+5];
void update(int u, int tl, int tr, int p, int v) {
if(tl == tr) {
tree[u] = max(tree[u], v);
} else {
int tm = (tl + tr) / 2;
if(p <= tm) update(2*u, tl, tm, p, v);
else update(2*u+1, tm+1, tr, p, v);
tree[u] = max(tree[2*u], tree[2*u+1]);
}
}
int query(int u, int tl, int tr, int l, int r) {
if(l > tr || tl > r) return 0;
if(l <= tl && tr <= r) return tree[u];
int tm = (tl + tr) / 2;
return max(query(2*u, tl, tm, l, r), query(2*u+1, tm+1, tr, l, r));
}
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(0); cin.tie(0);
int n, q;
cin >> n >> q;
vector<int> v(n+1), ans(q);
for(int i=1; i<=n; i++) cin >> v[i];
vector<array<int, 3> > qus[n+1];
for(int i=0; i<q; i++) {
int l, r, k; cin >> l >> r >> k;
qus[r].push_back({ l, k, i });
}
stack<pii> st;
for(int i=1; i<=n; i++) {
while(!st.empty() && st.top().first <= v[i]) st.pop();
if(!st.empty()) update(1, 1, n, st.top().second, st.top().first + v[i]);
for(auto &[l, k, id] : qus[i]) ans[id] = (query(1, 1, n, l, i) <= k);
st.push({ v[i], i });
}
for(int x : ans) cout << x << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
600 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
772 KB |
Output is correct |
17 |
Correct |
2 ms |
728 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
930 ms |
63576 KB |
Output is correct |
2 |
Correct |
869 ms |
63584 KB |
Output is correct |
3 |
Correct |
929 ms |
63576 KB |
Output is correct |
4 |
Correct |
863 ms |
63568 KB |
Output is correct |
5 |
Correct |
799 ms |
55408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
61 ms |
6816 KB |
Output is correct |
2 |
Correct |
57 ms |
6480 KB |
Output is correct |
3 |
Correct |
53 ms |
5808 KB |
Output is correct |
4 |
Correct |
53 ms |
7764 KB |
Output is correct |
5 |
Correct |
55 ms |
7704 KB |
Output is correct |
6 |
Correct |
48 ms |
7164 KB |
Output is correct |
7 |
Correct |
49 ms |
7252 KB |
Output is correct |
8 |
Correct |
51 ms |
7576 KB |
Output is correct |
9 |
Correct |
26 ms |
3860 KB |
Output is correct |
10 |
Correct |
52 ms |
7572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
600 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
772 KB |
Output is correct |
17 |
Correct |
2 ms |
728 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
140 ms |
13264 KB |
Output is correct |
20 |
Correct |
139 ms |
13396 KB |
Output is correct |
21 |
Correct |
137 ms |
14416 KB |
Output is correct |
22 |
Correct |
131 ms |
19300 KB |
Output is correct |
23 |
Correct |
136 ms |
19308 KB |
Output is correct |
24 |
Correct |
116 ms |
16904 KB |
Output is correct |
25 |
Correct |
122 ms |
16992 KB |
Output is correct |
26 |
Correct |
146 ms |
17376 KB |
Output is correct |
27 |
Correct |
134 ms |
17360 KB |
Output is correct |
28 |
Correct |
122 ms |
17516 KB |
Output is correct |
29 |
Correct |
126 ms |
17752 KB |
Output is correct |
30 |
Correct |
134 ms |
17748 KB |
Output is correct |
31 |
Correct |
130 ms |
17816 KB |
Output is correct |
32 |
Correct |
155 ms |
17748 KB |
Output is correct |
33 |
Correct |
138 ms |
17900 KB |
Output is correct |
34 |
Correct |
105 ms |
16724 KB |
Output is correct |
35 |
Correct |
105 ms |
16600 KB |
Output is correct |
36 |
Correct |
109 ms |
16416 KB |
Output is correct |
37 |
Correct |
97 ms |
16424 KB |
Output is correct |
38 |
Correct |
106 ms |
16752 KB |
Output is correct |
39 |
Correct |
105 ms |
16780 KB |
Output is correct |
40 |
Correct |
85 ms |
13048 KB |
Output is correct |
41 |
Correct |
101 ms |
15884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
2 ms |
348 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
3 ms |
600 KB |
Output is correct |
14 |
Correct |
3 ms |
604 KB |
Output is correct |
15 |
Correct |
3 ms |
604 KB |
Output is correct |
16 |
Correct |
2 ms |
772 KB |
Output is correct |
17 |
Correct |
2 ms |
728 KB |
Output is correct |
18 |
Correct |
2 ms |
604 KB |
Output is correct |
19 |
Correct |
930 ms |
63576 KB |
Output is correct |
20 |
Correct |
869 ms |
63584 KB |
Output is correct |
21 |
Correct |
929 ms |
63576 KB |
Output is correct |
22 |
Correct |
863 ms |
63568 KB |
Output is correct |
23 |
Correct |
799 ms |
55408 KB |
Output is correct |
24 |
Correct |
61 ms |
6816 KB |
Output is correct |
25 |
Correct |
57 ms |
6480 KB |
Output is correct |
26 |
Correct |
53 ms |
5808 KB |
Output is correct |
27 |
Correct |
53 ms |
7764 KB |
Output is correct |
28 |
Correct |
55 ms |
7704 KB |
Output is correct |
29 |
Correct |
48 ms |
7164 KB |
Output is correct |
30 |
Correct |
49 ms |
7252 KB |
Output is correct |
31 |
Correct |
51 ms |
7576 KB |
Output is correct |
32 |
Correct |
26 ms |
3860 KB |
Output is correct |
33 |
Correct |
52 ms |
7572 KB |
Output is correct |
34 |
Correct |
140 ms |
13264 KB |
Output is correct |
35 |
Correct |
139 ms |
13396 KB |
Output is correct |
36 |
Correct |
137 ms |
14416 KB |
Output is correct |
37 |
Correct |
131 ms |
19300 KB |
Output is correct |
38 |
Correct |
136 ms |
19308 KB |
Output is correct |
39 |
Correct |
116 ms |
16904 KB |
Output is correct |
40 |
Correct |
122 ms |
16992 KB |
Output is correct |
41 |
Correct |
146 ms |
17376 KB |
Output is correct |
42 |
Correct |
134 ms |
17360 KB |
Output is correct |
43 |
Correct |
122 ms |
17516 KB |
Output is correct |
44 |
Correct |
126 ms |
17752 KB |
Output is correct |
45 |
Correct |
134 ms |
17748 KB |
Output is correct |
46 |
Correct |
130 ms |
17816 KB |
Output is correct |
47 |
Correct |
155 ms |
17748 KB |
Output is correct |
48 |
Correct |
138 ms |
17900 KB |
Output is correct |
49 |
Correct |
105 ms |
16724 KB |
Output is correct |
50 |
Correct |
105 ms |
16600 KB |
Output is correct |
51 |
Correct |
109 ms |
16416 KB |
Output is correct |
52 |
Correct |
97 ms |
16424 KB |
Output is correct |
53 |
Correct |
106 ms |
16752 KB |
Output is correct |
54 |
Correct |
105 ms |
16780 KB |
Output is correct |
55 |
Correct |
85 ms |
13048 KB |
Output is correct |
56 |
Correct |
101 ms |
15884 KB |
Output is correct |
57 |
Correct |
880 ms |
96784 KB |
Output is correct |
58 |
Correct |
878 ms |
96728 KB |
Output is correct |
59 |
Correct |
798 ms |
95056 KB |
Output is correct |
60 |
Correct |
850 ms |
95056 KB |
Output is correct |
61 |
Correct |
804 ms |
95056 KB |
Output is correct |
62 |
Correct |
837 ms |
95116 KB |
Output is correct |
63 |
Correct |
575 ms |
83828 KB |
Output is correct |
64 |
Correct |
582 ms |
83792 KB |
Output is correct |
65 |
Correct |
805 ms |
86840 KB |
Output is correct |
66 |
Correct |
736 ms |
86888 KB |
Output is correct |
67 |
Correct |
805 ms |
86776 KB |
Output is correct |
68 |
Correct |
903 ms |
88392 KB |
Output is correct |
69 |
Correct |
902 ms |
88544 KB |
Output is correct |
70 |
Correct |
920 ms |
88168 KB |
Output is correct |
71 |
Correct |
935 ms |
88164 KB |
Output is correct |
72 |
Correct |
846 ms |
88092 KB |
Output is correct |
73 |
Correct |
585 ms |
81468 KB |
Output is correct |
74 |
Correct |
602 ms |
82504 KB |
Output is correct |
75 |
Correct |
588 ms |
81760 KB |
Output is correct |
76 |
Correct |
588 ms |
81884 KB |
Output is correct |
77 |
Correct |
556 ms |
81512 KB |
Output is correct |
78 |
Correct |
760 ms |
83212 KB |
Output is correct |
79 |
Correct |
575 ms |
60484 KB |
Output is correct |
80 |
Correct |
743 ms |
79044 KB |
Output is correct |