#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 modify(ll v, ll tl, ll tr, ll pos, ll val){
if(tl == tr)t[v] = val; else{
ll tm = (tl + tr) >> 1;
if(pos <= tm)modify(v << 1, tl, tm, pos, val);
else modify((v << 1) + 1, tm + 1, tr, pos, val);
t[v] = max(t[v << 1], t[(v << 1) + 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) >> 1;
return max(get(v << 1, tl, tm, l, min(r, tm)), get((v << 1) + 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]){
modify(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 |
25 ms |
26744 KB |
Output is correct |
2 |
Correct |
25 ms |
26744 KB |
Output is correct |
3 |
Correct |
26 ms |
26744 KB |
Output is correct |
4 |
Correct |
25 ms |
26744 KB |
Output is correct |
5 |
Correct |
25 ms |
26744 KB |
Output is correct |
6 |
Correct |
26 ms |
26744 KB |
Output is correct |
7 |
Correct |
26 ms |
26872 KB |
Output is correct |
8 |
Correct |
26 ms |
26744 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 |
25 ms |
26744 KB |
Output is correct |
2 |
Correct |
25 ms |
26744 KB |
Output is correct |
3 |
Correct |
26 ms |
26744 KB |
Output is correct |
4 |
Correct |
25 ms |
26744 KB |
Output is correct |
5 |
Correct |
25 ms |
26744 KB |
Output is correct |
6 |
Correct |
26 ms |
26744 KB |
Output is correct |
7 |
Correct |
26 ms |
26872 KB |
Output is correct |
8 |
Correct |
26 ms |
26744 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 |
27000 KB |
Output is correct |
12 |
Correct |
29 ms |
27260 KB |
Output is correct |
13 |
Correct |
30 ms |
27444 KB |
Output is correct |
14 |
Correct |
32 ms |
27384 KB |
Output is correct |
15 |
Correct |
32 ms |
27384 KB |
Output is correct |
16 |
Correct |
30 ms |
27256 KB |
Output is correct |
17 |
Correct |
29 ms |
27256 KB |
Output is correct |
18 |
Correct |
30 ms |
27280 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1679 ms |
118712 KB |
Output is correct |
2 |
Correct |
1686 ms |
118876 KB |
Output is correct |
3 |
Correct |
1658 ms |
118792 KB |
Output is correct |
4 |
Correct |
1684 ms |
118840 KB |
Output is correct |
5 |
Correct |
1409 ms |
91768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
36332 KB |
Output is correct |
2 |
Correct |
149 ms |
38392 KB |
Output is correct |
3 |
Correct |
133 ms |
35304 KB |
Output is correct |
4 |
Correct |
133 ms |
35292 KB |
Output is correct |
5 |
Correct |
137 ms |
35324 KB |
Output is correct |
6 |
Correct |
122 ms |
35440 KB |
Output is correct |
7 |
Correct |
124 ms |
35464 KB |
Output is correct |
8 |
Correct |
125 ms |
36732 KB |
Output is correct |
9 |
Correct |
88 ms |
32248 KB |
Output is correct |
10 |
Correct |
124 ms |
36208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
26744 KB |
Output is correct |
2 |
Correct |
25 ms |
26744 KB |
Output is correct |
3 |
Correct |
26 ms |
26744 KB |
Output is correct |
4 |
Correct |
25 ms |
26744 KB |
Output is correct |
5 |
Correct |
25 ms |
26744 KB |
Output is correct |
6 |
Correct |
26 ms |
26744 KB |
Output is correct |
7 |
Correct |
26 ms |
26872 KB |
Output is correct |
8 |
Correct |
26 ms |
26744 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 |
27000 KB |
Output is correct |
12 |
Correct |
29 ms |
27260 KB |
Output is correct |
13 |
Correct |
30 ms |
27444 KB |
Output is correct |
14 |
Correct |
32 ms |
27384 KB |
Output is correct |
15 |
Correct |
32 ms |
27384 KB |
Output is correct |
16 |
Correct |
30 ms |
27256 KB |
Output is correct |
17 |
Correct |
29 ms |
27256 KB |
Output is correct |
18 |
Correct |
30 ms |
27280 KB |
Output is correct |
19 |
Correct |
332 ms |
52628 KB |
Output is correct |
20 |
Correct |
330 ms |
52572 KB |
Output is correct |
21 |
Correct |
304 ms |
52336 KB |
Output is correct |
22 |
Correct |
302 ms |
52344 KB |
Output is correct |
23 |
Correct |
302 ms |
52344 KB |
Output is correct |
24 |
Correct |
260 ms |
46236 KB |
Output is correct |
25 |
Correct |
261 ms |
46188 KB |
Output is correct |
26 |
Correct |
271 ms |
46444 KB |
Output is correct |
27 |
Correct |
274 ms |
46376 KB |
Output is correct |
28 |
Correct |
272 ms |
46316 KB |
Output is correct |
29 |
Correct |
276 ms |
46500 KB |
Output is correct |
30 |
Correct |
278 ms |
46416 KB |
Output is correct |
31 |
Correct |
283 ms |
46520 KB |
Output is correct |
32 |
Correct |
278 ms |
46444 KB |
Output is correct |
33 |
Correct |
277 ms |
46444 KB |
Output is correct |
34 |
Correct |
254 ms |
46060 KB |
Output is correct |
35 |
Correct |
253 ms |
46140 KB |
Output is correct |
36 |
Correct |
268 ms |
45904 KB |
Output is correct |
37 |
Correct |
253 ms |
45824 KB |
Output is correct |
38 |
Correct |
255 ms |
46060 KB |
Output is correct |
39 |
Correct |
262 ms |
47012 KB |
Output is correct |
40 |
Correct |
212 ms |
43320 KB |
Output is correct |
41 |
Correct |
251 ms |
47444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
25 ms |
26744 KB |
Output is correct |
2 |
Correct |
25 ms |
26744 KB |
Output is correct |
3 |
Correct |
26 ms |
26744 KB |
Output is correct |
4 |
Correct |
25 ms |
26744 KB |
Output is correct |
5 |
Correct |
25 ms |
26744 KB |
Output is correct |
6 |
Correct |
26 ms |
26744 KB |
Output is correct |
7 |
Correct |
26 ms |
26872 KB |
Output is correct |
8 |
Correct |
26 ms |
26744 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 |
27000 KB |
Output is correct |
12 |
Correct |
29 ms |
27260 KB |
Output is correct |
13 |
Correct |
30 ms |
27444 KB |
Output is correct |
14 |
Correct |
32 ms |
27384 KB |
Output is correct |
15 |
Correct |
32 ms |
27384 KB |
Output is correct |
16 |
Correct |
30 ms |
27256 KB |
Output is correct |
17 |
Correct |
29 ms |
27256 KB |
Output is correct |
18 |
Correct |
30 ms |
27280 KB |
Output is correct |
19 |
Correct |
1679 ms |
118712 KB |
Output is correct |
20 |
Correct |
1686 ms |
118876 KB |
Output is correct |
21 |
Correct |
1658 ms |
118792 KB |
Output is correct |
22 |
Correct |
1684 ms |
118840 KB |
Output is correct |
23 |
Correct |
1409 ms |
91768 KB |
Output is correct |
24 |
Correct |
154 ms |
36332 KB |
Output is correct |
25 |
Correct |
149 ms |
38392 KB |
Output is correct |
26 |
Correct |
133 ms |
35304 KB |
Output is correct |
27 |
Correct |
133 ms |
35292 KB |
Output is correct |
28 |
Correct |
137 ms |
35324 KB |
Output is correct |
29 |
Correct |
122 ms |
35440 KB |
Output is correct |
30 |
Correct |
124 ms |
35464 KB |
Output is correct |
31 |
Correct |
125 ms |
36732 KB |
Output is correct |
32 |
Correct |
88 ms |
32248 KB |
Output is correct |
33 |
Correct |
124 ms |
36208 KB |
Output is correct |
34 |
Correct |
332 ms |
52628 KB |
Output is correct |
35 |
Correct |
330 ms |
52572 KB |
Output is correct |
36 |
Correct |
304 ms |
52336 KB |
Output is correct |
37 |
Correct |
302 ms |
52344 KB |
Output is correct |
38 |
Correct |
302 ms |
52344 KB |
Output is correct |
39 |
Correct |
260 ms |
46236 KB |
Output is correct |
40 |
Correct |
261 ms |
46188 KB |
Output is correct |
41 |
Correct |
271 ms |
46444 KB |
Output is correct |
42 |
Correct |
274 ms |
46376 KB |
Output is correct |
43 |
Correct |
272 ms |
46316 KB |
Output is correct |
44 |
Correct |
276 ms |
46500 KB |
Output is correct |
45 |
Correct |
278 ms |
46416 KB |
Output is correct |
46 |
Correct |
283 ms |
46520 KB |
Output is correct |
47 |
Correct |
278 ms |
46444 KB |
Output is correct |
48 |
Correct |
277 ms |
46444 KB |
Output is correct |
49 |
Correct |
254 ms |
46060 KB |
Output is correct |
50 |
Correct |
253 ms |
46140 KB |
Output is correct |
51 |
Correct |
268 ms |
45904 KB |
Output is correct |
52 |
Correct |
253 ms |
45824 KB |
Output is correct |
53 |
Correct |
255 ms |
46060 KB |
Output is correct |
54 |
Correct |
262 ms |
47012 KB |
Output is correct |
55 |
Correct |
212 ms |
43320 KB |
Output is correct |
56 |
Correct |
251 ms |
47444 KB |
Output is correct |
57 |
Correct |
1693 ms |
152252 KB |
Output is correct |
58 |
Correct |
1723 ms |
152308 KB |
Output is correct |
59 |
Correct |
1657 ms |
152224 KB |
Output is correct |
60 |
Correct |
1663 ms |
152236 KB |
Output is correct |
61 |
Correct |
1649 ms |
152248 KB |
Output is correct |
62 |
Correct |
1678 ms |
152204 KB |
Output is correct |
63 |
Correct |
1325 ms |
123176 KB |
Output is correct |
64 |
Correct |
1345 ms |
123172 KB |
Output is correct |
65 |
Correct |
1408 ms |
125144 KB |
Output is correct |
66 |
Correct |
1563 ms |
125068 KB |
Output is correct |
67 |
Correct |
1389 ms |
124992 KB |
Output is correct |
68 |
Correct |
1462 ms |
125172 KB |
Output is correct |
69 |
Correct |
1418 ms |
125160 KB |
Output is correct |
70 |
Correct |
1418 ms |
125072 KB |
Output is correct |
71 |
Correct |
1396 ms |
125276 KB |
Output is correct |
72 |
Correct |
1428 ms |
125244 KB |
Output is correct |
73 |
Correct |
1270 ms |
121816 KB |
Output is correct |
74 |
Correct |
1289 ms |
122712 KB |
Output is correct |
75 |
Correct |
1277 ms |
121788 KB |
Output is correct |
76 |
Correct |
1279 ms |
121684 KB |
Output is correct |
77 |
Correct |
1283 ms |
121800 KB |
Output is correct |
78 |
Correct |
1329 ms |
128220 KB |
Output is correct |
79 |
Correct |
1022 ms |
105956 KB |
Output is correct |
80 |
Correct |
1286 ms |
130112 KB |
Output is correct |