# include <bits/stdc++.h>
# define pb push_back
# define ff first
# define ss second
# define nl "\n"
# define sz(x) ((int)(x).size())
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll maxn = 1e6 + 25;
const ll inf = 1e18 + 0;
const ll mod = 1e9 + 7;
const ll dx[] = {-1, 1, 0, 0};
const ll dy[] = {0, 0, -1, 1};
using namespace std;
struct query
{
ll L, K, ID;
};
vector <query> q[maxn];
ll n, m, a[maxn];
ll t[maxn * 4];
ll ans[maxn];
void update (ll pos, ll x, ll v = 1, ll tl = 1, ll tr = n)
{
if (tl == tr)
{
t[v] = max(t[v], x);
return;
}
ll tm = (tl + tr) >> 1;
if (pos <= tm) update(pos, x, v * 2, tl, tm);
else update(pos, x, v * 2 + 1, tm + 1, tr);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
ll get (ll l, ll r, ll v = 1, ll tl = 1, ll tr = n)
{
if (tr < l || r < tl) return 0;
if (l <= tl && tr <= r) return t[v];
ll tm = (tl + tr) >> 1;
return max(get(l, r, v * 2, tl, tm), get(l, r, v * 2 + 1, tm + 1, tr));
}
void ma1n (/* SABR */)
{
cin >> n >> m;
for (ll i = 1; i <= n; ++i)
{
cin >> a[i];
}
for (ll i = 1; i <= m; ++i)
{
ll l, r, k;
cin >> l >> r >> k;
q[r].pb({l, k, i});
}
vector <ll> v;
for (ll r = 1; r <= n; ++r)
{
while (!v.empty() && a[v.back()] <= a[r]) v.pop_back();
if (!v.empty())
{
update(v.back(), a[r] + a[v.back()]);
}
for (query i : q[r])
{
ll l = i.L, k = i.K, id = i.ID;
if (get(l, r) <= k)
{
ans[id] = 1;
}
}
v.pb(r);
}
for (ll i = 1; i <= m; ++i) cout << ans[i] << nl;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
// freopen("file.in", "r", stdin);
// freopen("file.out", "w", stdout);
int ttt = 1;
// cin >> ttt;
for (int test = 1; test <= ttt; ++test)
{
// cout << "Case " << test << ":" << ' ';
ma1n();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23804 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23744 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
14 ms |
23868 KB |
Output is correct |
7 |
Correct |
12 ms |
23772 KB |
Output is correct |
8 |
Correct |
12 ms |
23824 KB |
Output is correct |
9 |
Correct |
12 ms |
23756 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23804 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23744 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
14 ms |
23868 KB |
Output is correct |
7 |
Correct |
12 ms |
23772 KB |
Output is correct |
8 |
Correct |
12 ms |
23824 KB |
Output is correct |
9 |
Correct |
12 ms |
23756 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
24020 KB |
Output is correct |
12 |
Correct |
14 ms |
24208 KB |
Output is correct |
13 |
Correct |
14 ms |
24136 KB |
Output is correct |
14 |
Correct |
17 ms |
24276 KB |
Output is correct |
15 |
Correct |
16 ms |
24276 KB |
Output is correct |
16 |
Correct |
15 ms |
24148 KB |
Output is correct |
17 |
Correct |
14 ms |
24208 KB |
Output is correct |
18 |
Correct |
15 ms |
24192 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1177 ms |
82548 KB |
Output is correct |
2 |
Correct |
1250 ms |
98228 KB |
Output is correct |
3 |
Correct |
1233 ms |
95620 KB |
Output is correct |
4 |
Correct |
1244 ms |
95892 KB |
Output is correct |
5 |
Correct |
1065 ms |
87096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
94 ms |
30844 KB |
Output is correct |
2 |
Correct |
87 ms |
33080 KB |
Output is correct |
3 |
Correct |
92 ms |
30976 KB |
Output is correct |
4 |
Correct |
81 ms |
30816 KB |
Output is correct |
5 |
Correct |
84 ms |
30824 KB |
Output is correct |
6 |
Correct |
68 ms |
29920 KB |
Output is correct |
7 |
Correct |
70 ms |
30004 KB |
Output is correct |
8 |
Correct |
74 ms |
30144 KB |
Output is correct |
9 |
Correct |
45 ms |
28980 KB |
Output is correct |
10 |
Correct |
73 ms |
30248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23804 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23744 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
14 ms |
23868 KB |
Output is correct |
7 |
Correct |
12 ms |
23772 KB |
Output is correct |
8 |
Correct |
12 ms |
23824 KB |
Output is correct |
9 |
Correct |
12 ms |
23756 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
24020 KB |
Output is correct |
12 |
Correct |
14 ms |
24208 KB |
Output is correct |
13 |
Correct |
14 ms |
24136 KB |
Output is correct |
14 |
Correct |
17 ms |
24276 KB |
Output is correct |
15 |
Correct |
16 ms |
24276 KB |
Output is correct |
16 |
Correct |
15 ms |
24148 KB |
Output is correct |
17 |
Correct |
14 ms |
24208 KB |
Output is correct |
18 |
Correct |
15 ms |
24192 KB |
Output is correct |
19 |
Correct |
217 ms |
44572 KB |
Output is correct |
20 |
Correct |
217 ms |
44452 KB |
Output is correct |
21 |
Correct |
187 ms |
45004 KB |
Output is correct |
22 |
Correct |
184 ms |
44900 KB |
Output is correct |
23 |
Correct |
188 ms |
45048 KB |
Output is correct |
24 |
Correct |
150 ms |
40836 KB |
Output is correct |
25 |
Correct |
152 ms |
40780 KB |
Output is correct |
26 |
Correct |
174 ms |
40564 KB |
Output is correct |
27 |
Correct |
171 ms |
40644 KB |
Output is correct |
28 |
Correct |
179 ms |
40668 KB |
Output is correct |
29 |
Correct |
189 ms |
40404 KB |
Output is correct |
30 |
Correct |
179 ms |
40440 KB |
Output is correct |
31 |
Correct |
183 ms |
40376 KB |
Output is correct |
32 |
Correct |
185 ms |
40460 KB |
Output is correct |
33 |
Correct |
181 ms |
40380 KB |
Output is correct |
34 |
Correct |
154 ms |
40176 KB |
Output is correct |
35 |
Correct |
148 ms |
40200 KB |
Output is correct |
36 |
Correct |
141 ms |
40044 KB |
Output is correct |
37 |
Correct |
147 ms |
39988 KB |
Output is correct |
38 |
Correct |
144 ms |
40240 KB |
Output is correct |
39 |
Correct |
167 ms |
39964 KB |
Output is correct |
40 |
Correct |
125 ms |
36820 KB |
Output is correct |
41 |
Correct |
171 ms |
37924 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
12 ms |
23804 KB |
Output is correct |
2 |
Correct |
12 ms |
23764 KB |
Output is correct |
3 |
Correct |
13 ms |
23764 KB |
Output is correct |
4 |
Correct |
13 ms |
23744 KB |
Output is correct |
5 |
Correct |
12 ms |
23764 KB |
Output is correct |
6 |
Correct |
14 ms |
23868 KB |
Output is correct |
7 |
Correct |
12 ms |
23772 KB |
Output is correct |
8 |
Correct |
12 ms |
23824 KB |
Output is correct |
9 |
Correct |
12 ms |
23756 KB |
Output is correct |
10 |
Correct |
13 ms |
23764 KB |
Output is correct |
11 |
Correct |
14 ms |
24020 KB |
Output is correct |
12 |
Correct |
14 ms |
24208 KB |
Output is correct |
13 |
Correct |
14 ms |
24136 KB |
Output is correct |
14 |
Correct |
17 ms |
24276 KB |
Output is correct |
15 |
Correct |
16 ms |
24276 KB |
Output is correct |
16 |
Correct |
15 ms |
24148 KB |
Output is correct |
17 |
Correct |
14 ms |
24208 KB |
Output is correct |
18 |
Correct |
15 ms |
24192 KB |
Output is correct |
19 |
Correct |
1177 ms |
82548 KB |
Output is correct |
20 |
Correct |
1250 ms |
98228 KB |
Output is correct |
21 |
Correct |
1233 ms |
95620 KB |
Output is correct |
22 |
Correct |
1244 ms |
95892 KB |
Output is correct |
23 |
Correct |
1065 ms |
87096 KB |
Output is correct |
24 |
Correct |
94 ms |
30844 KB |
Output is correct |
25 |
Correct |
87 ms |
33080 KB |
Output is correct |
26 |
Correct |
92 ms |
30976 KB |
Output is correct |
27 |
Correct |
81 ms |
30816 KB |
Output is correct |
28 |
Correct |
84 ms |
30824 KB |
Output is correct |
29 |
Correct |
68 ms |
29920 KB |
Output is correct |
30 |
Correct |
70 ms |
30004 KB |
Output is correct |
31 |
Correct |
74 ms |
30144 KB |
Output is correct |
32 |
Correct |
45 ms |
28980 KB |
Output is correct |
33 |
Correct |
73 ms |
30248 KB |
Output is correct |
34 |
Correct |
217 ms |
44572 KB |
Output is correct |
35 |
Correct |
217 ms |
44452 KB |
Output is correct |
36 |
Correct |
187 ms |
45004 KB |
Output is correct |
37 |
Correct |
184 ms |
44900 KB |
Output is correct |
38 |
Correct |
188 ms |
45048 KB |
Output is correct |
39 |
Correct |
150 ms |
40836 KB |
Output is correct |
40 |
Correct |
152 ms |
40780 KB |
Output is correct |
41 |
Correct |
174 ms |
40564 KB |
Output is correct |
42 |
Correct |
171 ms |
40644 KB |
Output is correct |
43 |
Correct |
179 ms |
40668 KB |
Output is correct |
44 |
Correct |
189 ms |
40404 KB |
Output is correct |
45 |
Correct |
179 ms |
40440 KB |
Output is correct |
46 |
Correct |
183 ms |
40376 KB |
Output is correct |
47 |
Correct |
185 ms |
40460 KB |
Output is correct |
48 |
Correct |
181 ms |
40380 KB |
Output is correct |
49 |
Correct |
154 ms |
40176 KB |
Output is correct |
50 |
Correct |
148 ms |
40200 KB |
Output is correct |
51 |
Correct |
141 ms |
40044 KB |
Output is correct |
52 |
Correct |
147 ms |
39988 KB |
Output is correct |
53 |
Correct |
144 ms |
40240 KB |
Output is correct |
54 |
Correct |
167 ms |
39964 KB |
Output is correct |
55 |
Correct |
125 ms |
36820 KB |
Output is correct |
56 |
Correct |
171 ms |
37924 KB |
Output is correct |
57 |
Correct |
1264 ms |
103960 KB |
Output is correct |
58 |
Correct |
1245 ms |
104200 KB |
Output is correct |
59 |
Correct |
1209 ms |
104828 KB |
Output is correct |
60 |
Correct |
1180 ms |
105076 KB |
Output is correct |
61 |
Correct |
1181 ms |
118172 KB |
Output is correct |
62 |
Correct |
1170 ms |
104744 KB |
Output is correct |
63 |
Correct |
818 ms |
90156 KB |
Output is correct |
64 |
Correct |
790 ms |
90040 KB |
Output is correct |
65 |
Correct |
1134 ms |
88868 KB |
Output is correct |
66 |
Correct |
1179 ms |
88556 KB |
Output is correct |
67 |
Correct |
1281 ms |
102004 KB |
Output is correct |
68 |
Correct |
1166 ms |
87648 KB |
Output is correct |
69 |
Correct |
1192 ms |
87660 KB |
Output is correct |
70 |
Correct |
1170 ms |
87664 KB |
Output is correct |
71 |
Correct |
1195 ms |
101116 KB |
Output is correct |
72 |
Correct |
1099 ms |
101032 KB |
Output is correct |
73 |
Correct |
719 ms |
91048 KB |
Output is correct |
74 |
Correct |
724 ms |
90932 KB |
Output is correct |
75 |
Correct |
704 ms |
91028 KB |
Output is correct |
76 |
Correct |
766 ms |
90328 KB |
Output is correct |
77 |
Correct |
704 ms |
90184 KB |
Output is correct |
78 |
Correct |
884 ms |
104596 KB |
Output is correct |
79 |
Correct |
671 ms |
88148 KB |
Output is correct |
80 |
Correct |
872 ms |
95376 KB |
Output is correct |