#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "Line(" << __LINE__ << ") -> " << #x << " is " << (x) << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 1e6 + 7, C = 1e9 + 7;
int a[N], ans[N];
V<array<int, 3>> G[N];
int bit[N];
void add(int pos, int val) {
for(; pos < N; pos += pos & -pos)
bit[pos] = max(bit[pos], val);
}
int qry(int pos) {
int res = 0;
for(; pos; pos -= pos & -pos)
res = max(res, bit[pos]);
return res;
}
signed main()
{
IO_OP;
int n, m;
cin >> n >> m;
for(int i = 1; i <= n; i++)
cin >> a[i];
for(int i = 0; i < m; i++) {
int l, r, k;
cin >> l >> r >> k;
G[l].PB({r, k, i});
}
a[n + 1] = INF;
deque<int> cut;
cut.PB(n + 1);
for(int i = n; i >= 1; i--) {
while(a[i] > a[cut[0]]) {
add(cut[0], a[cut[0]] + a[i]);
cut.pop_front();
}
cut.push_front(i);
for(auto qq:G[i]) {
int r = qq[0], k = qq[1], qi = qq[2];
int tt = qry(r);
if(tt <= k) ans[qi] = 1;
else ans[qi] = 0;
}
}
for(int i = 0; i < m; i++)
cout << ans[i] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
18 ms |
23916 KB |
Output is correct |
4 |
Correct |
17 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
24044 KB |
Output is correct |
6 |
Correct |
18 ms |
23916 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23916 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
18 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
18 ms |
23916 KB |
Output is correct |
4 |
Correct |
17 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
24044 KB |
Output is correct |
6 |
Correct |
18 ms |
23916 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23916 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
18 ms |
23916 KB |
Output is correct |
11 |
Correct |
18 ms |
24044 KB |
Output is correct |
12 |
Correct |
19 ms |
24044 KB |
Output is correct |
13 |
Correct |
19 ms |
24172 KB |
Output is correct |
14 |
Correct |
23 ms |
24172 KB |
Output is correct |
15 |
Correct |
24 ms |
24320 KB |
Output is correct |
16 |
Correct |
23 ms |
24172 KB |
Output is correct |
17 |
Correct |
19 ms |
24172 KB |
Output is correct |
18 |
Correct |
19 ms |
24172 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1020 ms |
59300 KB |
Output is correct |
2 |
Correct |
1105 ms |
59528 KB |
Output is correct |
3 |
Correct |
1006 ms |
59244 KB |
Output is correct |
4 |
Correct |
1020 ms |
59244 KB |
Output is correct |
5 |
Correct |
930 ms |
59564 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
27500 KB |
Output is correct |
2 |
Correct |
82 ms |
27520 KB |
Output is correct |
3 |
Correct |
82 ms |
27500 KB |
Output is correct |
4 |
Correct |
79 ms |
27756 KB |
Output is correct |
5 |
Correct |
85 ms |
27628 KB |
Output is correct |
6 |
Correct |
65 ms |
26988 KB |
Output is correct |
7 |
Correct |
66 ms |
26988 KB |
Output is correct |
8 |
Correct |
84 ms |
27436 KB |
Output is correct |
9 |
Correct |
52 ms |
26296 KB |
Output is correct |
10 |
Correct |
76 ms |
27300 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
18 ms |
23916 KB |
Output is correct |
4 |
Correct |
17 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
24044 KB |
Output is correct |
6 |
Correct |
18 ms |
23916 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23916 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
18 ms |
23916 KB |
Output is correct |
11 |
Correct |
18 ms |
24044 KB |
Output is correct |
12 |
Correct |
19 ms |
24044 KB |
Output is correct |
13 |
Correct |
19 ms |
24172 KB |
Output is correct |
14 |
Correct |
23 ms |
24172 KB |
Output is correct |
15 |
Correct |
24 ms |
24320 KB |
Output is correct |
16 |
Correct |
23 ms |
24172 KB |
Output is correct |
17 |
Correct |
19 ms |
24172 KB |
Output is correct |
18 |
Correct |
19 ms |
24172 KB |
Output is correct |
19 |
Correct |
194 ms |
31212 KB |
Output is correct |
20 |
Correct |
195 ms |
37740 KB |
Output is correct |
21 |
Correct |
163 ms |
37120 KB |
Output is correct |
22 |
Correct |
164 ms |
37068 KB |
Output is correct |
23 |
Correct |
166 ms |
37228 KB |
Output is correct |
24 |
Correct |
152 ms |
36972 KB |
Output is correct |
25 |
Correct |
149 ms |
36972 KB |
Output is correct |
26 |
Correct |
169 ms |
37228 KB |
Output is correct |
27 |
Correct |
190 ms |
37356 KB |
Output is correct |
28 |
Correct |
184 ms |
37228 KB |
Output is correct |
29 |
Correct |
180 ms |
37816 KB |
Output is correct |
30 |
Correct |
186 ms |
37868 KB |
Output is correct |
31 |
Correct |
183 ms |
37740 KB |
Output is correct |
32 |
Correct |
178 ms |
37740 KB |
Output is correct |
33 |
Correct |
186 ms |
37740 KB |
Output is correct |
34 |
Correct |
139 ms |
36112 KB |
Output is correct |
35 |
Correct |
134 ms |
35948 KB |
Output is correct |
36 |
Correct |
128 ms |
35948 KB |
Output is correct |
37 |
Correct |
129 ms |
35948 KB |
Output is correct |
38 |
Correct |
140 ms |
35948 KB |
Output is correct |
39 |
Correct |
155 ms |
35492 KB |
Output is correct |
40 |
Correct |
128 ms |
33952 KB |
Output is correct |
41 |
Correct |
148 ms |
34976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
23916 KB |
Output is correct |
2 |
Correct |
16 ms |
23788 KB |
Output is correct |
3 |
Correct |
18 ms |
23916 KB |
Output is correct |
4 |
Correct |
17 ms |
23916 KB |
Output is correct |
5 |
Correct |
17 ms |
24044 KB |
Output is correct |
6 |
Correct |
18 ms |
23916 KB |
Output is correct |
7 |
Correct |
17 ms |
23916 KB |
Output is correct |
8 |
Correct |
16 ms |
23916 KB |
Output is correct |
9 |
Correct |
17 ms |
23916 KB |
Output is correct |
10 |
Correct |
18 ms |
23916 KB |
Output is correct |
11 |
Correct |
18 ms |
24044 KB |
Output is correct |
12 |
Correct |
19 ms |
24044 KB |
Output is correct |
13 |
Correct |
19 ms |
24172 KB |
Output is correct |
14 |
Correct |
23 ms |
24172 KB |
Output is correct |
15 |
Correct |
24 ms |
24320 KB |
Output is correct |
16 |
Correct |
23 ms |
24172 KB |
Output is correct |
17 |
Correct |
19 ms |
24172 KB |
Output is correct |
18 |
Correct |
19 ms |
24172 KB |
Output is correct |
19 |
Correct |
1020 ms |
59300 KB |
Output is correct |
20 |
Correct |
1105 ms |
59528 KB |
Output is correct |
21 |
Correct |
1006 ms |
59244 KB |
Output is correct |
22 |
Correct |
1020 ms |
59244 KB |
Output is correct |
23 |
Correct |
930 ms |
59564 KB |
Output is correct |
24 |
Correct |
89 ms |
27500 KB |
Output is correct |
25 |
Correct |
82 ms |
27520 KB |
Output is correct |
26 |
Correct |
82 ms |
27500 KB |
Output is correct |
27 |
Correct |
79 ms |
27756 KB |
Output is correct |
28 |
Correct |
85 ms |
27628 KB |
Output is correct |
29 |
Correct |
65 ms |
26988 KB |
Output is correct |
30 |
Correct |
66 ms |
26988 KB |
Output is correct |
31 |
Correct |
84 ms |
27436 KB |
Output is correct |
32 |
Correct |
52 ms |
26296 KB |
Output is correct |
33 |
Correct |
76 ms |
27300 KB |
Output is correct |
34 |
Correct |
194 ms |
31212 KB |
Output is correct |
35 |
Correct |
195 ms |
37740 KB |
Output is correct |
36 |
Correct |
163 ms |
37120 KB |
Output is correct |
37 |
Correct |
164 ms |
37068 KB |
Output is correct |
38 |
Correct |
166 ms |
37228 KB |
Output is correct |
39 |
Correct |
152 ms |
36972 KB |
Output is correct |
40 |
Correct |
149 ms |
36972 KB |
Output is correct |
41 |
Correct |
169 ms |
37228 KB |
Output is correct |
42 |
Correct |
190 ms |
37356 KB |
Output is correct |
43 |
Correct |
184 ms |
37228 KB |
Output is correct |
44 |
Correct |
180 ms |
37816 KB |
Output is correct |
45 |
Correct |
186 ms |
37868 KB |
Output is correct |
46 |
Correct |
183 ms |
37740 KB |
Output is correct |
47 |
Correct |
178 ms |
37740 KB |
Output is correct |
48 |
Correct |
186 ms |
37740 KB |
Output is correct |
49 |
Correct |
139 ms |
36112 KB |
Output is correct |
50 |
Correct |
134 ms |
35948 KB |
Output is correct |
51 |
Correct |
128 ms |
35948 KB |
Output is correct |
52 |
Correct |
129 ms |
35948 KB |
Output is correct |
53 |
Correct |
140 ms |
35948 KB |
Output is correct |
54 |
Correct |
155 ms |
35492 KB |
Output is correct |
55 |
Correct |
128 ms |
33952 KB |
Output is correct |
56 |
Correct |
148 ms |
34976 KB |
Output is correct |
57 |
Correct |
1036 ms |
93676 KB |
Output is correct |
58 |
Correct |
1082 ms |
85996 KB |
Output is correct |
59 |
Correct |
958 ms |
73196 KB |
Output is correct |
60 |
Correct |
972 ms |
74860 KB |
Output is correct |
61 |
Correct |
992 ms |
73196 KB |
Output is correct |
62 |
Correct |
956 ms |
79468 KB |
Output is correct |
63 |
Correct |
659 ms |
67892 KB |
Output is correct |
64 |
Correct |
692 ms |
67948 KB |
Output is correct |
65 |
Correct |
931 ms |
88044 KB |
Output is correct |
66 |
Correct |
922 ms |
91644 KB |
Output is correct |
67 |
Correct |
986 ms |
91884 KB |
Output is correct |
68 |
Correct |
971 ms |
94116 KB |
Output is correct |
69 |
Correct |
964 ms |
94076 KB |
Output is correct |
70 |
Correct |
955 ms |
74904 KB |
Output is correct |
71 |
Correct |
953 ms |
93292 KB |
Output is correct |
72 |
Correct |
960 ms |
86788 KB |
Output is correct |
73 |
Correct |
598 ms |
69996 KB |
Output is correct |
74 |
Correct |
597 ms |
65388 KB |
Output is correct |
75 |
Correct |
577 ms |
69868 KB |
Output is correct |
76 |
Correct |
592 ms |
58348 KB |
Output is correct |
77 |
Correct |
571 ms |
81644 KB |
Output is correct |
78 |
Correct |
811 ms |
83876 KB |
Output is correct |
79 |
Correct |
635 ms |
73192 KB |
Output is correct |
80 |
Correct |
805 ms |
65680 KB |
Output is correct |