#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN = 1e6+5;
int tree[4*MAXN];
int a[MAXN];
vector<tuple<int,int,int>> queries[MAXN];
bool ans[MAXN];
void upd(int i, int v, int x, int lx, int rx) {
if (lx == rx) {
tree[x] = v;
return;
}
int mid = (lx + rx) / 2;
if (i <= mid) upd(i, v, 2*x, lx, mid);
else upd(i, v, 2*x+1, mid+1, rx);
tree[x] = max(tree[2*x], tree[2*x+1]);
}
int qry(int l, int r, int x, int lx, int rx) {
if (l <= lx && rx <= r) return tree[x];
if (r < lx || rx < l) return 0;
int mid = (lx+rx) /2;
return max(qry(l,r,2*x,lx,mid), qry(l,r,2*x+1,mid+1,rx));
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
int n, m; cin >> n >> m;
//vector<int> a(n+1);
//vector<vector<tuple<int,int,int>>> queries(n+1);
//vector<int> ans(n+1);
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
for (int i = 1; i <= m; ++i) {
int l, r, k; cin >> l >> r >> k;
queries[r].push_back({l, k, i});
}
//cout << "OK"<<endl;
stack<int> st;
for (int i = 1; i <= n; ++i) { // iterate from 1 to n over Rs in queries
while(!st.empty() && a[st.top()] <= a[i]) st.pop();
if (!st.empty()) { // Greedily include swap(st.top(), i) at st.top(), because all future Rs are >= than i
upd(st.top(), a[st.top()] + a[i], 1, 1, n);
}
for (auto &x : queries[i]) {
int l = get<0>(x);
int k = get<1>(x);
int j = get<2>(x);
if (qry(l, i, 1, 1, n) <= k) ans[j] = 1;
else ans[j] = 0;
}
st.push(i);
}
for (int i = 1; i <= m; ++i) cout << ans[i] << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23820 KB |
Output is correct |
6 |
Correct |
11 ms |
23796 KB |
Output is correct |
7 |
Correct |
12 ms |
23832 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
13 ms |
23820 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23820 KB |
Output is correct |
6 |
Correct |
11 ms |
23796 KB |
Output is correct |
7 |
Correct |
12 ms |
23832 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
13 ms |
23820 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
23892 KB |
Output is correct |
12 |
Correct |
16 ms |
24032 KB |
Output is correct |
13 |
Correct |
15 ms |
24056 KB |
Output is correct |
14 |
Correct |
17 ms |
24076 KB |
Output is correct |
15 |
Correct |
17 ms |
24192 KB |
Output is correct |
16 |
Correct |
15 ms |
24056 KB |
Output is correct |
17 |
Correct |
15 ms |
24000 KB |
Output is correct |
18 |
Correct |
16 ms |
23956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1218 ms |
60592 KB |
Output is correct |
2 |
Correct |
1191 ms |
60624 KB |
Output is correct |
3 |
Correct |
1299 ms |
60536 KB |
Output is correct |
4 |
Correct |
1201 ms |
60672 KB |
Output is correct |
5 |
Correct |
1025 ms |
52348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
98 ms |
27596 KB |
Output is correct |
2 |
Correct |
101 ms |
27300 KB |
Output is correct |
3 |
Correct |
80 ms |
26420 KB |
Output is correct |
4 |
Correct |
82 ms |
26472 KB |
Output is correct |
5 |
Correct |
90 ms |
26636 KB |
Output is correct |
6 |
Correct |
75 ms |
26124 KB |
Output is correct |
7 |
Correct |
72 ms |
26172 KB |
Output is correct |
8 |
Correct |
75 ms |
26452 KB |
Output is correct |
9 |
Correct |
46 ms |
25600 KB |
Output is correct |
10 |
Correct |
74 ms |
28084 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23820 KB |
Output is correct |
6 |
Correct |
11 ms |
23796 KB |
Output is correct |
7 |
Correct |
12 ms |
23832 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
13 ms |
23820 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
23892 KB |
Output is correct |
12 |
Correct |
16 ms |
24032 KB |
Output is correct |
13 |
Correct |
15 ms |
24056 KB |
Output is correct |
14 |
Correct |
17 ms |
24076 KB |
Output is correct |
15 |
Correct |
17 ms |
24192 KB |
Output is correct |
16 |
Correct |
15 ms |
24056 KB |
Output is correct |
17 |
Correct |
15 ms |
24000 KB |
Output is correct |
18 |
Correct |
16 ms |
23956 KB |
Output is correct |
19 |
Correct |
232 ms |
38020 KB |
Output is correct |
20 |
Correct |
201 ms |
38060 KB |
Output is correct |
21 |
Correct |
191 ms |
37416 KB |
Output is correct |
22 |
Correct |
182 ms |
37400 KB |
Output is correct |
23 |
Correct |
180 ms |
37508 KB |
Output is correct |
24 |
Correct |
159 ms |
35180 KB |
Output is correct |
25 |
Correct |
153 ms |
35292 KB |
Output is correct |
26 |
Correct |
175 ms |
35492 KB |
Output is correct |
27 |
Correct |
175 ms |
35456 KB |
Output is correct |
28 |
Correct |
177 ms |
35620 KB |
Output is correct |
29 |
Correct |
176 ms |
35984 KB |
Output is correct |
30 |
Correct |
225 ms |
36028 KB |
Output is correct |
31 |
Correct |
176 ms |
35980 KB |
Output is correct |
32 |
Correct |
172 ms |
35976 KB |
Output is correct |
33 |
Correct |
194 ms |
36236 KB |
Output is correct |
34 |
Correct |
155 ms |
34808 KB |
Output is correct |
35 |
Correct |
148 ms |
34724 KB |
Output is correct |
36 |
Correct |
141 ms |
34624 KB |
Output is correct |
37 |
Correct |
142 ms |
34708 KB |
Output is correct |
38 |
Correct |
154 ms |
34812 KB |
Output is correct |
39 |
Correct |
180 ms |
34876 KB |
Output is correct |
40 |
Correct |
134 ms |
32988 KB |
Output is correct |
41 |
Correct |
160 ms |
33820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
23764 KB |
Output is correct |
2 |
Correct |
13 ms |
23764 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23764 KB |
Output is correct |
5 |
Correct |
12 ms |
23820 KB |
Output is correct |
6 |
Correct |
11 ms |
23796 KB |
Output is correct |
7 |
Correct |
12 ms |
23832 KB |
Output is correct |
8 |
Correct |
13 ms |
23820 KB |
Output is correct |
9 |
Correct |
13 ms |
23820 KB |
Output is correct |
10 |
Correct |
12 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
23892 KB |
Output is correct |
12 |
Correct |
16 ms |
24032 KB |
Output is correct |
13 |
Correct |
15 ms |
24056 KB |
Output is correct |
14 |
Correct |
17 ms |
24076 KB |
Output is correct |
15 |
Correct |
17 ms |
24192 KB |
Output is correct |
16 |
Correct |
15 ms |
24056 KB |
Output is correct |
17 |
Correct |
15 ms |
24000 KB |
Output is correct |
18 |
Correct |
16 ms |
23956 KB |
Output is correct |
19 |
Correct |
1218 ms |
60592 KB |
Output is correct |
20 |
Correct |
1191 ms |
60624 KB |
Output is correct |
21 |
Correct |
1299 ms |
60536 KB |
Output is correct |
22 |
Correct |
1201 ms |
60672 KB |
Output is correct |
23 |
Correct |
1025 ms |
52348 KB |
Output is correct |
24 |
Correct |
98 ms |
27596 KB |
Output is correct |
25 |
Correct |
101 ms |
27300 KB |
Output is correct |
26 |
Correct |
80 ms |
26420 KB |
Output is correct |
27 |
Correct |
82 ms |
26472 KB |
Output is correct |
28 |
Correct |
90 ms |
26636 KB |
Output is correct |
29 |
Correct |
75 ms |
26124 KB |
Output is correct |
30 |
Correct |
72 ms |
26172 KB |
Output is correct |
31 |
Correct |
75 ms |
26452 KB |
Output is correct |
32 |
Correct |
46 ms |
25600 KB |
Output is correct |
33 |
Correct |
74 ms |
28084 KB |
Output is correct |
34 |
Correct |
232 ms |
38020 KB |
Output is correct |
35 |
Correct |
201 ms |
38060 KB |
Output is correct |
36 |
Correct |
191 ms |
37416 KB |
Output is correct |
37 |
Correct |
182 ms |
37400 KB |
Output is correct |
38 |
Correct |
180 ms |
37508 KB |
Output is correct |
39 |
Correct |
159 ms |
35180 KB |
Output is correct |
40 |
Correct |
153 ms |
35292 KB |
Output is correct |
41 |
Correct |
175 ms |
35492 KB |
Output is correct |
42 |
Correct |
175 ms |
35456 KB |
Output is correct |
43 |
Correct |
177 ms |
35620 KB |
Output is correct |
44 |
Correct |
176 ms |
35984 KB |
Output is correct |
45 |
Correct |
225 ms |
36028 KB |
Output is correct |
46 |
Correct |
176 ms |
35980 KB |
Output is correct |
47 |
Correct |
172 ms |
35976 KB |
Output is correct |
48 |
Correct |
194 ms |
36236 KB |
Output is correct |
49 |
Correct |
155 ms |
34808 KB |
Output is correct |
50 |
Correct |
148 ms |
34724 KB |
Output is correct |
51 |
Correct |
141 ms |
34624 KB |
Output is correct |
52 |
Correct |
142 ms |
34708 KB |
Output is correct |
53 |
Correct |
154 ms |
34812 KB |
Output is correct |
54 |
Correct |
180 ms |
34876 KB |
Output is correct |
55 |
Correct |
134 ms |
32988 KB |
Output is correct |
56 |
Correct |
160 ms |
33820 KB |
Output is correct |
57 |
Correct |
1219 ms |
93728 KB |
Output is correct |
58 |
Correct |
1273 ms |
93716 KB |
Output is correct |
59 |
Correct |
1189 ms |
92144 KB |
Output is correct |
60 |
Correct |
1223 ms |
92148 KB |
Output is correct |
61 |
Correct |
1169 ms |
92212 KB |
Output is correct |
62 |
Correct |
1160 ms |
92116 KB |
Output is correct |
63 |
Correct |
809 ms |
80800 KB |
Output is correct |
64 |
Correct |
780 ms |
80636 KB |
Output is correct |
65 |
Correct |
986 ms |
83776 KB |
Output is correct |
66 |
Correct |
1073 ms |
83828 KB |
Output is correct |
67 |
Correct |
991 ms |
83812 KB |
Output is correct |
68 |
Correct |
1043 ms |
85440 KB |
Output is correct |
69 |
Correct |
1060 ms |
85436 KB |
Output is correct |
70 |
Correct |
1072 ms |
85288 KB |
Output is correct |
71 |
Correct |
1073 ms |
85064 KB |
Output is correct |
72 |
Correct |
1032 ms |
85244 KB |
Output is correct |
73 |
Correct |
706 ms |
76408 KB |
Output is correct |
74 |
Correct |
732 ms |
77412 KB |
Output is correct |
75 |
Correct |
719 ms |
76580 KB |
Output is correct |
76 |
Correct |
761 ms |
76784 KB |
Output is correct |
77 |
Correct |
769 ms |
76256 KB |
Output is correct |
78 |
Correct |
928 ms |
80280 KB |
Output is correct |
79 |
Correct |
775 ms |
68628 KB |
Output is correct |
80 |
Correct |
948 ms |
74692 KB |
Output is correct |