#include <bits/stdc++.h>
#ifdef LOCAL
#include "/home/trcmai/code/tools.h"
#define debug(x...) cerr << "\e[91m"<<__func__<<":"<<__LINE__<<" [" << #x << "] = ["; _print(x); cerr << "\e[39m" << endl;
#else
#define debug(x...)
#endif
using namespace std;
#define all(a) a.begin(), a.end()
#define ll long long
#define endl '\n'
const int N = 1e6 + 6, LOG = 27, MOD = 1e9 + 7;
const ll INF = 1e18;
int n,q,jmp[N];
ll w[N];
vector<tuple<int,int,ll>>Q[N];
template<class T> struct segtree_max {
int n;
vector<T> t;
T merge(T a, T b) {return max(a, b);}
void init(int N) {n = N; t.assign(2*n, numeric_limits<T>::min());}
void set(int i, T v) {
for (t[i+=n] = v; i > 1; i>>=1) t[i >> 1] = merge(t[i], t[i^1]);
}
void build(const vector<T> &a) {
for (int i = 0; i < n; i++) set(i, a[i]);
}
T get(int l, int r) {
r++;
T x = numeric_limits<T>::min();
for (l+=n, r+=n; l < r; l>>=1, r>>=1) {
if (l & 1) x = merge(x, t[l++]);
if (r & 1) x = merge(x, t[--r]);
}
return x;
}
};
signed main() {
cin.tie(0)->sync_with_stdio(0);
auto solver=[&](){
cin>>n>>q;
deque<int>dq;
for(int i = 1;i <= n;++i){
cin>>w[i];
while(dq.size() && w[dq.back()] <= w[i]) dq.pop_back();
if(dq.size()) jmp[i] = dq.back();
dq.push_back(i);
}
for(int i = 1;i <= q;++i){
int l,r; ll c;
cin>>l>>r>>c;
Q[r].emplace_back(i,l,c);
}
vector<bool>res(q + 1,false);
segtree_max<int> st; st.init(n + 5);
for(int i = 1;i <= n;++i){
st.set(jmp[i],w[i] + w[jmp[i]]);
for(auto [idx,l,c] : Q[i])
res[idx] = (st.get(l,i) <= c);
}
for(int i = 1;i <= q;++i)
cout<<res[i]<<endl;
};
int t = 1; // cin>>t;
while (t--) solver();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27224 KB |
Output is correct |
2 |
Correct |
3 ms |
25180 KB |
Output is correct |
3 |
Correct |
3 ms |
27228 KB |
Output is correct |
4 |
Correct |
4 ms |
27236 KB |
Output is correct |
5 |
Correct |
4 ms |
27228 KB |
Output is correct |
6 |
Correct |
4 ms |
27224 KB |
Output is correct |
7 |
Correct |
4 ms |
27236 KB |
Output is correct |
8 |
Correct |
3 ms |
27228 KB |
Output is correct |
9 |
Correct |
3 ms |
27228 KB |
Output is correct |
10 |
Correct |
3 ms |
27272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27224 KB |
Output is correct |
2 |
Correct |
3 ms |
25180 KB |
Output is correct |
3 |
Correct |
3 ms |
27228 KB |
Output is correct |
4 |
Correct |
4 ms |
27236 KB |
Output is correct |
5 |
Correct |
4 ms |
27228 KB |
Output is correct |
6 |
Correct |
4 ms |
27224 KB |
Output is correct |
7 |
Correct |
4 ms |
27236 KB |
Output is correct |
8 |
Correct |
3 ms |
27228 KB |
Output is correct |
9 |
Correct |
3 ms |
27228 KB |
Output is correct |
10 |
Correct |
3 ms |
27272 KB |
Output is correct |
11 |
Correct |
4 ms |
27228 KB |
Output is correct |
12 |
Correct |
5 ms |
27228 KB |
Output is correct |
13 |
Correct |
5 ms |
27392 KB |
Output is correct |
14 |
Correct |
5 ms |
27484 KB |
Output is correct |
15 |
Correct |
5 ms |
27484 KB |
Output is correct |
16 |
Correct |
4 ms |
27484 KB |
Output is correct |
17 |
Correct |
5 ms |
27492 KB |
Output is correct |
18 |
Correct |
5 ms |
27484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
545 ms |
71592 KB |
Output is correct |
2 |
Correct |
527 ms |
71752 KB |
Output is correct |
3 |
Correct |
529 ms |
71764 KB |
Output is correct |
4 |
Correct |
543 ms |
71596 KB |
Output is correct |
5 |
Correct |
536 ms |
69548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
39 ms |
30808 KB |
Output is correct |
2 |
Correct |
36 ms |
30548 KB |
Output is correct |
3 |
Correct |
39 ms |
28752 KB |
Output is correct |
4 |
Correct |
38 ms |
28756 KB |
Output is correct |
5 |
Correct |
38 ms |
28648 KB |
Output is correct |
6 |
Correct |
30 ms |
30436 KB |
Output is correct |
7 |
Correct |
29 ms |
30796 KB |
Output is correct |
8 |
Correct |
33 ms |
30408 KB |
Output is correct |
9 |
Correct |
21 ms |
29496 KB |
Output is correct |
10 |
Correct |
36 ms |
30412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27224 KB |
Output is correct |
2 |
Correct |
3 ms |
25180 KB |
Output is correct |
3 |
Correct |
3 ms |
27228 KB |
Output is correct |
4 |
Correct |
4 ms |
27236 KB |
Output is correct |
5 |
Correct |
4 ms |
27228 KB |
Output is correct |
6 |
Correct |
4 ms |
27224 KB |
Output is correct |
7 |
Correct |
4 ms |
27236 KB |
Output is correct |
8 |
Correct |
3 ms |
27228 KB |
Output is correct |
9 |
Correct |
3 ms |
27228 KB |
Output is correct |
10 |
Correct |
3 ms |
27272 KB |
Output is correct |
11 |
Correct |
4 ms |
27228 KB |
Output is correct |
12 |
Correct |
5 ms |
27228 KB |
Output is correct |
13 |
Correct |
5 ms |
27392 KB |
Output is correct |
14 |
Correct |
5 ms |
27484 KB |
Output is correct |
15 |
Correct |
5 ms |
27484 KB |
Output is correct |
16 |
Correct |
4 ms |
27484 KB |
Output is correct |
17 |
Correct |
5 ms |
27492 KB |
Output is correct |
18 |
Correct |
5 ms |
27484 KB |
Output is correct |
19 |
Correct |
86 ms |
36436 KB |
Output is correct |
20 |
Correct |
91 ms |
36376 KB |
Output is correct |
21 |
Correct |
82 ms |
36180 KB |
Output is correct |
22 |
Correct |
77 ms |
36068 KB |
Output is correct |
23 |
Correct |
79 ms |
36176 KB |
Output is correct |
24 |
Correct |
72 ms |
34132 KB |
Output is correct |
25 |
Correct |
74 ms |
34128 KB |
Output is correct |
26 |
Correct |
79 ms |
34128 KB |
Output is correct |
27 |
Correct |
80 ms |
34128 KB |
Output is correct |
28 |
Correct |
82 ms |
34136 KB |
Output is correct |
29 |
Correct |
87 ms |
34388 KB |
Output is correct |
30 |
Correct |
92 ms |
34216 KB |
Output is correct |
31 |
Correct |
83 ms |
34384 KB |
Output is correct |
32 |
Correct |
85 ms |
34384 KB |
Output is correct |
33 |
Correct |
85 ms |
34384 KB |
Output is correct |
34 |
Correct |
65 ms |
35664 KB |
Output is correct |
35 |
Correct |
64 ms |
35664 KB |
Output is correct |
36 |
Correct |
64 ms |
35668 KB |
Output is correct |
37 |
Correct |
73 ms |
35660 KB |
Output is correct |
38 |
Correct |
66 ms |
35560 KB |
Output is correct |
39 |
Correct |
80 ms |
35820 KB |
Output is correct |
40 |
Correct |
63 ms |
33040 KB |
Output is correct |
41 |
Correct |
72 ms |
35776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
27224 KB |
Output is correct |
2 |
Correct |
3 ms |
25180 KB |
Output is correct |
3 |
Correct |
3 ms |
27228 KB |
Output is correct |
4 |
Correct |
4 ms |
27236 KB |
Output is correct |
5 |
Correct |
4 ms |
27228 KB |
Output is correct |
6 |
Correct |
4 ms |
27224 KB |
Output is correct |
7 |
Correct |
4 ms |
27236 KB |
Output is correct |
8 |
Correct |
3 ms |
27228 KB |
Output is correct |
9 |
Correct |
3 ms |
27228 KB |
Output is correct |
10 |
Correct |
3 ms |
27272 KB |
Output is correct |
11 |
Correct |
4 ms |
27228 KB |
Output is correct |
12 |
Correct |
5 ms |
27228 KB |
Output is correct |
13 |
Correct |
5 ms |
27392 KB |
Output is correct |
14 |
Correct |
5 ms |
27484 KB |
Output is correct |
15 |
Correct |
5 ms |
27484 KB |
Output is correct |
16 |
Correct |
4 ms |
27484 KB |
Output is correct |
17 |
Correct |
5 ms |
27492 KB |
Output is correct |
18 |
Correct |
5 ms |
27484 KB |
Output is correct |
19 |
Correct |
545 ms |
71592 KB |
Output is correct |
20 |
Correct |
527 ms |
71752 KB |
Output is correct |
21 |
Correct |
529 ms |
71764 KB |
Output is correct |
22 |
Correct |
543 ms |
71596 KB |
Output is correct |
23 |
Correct |
536 ms |
69548 KB |
Output is correct |
24 |
Correct |
39 ms |
30808 KB |
Output is correct |
25 |
Correct |
36 ms |
30548 KB |
Output is correct |
26 |
Correct |
39 ms |
28752 KB |
Output is correct |
27 |
Correct |
38 ms |
28756 KB |
Output is correct |
28 |
Correct |
38 ms |
28648 KB |
Output is correct |
29 |
Correct |
30 ms |
30436 KB |
Output is correct |
30 |
Correct |
29 ms |
30796 KB |
Output is correct |
31 |
Correct |
33 ms |
30408 KB |
Output is correct |
32 |
Correct |
21 ms |
29496 KB |
Output is correct |
33 |
Correct |
36 ms |
30412 KB |
Output is correct |
34 |
Correct |
86 ms |
36436 KB |
Output is correct |
35 |
Correct |
91 ms |
36376 KB |
Output is correct |
36 |
Correct |
82 ms |
36180 KB |
Output is correct |
37 |
Correct |
77 ms |
36068 KB |
Output is correct |
38 |
Correct |
79 ms |
36176 KB |
Output is correct |
39 |
Correct |
72 ms |
34132 KB |
Output is correct |
40 |
Correct |
74 ms |
34128 KB |
Output is correct |
41 |
Correct |
79 ms |
34128 KB |
Output is correct |
42 |
Correct |
80 ms |
34128 KB |
Output is correct |
43 |
Correct |
82 ms |
34136 KB |
Output is correct |
44 |
Correct |
87 ms |
34388 KB |
Output is correct |
45 |
Correct |
92 ms |
34216 KB |
Output is correct |
46 |
Correct |
83 ms |
34384 KB |
Output is correct |
47 |
Correct |
85 ms |
34384 KB |
Output is correct |
48 |
Correct |
85 ms |
34384 KB |
Output is correct |
49 |
Correct |
65 ms |
35664 KB |
Output is correct |
50 |
Correct |
64 ms |
35664 KB |
Output is correct |
51 |
Correct |
64 ms |
35668 KB |
Output is correct |
52 |
Correct |
73 ms |
35660 KB |
Output is correct |
53 |
Correct |
66 ms |
35560 KB |
Output is correct |
54 |
Correct |
80 ms |
35820 KB |
Output is correct |
55 |
Correct |
63 ms |
33040 KB |
Output is correct |
56 |
Correct |
72 ms |
35776 KB |
Output is correct |
57 |
Correct |
531 ms |
71248 KB |
Output is correct |
58 |
Correct |
492 ms |
71164 KB |
Output is correct |
59 |
Correct |
529 ms |
70484 KB |
Output is correct |
60 |
Correct |
482 ms |
70316 KB |
Output is correct |
61 |
Correct |
471 ms |
70484 KB |
Output is correct |
62 |
Correct |
488 ms |
70480 KB |
Output is correct |
63 |
Correct |
339 ms |
67668 KB |
Output is correct |
64 |
Correct |
334 ms |
67664 KB |
Output is correct |
65 |
Correct |
473 ms |
68176 KB |
Output is correct |
66 |
Correct |
454 ms |
68176 KB |
Output is correct |
67 |
Correct |
501 ms |
68176 KB |
Output is correct |
68 |
Correct |
554 ms |
68948 KB |
Output is correct |
69 |
Correct |
581 ms |
69032 KB |
Output is correct |
70 |
Correct |
587 ms |
68776 KB |
Output is correct |
71 |
Correct |
598 ms |
68692 KB |
Output is correct |
72 |
Correct |
582 ms |
68772 KB |
Output is correct |
73 |
Correct |
327 ms |
66224 KB |
Output is correct |
74 |
Correct |
325 ms |
66216 KB |
Output is correct |
75 |
Correct |
341 ms |
66216 KB |
Output is correct |
76 |
Correct |
320 ms |
66212 KB |
Output is correct |
77 |
Correct |
325 ms |
66132 KB |
Output is correct |
78 |
Correct |
514 ms |
68876 KB |
Output is correct |
79 |
Correct |
358 ms |
58800 KB |
Output is correct |
80 |
Correct |
413 ms |
68868 KB |
Output is correct |