#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define send {ios_base::sync_with_stdio(false);}
#define help {cin.tie(NULL); cout.tie(NULL);}
#define all(v) v.begin(), v.end()
#define int long long
#define ld long double
#define ll long double
#define ar array
mt19937 rng(std::chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e6 + 20;
const int M = (1 << 14) + 10;
const int LOG = __lg(N) + 2;
const int SQRT = sqrt(N);
//const int MOD = 998244353;
const int MOD = 1e9 + 7;
const int INF = 1e16;
const ld EPS = 1e-12;
const ld PI = 3.14159265358979323846;
int n, m, k, q, l, r, x, y, z;
int ans;
void orz();
signed main(){
send help;
int t = 1;
//cin>>t;
while(t--)orz();
}
namespace seggy{
int s[4 * N];
void upd(int k,int tl,int tr,int p,int v){
if(tl == tr){
s[k] = max(s[k], v);
return;
}
int tm = (tl + tr) / 2;
if(p <= tm)upd(k * 2, tl, tm, p, v);
else upd(k * 2 + 1, tm + 1, tr, p, v);
s[k] = max(s[k * 2], s[k * 2 + 1]);
}
int qry(int k,int tl,int tr,int l,int r){
if(tl > r || l > tr)return -INF;
if(l <= tl && tr <= r)return s[k];
int tm = (tl + tr) / 2;
return max(qry(k * 2, tl, tm, l, r), qry(k * 2 + 1,tm + 1, tr, l, r));
}
};
int A[N];
void orz(){
cin>>n>>m;
for(int i = 0;i < n;i++)cin>>A[i];
vector<ar<int, 3> > que[n];
for(int i = 0;i < m;i++){
int l, r, x;
cin>>l>>r>>x;
--l, --r;
que[r].push_back({l, x, i});
}
bool ans[m];
stack<int> st;
for(int i = 0;i < n;i++){
while(st.size() && A[st.top()] <= A[i])st.pop();
if(st.size())seggy::upd(1, 0, n - 1, st.top(), A[st.top()] + A[i]);
for(auto [l, x, j]: que[i])ans[j] = seggy::qry(1, 0, n - 1, l, i) <= x;
st.push(i);
}
for(auto u: ans)cout<<u<<'\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
3 ms |
848 KB |
Output is correct |
13 |
Correct |
3 ms |
848 KB |
Output is correct |
14 |
Correct |
4 ms |
848 KB |
Output is correct |
15 |
Correct |
4 ms |
848 KB |
Output is correct |
16 |
Correct |
3 ms |
848 KB |
Output is correct |
17 |
Correct |
3 ms |
900 KB |
Output is correct |
18 |
Correct |
4 ms |
848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1037 ms |
96856 KB |
Output is correct |
2 |
Correct |
1006 ms |
108652 KB |
Output is correct |
3 |
Correct |
1080 ms |
116616 KB |
Output is correct |
4 |
Correct |
1072 ms |
108736 KB |
Output is correct |
5 |
Correct |
950 ms |
100168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
70 ms |
13896 KB |
Output is correct |
2 |
Correct |
66 ms |
14300 KB |
Output is correct |
3 |
Correct |
61 ms |
10612 KB |
Output is correct |
4 |
Correct |
60 ms |
10568 KB |
Output is correct |
5 |
Correct |
63 ms |
10568 KB |
Output is correct |
6 |
Correct |
53 ms |
12468 KB |
Output is correct |
7 |
Correct |
49 ms |
12368 KB |
Output is correct |
8 |
Correct |
63 ms |
10248 KB |
Output is correct |
9 |
Correct |
28 ms |
4868 KB |
Output is correct |
10 |
Correct |
61 ms |
10248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
3 ms |
848 KB |
Output is correct |
13 |
Correct |
3 ms |
848 KB |
Output is correct |
14 |
Correct |
4 ms |
848 KB |
Output is correct |
15 |
Correct |
4 ms |
848 KB |
Output is correct |
16 |
Correct |
3 ms |
848 KB |
Output is correct |
17 |
Correct |
3 ms |
900 KB |
Output is correct |
18 |
Correct |
4 ms |
848 KB |
Output is correct |
19 |
Correct |
162 ms |
24652 KB |
Output is correct |
20 |
Correct |
178 ms |
26696 KB |
Output is correct |
21 |
Correct |
149 ms |
26952 KB |
Output is correct |
22 |
Correct |
143 ms |
26952 KB |
Output is correct |
23 |
Correct |
145 ms |
26960 KB |
Output is correct |
24 |
Correct |
130 ms |
21320 KB |
Output is correct |
25 |
Correct |
120 ms |
21384 KB |
Output is correct |
26 |
Correct |
136 ms |
21156 KB |
Output is correct |
27 |
Correct |
137 ms |
21180 KB |
Output is correct |
28 |
Correct |
147 ms |
21156 KB |
Output is correct |
29 |
Correct |
151 ms |
21108 KB |
Output is correct |
30 |
Correct |
138 ms |
21064 KB |
Output is correct |
31 |
Correct |
144 ms |
21096 KB |
Output is correct |
32 |
Correct |
149 ms |
21076 KB |
Output is correct |
33 |
Correct |
163 ms |
21064 KB |
Output is correct |
34 |
Correct |
125 ms |
22856 KB |
Output is correct |
35 |
Correct |
119 ms |
22856 KB |
Output is correct |
36 |
Correct |
119 ms |
22520 KB |
Output is correct |
37 |
Correct |
113 ms |
22700 KB |
Output is correct |
38 |
Correct |
112 ms |
22856 KB |
Output is correct |
39 |
Correct |
119 ms |
20428 KB |
Output is correct |
40 |
Correct |
99 ms |
16300 KB |
Output is correct |
41 |
Correct |
113 ms |
19708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
504 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
2 ms |
592 KB |
Output is correct |
12 |
Correct |
3 ms |
848 KB |
Output is correct |
13 |
Correct |
3 ms |
848 KB |
Output is correct |
14 |
Correct |
4 ms |
848 KB |
Output is correct |
15 |
Correct |
4 ms |
848 KB |
Output is correct |
16 |
Correct |
3 ms |
848 KB |
Output is correct |
17 |
Correct |
3 ms |
900 KB |
Output is correct |
18 |
Correct |
4 ms |
848 KB |
Output is correct |
19 |
Correct |
1037 ms |
96856 KB |
Output is correct |
20 |
Correct |
1006 ms |
108652 KB |
Output is correct |
21 |
Correct |
1080 ms |
116616 KB |
Output is correct |
22 |
Correct |
1072 ms |
108736 KB |
Output is correct |
23 |
Correct |
950 ms |
100168 KB |
Output is correct |
24 |
Correct |
70 ms |
13896 KB |
Output is correct |
25 |
Correct |
66 ms |
14300 KB |
Output is correct |
26 |
Correct |
61 ms |
10612 KB |
Output is correct |
27 |
Correct |
60 ms |
10568 KB |
Output is correct |
28 |
Correct |
63 ms |
10568 KB |
Output is correct |
29 |
Correct |
53 ms |
12468 KB |
Output is correct |
30 |
Correct |
49 ms |
12368 KB |
Output is correct |
31 |
Correct |
63 ms |
10248 KB |
Output is correct |
32 |
Correct |
28 ms |
4868 KB |
Output is correct |
33 |
Correct |
61 ms |
10248 KB |
Output is correct |
34 |
Correct |
162 ms |
24652 KB |
Output is correct |
35 |
Correct |
178 ms |
26696 KB |
Output is correct |
36 |
Correct |
149 ms |
26952 KB |
Output is correct |
37 |
Correct |
143 ms |
26952 KB |
Output is correct |
38 |
Correct |
145 ms |
26960 KB |
Output is correct |
39 |
Correct |
130 ms |
21320 KB |
Output is correct |
40 |
Correct |
120 ms |
21384 KB |
Output is correct |
41 |
Correct |
136 ms |
21156 KB |
Output is correct |
42 |
Correct |
137 ms |
21180 KB |
Output is correct |
43 |
Correct |
147 ms |
21156 KB |
Output is correct |
44 |
Correct |
151 ms |
21108 KB |
Output is correct |
45 |
Correct |
138 ms |
21064 KB |
Output is correct |
46 |
Correct |
144 ms |
21096 KB |
Output is correct |
47 |
Correct |
149 ms |
21076 KB |
Output is correct |
48 |
Correct |
163 ms |
21064 KB |
Output is correct |
49 |
Correct |
125 ms |
22856 KB |
Output is correct |
50 |
Correct |
119 ms |
22856 KB |
Output is correct |
51 |
Correct |
119 ms |
22520 KB |
Output is correct |
52 |
Correct |
113 ms |
22700 KB |
Output is correct |
53 |
Correct |
112 ms |
22856 KB |
Output is correct |
54 |
Correct |
119 ms |
20428 KB |
Output is correct |
55 |
Correct |
99 ms |
16300 KB |
Output is correct |
56 |
Correct |
113 ms |
19708 KB |
Output is correct |
57 |
Correct |
995 ms |
117136 KB |
Output is correct |
58 |
Correct |
1044 ms |
117384 KB |
Output is correct |
59 |
Correct |
1024 ms |
118040 KB |
Output is correct |
60 |
Correct |
972 ms |
118132 KB |
Output is correct |
61 |
Correct |
979 ms |
117924 KB |
Output is correct |
62 |
Correct |
1143 ms |
118012 KB |
Output is correct |
63 |
Correct |
691 ms |
102216 KB |
Output is correct |
64 |
Correct |
652 ms |
102216 KB |
Output is correct |
65 |
Correct |
862 ms |
102204 KB |
Output is correct |
66 |
Correct |
892 ms |
102216 KB |
Output is correct |
67 |
Correct |
843 ms |
102472 KB |
Output is correct |
68 |
Correct |
824 ms |
101448 KB |
Output is correct |
69 |
Correct |
880 ms |
101448 KB |
Output is correct |
70 |
Correct |
945 ms |
101540 KB |
Output is correct |
71 |
Correct |
899 ms |
101448 KB |
Output is correct |
72 |
Correct |
921 ms |
101412 KB |
Output is correct |
73 |
Correct |
653 ms |
100592 KB |
Output is correct |
74 |
Correct |
606 ms |
101192 KB |
Output is correct |
75 |
Correct |
596 ms |
100168 KB |
Output is correct |
76 |
Correct |
594 ms |
100660 KB |
Output is correct |
77 |
Correct |
594 ms |
100424 KB |
Output is correct |
78 |
Correct |
812 ms |
98340 KB |
Output is correct |
79 |
Correct |
545 ms |
70960 KB |
Output is correct |
80 |
Correct |
734 ms |
89112 KB |
Output is correct |