#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 2e5;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T> void vout(T s){cout << s << endl;exit(0);}
ll ans[MAXN];
vector <ll> v[MAXN];
struct qry{
ll l, r, idx, k;
};
bool cmp(qry a, qry b){
if(a.l > b.l)return 1;
if(a.l < b.l)return 0;
return (a.idx < b.idx);
}
ll t[4 * MAXN];
void upd(ll v,ll tl,ll tr,ll pos,ll val)
{
if(tl == tr)
{
t[v] = max(t[v], val);
return;
}
ll tm = (tl + tr) / 2;
if(pos <= tm)
upd(2 * v, tl, tm, pos, val);
else
upd(2 * v + 1, tm + 1, tr, pos, val);
t[v] = max(t[2 * v], t[2 * v + 1]);
}
ll get(ll v,ll tl,ll tr,ll l,ll r)
{
if(l > r)
return 0;
if(tl == l && tr == r)
return t[v];
ll tm = (tl + tr) / 2;
return max(get(2 * v, tl, tm, l, min(r, tm)), get(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
int main(){
ios_base :: sync_with_stdio(0);
cin.tie(0);
ll n, m;
cin >> n >> m;
vector <ll> w(n + 1), le(n + 1);
for(int i = 1; i <= n; i++)cin >> w[i];
w[0] = 1e18;
vector <ll> st;
st.p_b(0);
for(int i = 1; i <= n; i++){
while(w[st.back()] <= w[i])st.pop_back();
le[i] = st.back();
v[le[i]].p_b(i);
st.p_b(i);
}
vector <qry> c(m);
ll uk = n;
for(int i = 0; i < m; i++){
cin >> c[i].l >> c[i].r >> c[i].k;
c[i].idx = i;
}
sort(all(c), cmp);
for(auto kek : c){
while(kek.l < uk){
for(auto j : v[uk - 1]){
upd(1, 1, n, j, w[uk - 1] + w[j]);
}
uk--;
}
ans[kek.idx] = (get(1, 1, n, kek.l, kek.r) <= kek.k);
}
for(int i = 0; i < m; i++)cout << ans[i] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
26744 KB |
Output is correct |
2 |
Correct |
27 ms |
26744 KB |
Output is correct |
3 |
Correct |
26 ms |
26708 KB |
Output is correct |
4 |
Correct |
26 ms |
26744 KB |
Output is correct |
5 |
Correct |
26 ms |
26744 KB |
Output is correct |
6 |
Correct |
25 ms |
26744 KB |
Output is correct |
7 |
Correct |
26 ms |
26744 KB |
Output is correct |
8 |
Correct |
26 ms |
26816 KB |
Output is correct |
9 |
Correct |
26 ms |
26744 KB |
Output is correct |
10 |
Correct |
26 ms |
26744 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
26744 KB |
Output is correct |
2 |
Correct |
27 ms |
26744 KB |
Output is correct |
3 |
Correct |
26 ms |
26708 KB |
Output is correct |
4 |
Correct |
26 ms |
26744 KB |
Output is correct |
5 |
Correct |
26 ms |
26744 KB |
Output is correct |
6 |
Correct |
25 ms |
26744 KB |
Output is correct |
7 |
Correct |
26 ms |
26744 KB |
Output is correct |
8 |
Correct |
26 ms |
26816 KB |
Output is correct |
9 |
Correct |
26 ms |
26744 KB |
Output is correct |
10 |
Correct |
26 ms |
26744 KB |
Output is correct |
11 |
Correct |
29 ms |
26872 KB |
Output is correct |
12 |
Correct |
30 ms |
27128 KB |
Output is correct |
13 |
Correct |
31 ms |
27128 KB |
Output is correct |
14 |
Correct |
33 ms |
27384 KB |
Output is correct |
15 |
Correct |
33 ms |
27256 KB |
Output is correct |
16 |
Correct |
32 ms |
27256 KB |
Output is correct |
17 |
Correct |
30 ms |
27128 KB |
Output is correct |
18 |
Correct |
31 ms |
27256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1753 ms |
118780 KB |
Output is correct |
2 |
Correct |
1774 ms |
151716 KB |
Output is correct |
3 |
Correct |
1786 ms |
151396 KB |
Output is correct |
4 |
Correct |
1787 ms |
151608 KB |
Output is correct |
5 |
Correct |
1440 ms |
124468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
184 ms |
36332 KB |
Output is correct |
2 |
Correct |
161 ms |
36344 KB |
Output is correct |
3 |
Correct |
141 ms |
33336 KB |
Output is correct |
4 |
Correct |
142 ms |
33420 KB |
Output is correct |
5 |
Correct |
140 ms |
33364 KB |
Output is correct |
6 |
Correct |
133 ms |
33604 KB |
Output is correct |
7 |
Correct |
133 ms |
33640 KB |
Output is correct |
8 |
Correct |
135 ms |
35000 KB |
Output is correct |
9 |
Correct |
91 ms |
30840 KB |
Output is correct |
10 |
Correct |
131 ms |
34424 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
26744 KB |
Output is correct |
2 |
Correct |
27 ms |
26744 KB |
Output is correct |
3 |
Correct |
26 ms |
26708 KB |
Output is correct |
4 |
Correct |
26 ms |
26744 KB |
Output is correct |
5 |
Correct |
26 ms |
26744 KB |
Output is correct |
6 |
Correct |
25 ms |
26744 KB |
Output is correct |
7 |
Correct |
26 ms |
26744 KB |
Output is correct |
8 |
Correct |
26 ms |
26816 KB |
Output is correct |
9 |
Correct |
26 ms |
26744 KB |
Output is correct |
10 |
Correct |
26 ms |
26744 KB |
Output is correct |
11 |
Correct |
29 ms |
26872 KB |
Output is correct |
12 |
Correct |
30 ms |
27128 KB |
Output is correct |
13 |
Correct |
31 ms |
27128 KB |
Output is correct |
14 |
Correct |
33 ms |
27384 KB |
Output is correct |
15 |
Correct |
33 ms |
27256 KB |
Output is correct |
16 |
Correct |
32 ms |
27256 KB |
Output is correct |
17 |
Correct |
30 ms |
27128 KB |
Output is correct |
18 |
Correct |
31 ms |
27256 KB |
Output is correct |
19 |
Correct |
351 ms |
45992 KB |
Output is correct |
20 |
Correct |
356 ms |
46032 KB |
Output is correct |
21 |
Correct |
328 ms |
46040 KB |
Output is correct |
22 |
Correct |
328 ms |
46004 KB |
Output is correct |
23 |
Correct |
323 ms |
45948 KB |
Output is correct |
24 |
Correct |
274 ms |
39908 KB |
Output is correct |
25 |
Correct |
275 ms |
39956 KB |
Output is correct |
26 |
Correct |
285 ms |
39788 KB |
Output is correct |
27 |
Correct |
296 ms |
39784 KB |
Output is correct |
28 |
Correct |
285 ms |
39820 KB |
Output is correct |
29 |
Correct |
291 ms |
39812 KB |
Output is correct |
30 |
Correct |
290 ms |
39864 KB |
Output is correct |
31 |
Correct |
291 ms |
39916 KB |
Output is correct |
32 |
Correct |
291 ms |
39720 KB |
Output is correct |
33 |
Correct |
292 ms |
39916 KB |
Output is correct |
34 |
Correct |
270 ms |
39904 KB |
Output is correct |
35 |
Correct |
267 ms |
39792 KB |
Output is correct |
36 |
Correct |
266 ms |
39848 KB |
Output is correct |
37 |
Correct |
269 ms |
39976 KB |
Output is correct |
38 |
Correct |
268 ms |
39900 KB |
Output is correct |
39 |
Correct |
271 ms |
41976 KB |
Output is correct |
40 |
Correct |
215 ms |
38880 KB |
Output is correct |
41 |
Correct |
261 ms |
42504 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
26 ms |
26744 KB |
Output is correct |
2 |
Correct |
27 ms |
26744 KB |
Output is correct |
3 |
Correct |
26 ms |
26708 KB |
Output is correct |
4 |
Correct |
26 ms |
26744 KB |
Output is correct |
5 |
Correct |
26 ms |
26744 KB |
Output is correct |
6 |
Correct |
25 ms |
26744 KB |
Output is correct |
7 |
Correct |
26 ms |
26744 KB |
Output is correct |
8 |
Correct |
26 ms |
26816 KB |
Output is correct |
9 |
Correct |
26 ms |
26744 KB |
Output is correct |
10 |
Correct |
26 ms |
26744 KB |
Output is correct |
11 |
Correct |
29 ms |
26872 KB |
Output is correct |
12 |
Correct |
30 ms |
27128 KB |
Output is correct |
13 |
Correct |
31 ms |
27128 KB |
Output is correct |
14 |
Correct |
33 ms |
27384 KB |
Output is correct |
15 |
Correct |
33 ms |
27256 KB |
Output is correct |
16 |
Correct |
32 ms |
27256 KB |
Output is correct |
17 |
Correct |
30 ms |
27128 KB |
Output is correct |
18 |
Correct |
31 ms |
27256 KB |
Output is correct |
19 |
Correct |
1753 ms |
118780 KB |
Output is correct |
20 |
Correct |
1774 ms |
151716 KB |
Output is correct |
21 |
Correct |
1786 ms |
151396 KB |
Output is correct |
22 |
Correct |
1787 ms |
151608 KB |
Output is correct |
23 |
Correct |
1440 ms |
124468 KB |
Output is correct |
24 |
Correct |
184 ms |
36332 KB |
Output is correct |
25 |
Correct |
161 ms |
36344 KB |
Output is correct |
26 |
Correct |
141 ms |
33336 KB |
Output is correct |
27 |
Correct |
142 ms |
33420 KB |
Output is correct |
28 |
Correct |
140 ms |
33364 KB |
Output is correct |
29 |
Correct |
133 ms |
33604 KB |
Output is correct |
30 |
Correct |
133 ms |
33640 KB |
Output is correct |
31 |
Correct |
135 ms |
35000 KB |
Output is correct |
32 |
Correct |
91 ms |
30840 KB |
Output is correct |
33 |
Correct |
131 ms |
34424 KB |
Output is correct |
34 |
Correct |
351 ms |
45992 KB |
Output is correct |
35 |
Correct |
356 ms |
46032 KB |
Output is correct |
36 |
Correct |
328 ms |
46040 KB |
Output is correct |
37 |
Correct |
328 ms |
46004 KB |
Output is correct |
38 |
Correct |
323 ms |
45948 KB |
Output is correct |
39 |
Correct |
274 ms |
39908 KB |
Output is correct |
40 |
Correct |
275 ms |
39956 KB |
Output is correct |
41 |
Correct |
285 ms |
39788 KB |
Output is correct |
42 |
Correct |
296 ms |
39784 KB |
Output is correct |
43 |
Correct |
285 ms |
39820 KB |
Output is correct |
44 |
Correct |
291 ms |
39812 KB |
Output is correct |
45 |
Correct |
290 ms |
39864 KB |
Output is correct |
46 |
Correct |
291 ms |
39916 KB |
Output is correct |
47 |
Correct |
291 ms |
39720 KB |
Output is correct |
48 |
Correct |
292 ms |
39916 KB |
Output is correct |
49 |
Correct |
270 ms |
39904 KB |
Output is correct |
50 |
Correct |
267 ms |
39792 KB |
Output is correct |
51 |
Correct |
266 ms |
39848 KB |
Output is correct |
52 |
Correct |
269 ms |
39976 KB |
Output is correct |
53 |
Correct |
268 ms |
39900 KB |
Output is correct |
54 |
Correct |
271 ms |
41976 KB |
Output is correct |
55 |
Correct |
215 ms |
38880 KB |
Output is correct |
56 |
Correct |
261 ms |
42504 KB |
Output is correct |
57 |
Correct |
1813 ms |
152396 KB |
Output is correct |
58 |
Correct |
1777 ms |
152248 KB |
Output is correct |
59 |
Correct |
1760 ms |
152300 KB |
Output is correct |
60 |
Correct |
1782 ms |
152164 KB |
Output is correct |
61 |
Correct |
1795 ms |
152128 KB |
Output is correct |
62 |
Correct |
1753 ms |
152156 KB |
Output is correct |
63 |
Correct |
1373 ms |
123176 KB |
Output is correct |
64 |
Correct |
1370 ms |
123164 KB |
Output is correct |
65 |
Correct |
1489 ms |
125132 KB |
Output is correct |
66 |
Correct |
1448 ms |
124928 KB |
Output is correct |
67 |
Correct |
1447 ms |
125020 KB |
Output is correct |
68 |
Correct |
1425 ms |
125256 KB |
Output is correct |
69 |
Correct |
1445 ms |
125052 KB |
Output is correct |
70 |
Correct |
1460 ms |
125124 KB |
Output is correct |
71 |
Correct |
1505 ms |
125040 KB |
Output is correct |
72 |
Correct |
1466 ms |
125116 KB |
Output is correct |
73 |
Correct |
1329 ms |
121636 KB |
Output is correct |
74 |
Correct |
1337 ms |
122684 KB |
Output is correct |
75 |
Correct |
1355 ms |
121672 KB |
Output is correct |
76 |
Correct |
1331 ms |
121656 KB |
Output is correct |
77 |
Correct |
1321 ms |
121664 KB |
Output is correct |
78 |
Correct |
1361 ms |
128064 KB |
Output is correct |
79 |
Correct |
1029 ms |
105924 KB |
Output is correct |
80 |
Correct |
1340 ms |
129804 KB |
Output is correct |