#include <iostream>
#include <stack>
#include <cstring>
#include <vector>
#include <algorithm>
#include <deque>
#include <set>
#include <utility>
#include <array>
using namespace std;
#define ALL(x) x.begin(), x.end()
#define ShinLena cin.tie(nullptr)->sync_with_stdio(false);
using ll = long long;
#define N 1000005
int n, m, a[N], t[N<<1], d[N<<1], e[N];
array<int, 4> b[N];
void push(int v, int l, int r)
{
if (!d[v]) return;
t[v] += d[v];
if (l ^ r)
{
int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
d[vl] += d[v], d[vr] += d[v];
}
d[v] = 0;
}
void add(int x, int y, int k, int v, int l, int r)
{
push(v, l, r);
if (y < l || r < x) return;
if (x <= l && r <= y) { d[v] = k; push(v, l, r); return; }
int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
add(x, y, k, vl, l, m);
add(x, y, k, vr, m+1, r);
t[v] = max(t[vl], t[vr]);
}
int query(int x, int y, int v, int l, int r)
{
push(v, l, r);
if (y < l || r < x) return 0;
if (x <= l && r <= y) return t[v];
int m = (l+r)/2, vl=v+1, vr=v+(m-l+1)*2;
return max(query(x, y, vl, l, m), query(x, y, vr, m+1, r));
}
std::stack<int> s;
int main()
{
ShinLena;
cin >> n >> m;
for (int i = 1; i <= n; ++i) cin >> a[i];
for (int i = 0; i < m; ++i) cin >> b[i][0] >> b[i][1] >> b[i][2], b[i][3] = i;
sort(b, b+m);
s.push(n+1); a[n+1] = 1e9+1;
int j = m-1;
for (int i = n; i >= 1; --i)
{
while (s.size() && a[s.top()] < a[i])
{
int x = s.top();
s.pop();
add(x, x, a[x], 0, 1, n);
add(x+1, s.top() - 1, -a[x], 0, 1, n);
}
add(i+1, s.top() - 1, a[i], 0, 1, n);
s.push(i);
for (; j >= 0 && b[j][0] == i; --j) e[b[j][3]] = b[j][2] >= query(i+1, b[j][1], 0, 1, n);
}
for (int i = 0; i < m; ++i) cout << e[i] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6612 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6612 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
3 ms |
4700 KB |
Output is correct |
12 |
Correct |
6 ms |
4956 KB |
Output is correct |
13 |
Correct |
5 ms |
4700 KB |
Output is correct |
14 |
Correct |
7 ms |
6876 KB |
Output is correct |
15 |
Correct |
6 ms |
4852 KB |
Output is correct |
16 |
Correct |
5 ms |
4700 KB |
Output is correct |
17 |
Correct |
4 ms |
4700 KB |
Output is correct |
18 |
Correct |
5 ms |
4700 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1608 ms |
41644 KB |
Output is correct |
2 |
Correct |
1586 ms |
74304 KB |
Output is correct |
3 |
Correct |
1632 ms |
74304 KB |
Output is correct |
4 |
Correct |
1623 ms |
74268 KB |
Output is correct |
5 |
Correct |
1068 ms |
70596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
123 ms |
9808 KB |
Output is correct |
2 |
Correct |
122 ms |
11580 KB |
Output is correct |
3 |
Correct |
84 ms |
10112 KB |
Output is correct |
4 |
Correct |
89 ms |
10148 KB |
Output is correct |
5 |
Correct |
86 ms |
10044 KB |
Output is correct |
6 |
Correct |
84 ms |
9852 KB |
Output is correct |
7 |
Correct |
84 ms |
9812 KB |
Output is correct |
8 |
Correct |
103 ms |
9968 KB |
Output is correct |
9 |
Correct |
41 ms |
8284 KB |
Output is correct |
10 |
Correct |
97 ms |
9960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6612 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
3 ms |
4700 KB |
Output is correct |
12 |
Correct |
6 ms |
4956 KB |
Output is correct |
13 |
Correct |
5 ms |
4700 KB |
Output is correct |
14 |
Correct |
7 ms |
6876 KB |
Output is correct |
15 |
Correct |
6 ms |
4852 KB |
Output is correct |
16 |
Correct |
5 ms |
4700 KB |
Output is correct |
17 |
Correct |
4 ms |
4700 KB |
Output is correct |
18 |
Correct |
5 ms |
4700 KB |
Output is correct |
19 |
Correct |
286 ms |
20912 KB |
Output is correct |
20 |
Correct |
272 ms |
20904 KB |
Output is correct |
21 |
Correct |
265 ms |
18940 KB |
Output is correct |
22 |
Correct |
267 ms |
20564 KB |
Output is correct |
23 |
Correct |
263 ms |
18776 KB |
Output is correct |
24 |
Correct |
192 ms |
17948 KB |
Output is correct |
25 |
Correct |
180 ms |
17768 KB |
Output is correct |
26 |
Correct |
189 ms |
18004 KB |
Output is correct |
27 |
Correct |
189 ms |
18108 KB |
Output is correct |
28 |
Correct |
196 ms |
17892 KB |
Output is correct |
29 |
Correct |
189 ms |
18172 KB |
Output is correct |
30 |
Correct |
190 ms |
18084 KB |
Output is correct |
31 |
Correct |
193 ms |
18180 KB |
Output is correct |
32 |
Correct |
197 ms |
18004 KB |
Output is correct |
33 |
Correct |
191 ms |
18004 KB |
Output is correct |
34 |
Correct |
189 ms |
17744 KB |
Output is correct |
35 |
Correct |
179 ms |
17692 KB |
Output is correct |
36 |
Correct |
180 ms |
17500 KB |
Output is correct |
37 |
Correct |
175 ms |
17492 KB |
Output is correct |
38 |
Correct |
190 ms |
17700 KB |
Output is correct |
39 |
Correct |
201 ms |
17000 KB |
Output is correct |
40 |
Correct |
163 ms |
15696 KB |
Output is correct |
41 |
Correct |
210 ms |
16728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
2 ms |
6612 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
2 ms |
4440 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
3 ms |
4700 KB |
Output is correct |
12 |
Correct |
6 ms |
4956 KB |
Output is correct |
13 |
Correct |
5 ms |
4700 KB |
Output is correct |
14 |
Correct |
7 ms |
6876 KB |
Output is correct |
15 |
Correct |
6 ms |
4852 KB |
Output is correct |
16 |
Correct |
5 ms |
4700 KB |
Output is correct |
17 |
Correct |
4 ms |
4700 KB |
Output is correct |
18 |
Correct |
5 ms |
4700 KB |
Output is correct |
19 |
Correct |
1608 ms |
41644 KB |
Output is correct |
20 |
Correct |
1586 ms |
74304 KB |
Output is correct |
21 |
Correct |
1632 ms |
74304 KB |
Output is correct |
22 |
Correct |
1623 ms |
74268 KB |
Output is correct |
23 |
Correct |
1068 ms |
70596 KB |
Output is correct |
24 |
Correct |
123 ms |
9808 KB |
Output is correct |
25 |
Correct |
122 ms |
11580 KB |
Output is correct |
26 |
Correct |
84 ms |
10112 KB |
Output is correct |
27 |
Correct |
89 ms |
10148 KB |
Output is correct |
28 |
Correct |
86 ms |
10044 KB |
Output is correct |
29 |
Correct |
84 ms |
9852 KB |
Output is correct |
30 |
Correct |
84 ms |
9812 KB |
Output is correct |
31 |
Correct |
103 ms |
9968 KB |
Output is correct |
32 |
Correct |
41 ms |
8284 KB |
Output is correct |
33 |
Correct |
97 ms |
9960 KB |
Output is correct |
34 |
Correct |
286 ms |
20912 KB |
Output is correct |
35 |
Correct |
272 ms |
20904 KB |
Output is correct |
36 |
Correct |
265 ms |
18940 KB |
Output is correct |
37 |
Correct |
267 ms |
20564 KB |
Output is correct |
38 |
Correct |
263 ms |
18776 KB |
Output is correct |
39 |
Correct |
192 ms |
17948 KB |
Output is correct |
40 |
Correct |
180 ms |
17768 KB |
Output is correct |
41 |
Correct |
189 ms |
18004 KB |
Output is correct |
42 |
Correct |
189 ms |
18108 KB |
Output is correct |
43 |
Correct |
196 ms |
17892 KB |
Output is correct |
44 |
Correct |
189 ms |
18172 KB |
Output is correct |
45 |
Correct |
190 ms |
18084 KB |
Output is correct |
46 |
Correct |
193 ms |
18180 KB |
Output is correct |
47 |
Correct |
197 ms |
18004 KB |
Output is correct |
48 |
Correct |
191 ms |
18004 KB |
Output is correct |
49 |
Correct |
189 ms |
17744 KB |
Output is correct |
50 |
Correct |
179 ms |
17692 KB |
Output is correct |
51 |
Correct |
180 ms |
17500 KB |
Output is correct |
52 |
Correct |
175 ms |
17492 KB |
Output is correct |
53 |
Correct |
190 ms |
17700 KB |
Output is correct |
54 |
Correct |
201 ms |
17000 KB |
Output is correct |
55 |
Correct |
163 ms |
15696 KB |
Output is correct |
56 |
Correct |
210 ms |
16728 KB |
Output is correct |
57 |
Correct |
1645 ms |
74792 KB |
Output is correct |
58 |
Correct |
1562 ms |
74988 KB |
Output is correct |
59 |
Correct |
1489 ms |
74968 KB |
Output is correct |
60 |
Correct |
1497 ms |
75160 KB |
Output is correct |
61 |
Correct |
1502 ms |
74864 KB |
Output is correct |
62 |
Correct |
1513 ms |
74772 KB |
Output is correct |
63 |
Correct |
967 ms |
69736 KB |
Output is correct |
64 |
Correct |
973 ms |
69712 KB |
Output is correct |
65 |
Correct |
1036 ms |
71012 KB |
Output is correct |
66 |
Correct |
1030 ms |
71364 KB |
Output is correct |
67 |
Correct |
1078 ms |
71320 KB |
Output is correct |
68 |
Correct |
1109 ms |
70876 KB |
Output is correct |
69 |
Correct |
1062 ms |
71256 KB |
Output is correct |
70 |
Correct |
1059 ms |
71304 KB |
Output is correct |
71 |
Correct |
1117 ms |
71216 KB |
Output is correct |
72 |
Correct |
1078 ms |
71200 KB |
Output is correct |
73 |
Correct |
961 ms |
67924 KB |
Output is correct |
74 |
Correct |
966 ms |
68860 KB |
Output is correct |
75 |
Correct |
951 ms |
67792 KB |
Output is correct |
76 |
Correct |
951 ms |
67924 KB |
Output is correct |
77 |
Correct |
949 ms |
67992 KB |
Output is correct |
78 |
Correct |
1168 ms |
66304 KB |
Output is correct |
79 |
Correct |
803 ms |
53336 KB |
Output is correct |
80 |
Correct |
1281 ms |
65892 KB |
Output is correct |