#include <bits/stdc++.h>
#include <bits/extc++.h>
//#define double long double
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(nullptr);
#define pb push_back
#define UNIQUE(a) sort(ALL(a));a.resize(unique(ALL(a))-a.begin());
#define ALL(X) X.begin(),X.end()
#define F(i,n) FF(i,0,(n))
#define F1(i,n) FF(i,1,(n)+1)
#define FF(i,n,m) for(int i=(int)n;i<int(m);++i)
#define rF(i,a,b) for(int i=a;i>=(int)b;--i)
#define mkp(a,b) make_pair(a,b)
#define Fi first
#define Se second
#define int ll
//#pragma GCC optimize("O3")//,unroll-loops
//#pragma GCC target("popcnt")
using namespace std;
template<typename T> bool remax(T& a, const T& b) {return b>a?a=b,1:0;}
template<typename T> bool remin(T& a, const T& b) {return b<a?a=b,1:0;}
using ll=long long;
using ull=unsigned long long;
using int128= __int128_t;
using uint128= __uint128_t;
using pii =pair<int,int> ;
const double pi=acos(-1);
const int N=1E6+5;
const ll M=105;
const ll INF_64=0x3f3f3f3f3f3f3f3f;
const int INF_32=0x3f3f3f3f;
const int16_t INF_16=0x3f3f;
const int klog=20;
const int mod=1000000007;//1000000007;//998244353
const double eps=1E-3;
void gen(){
}
int BIT[N]{};
int n,m;
int lowbit(int x){return x&(-x);}
void add(int i, int val) {
BIT[i] = val;
for (int j = i; j < n; j |= (j + 1)) {
remax(BIT[j], val);
}
}
int ask(int i) {
int res = 0;
for (int j = i; j >= 0; j = (j & (j + 1)) - 1) {
remax(res, BIT[j]);
}
return res;
}
int a[N];
int an[N];
vector<array<int,3>> Q[N];
void sol(){
cin>>n>>m;
F(i,n) cin>>a[i];
vector<int> stk;
vector<pii> seg;
F(i,n){
while(stk.size()&&a[stk.back()]<=a[i])
stk.pop_back();
if(stk.size())
seg.pb({stk.back(),i});
stk.pb(i);
}
sort(ALL(seg));
F(i,m){
int l,r,k;cin>>l>>r>>k;
Q[l-1].pb({r-1,k,i});
}
int id=seg.size()-1;
rF(i,n-1,0){
while(id>=0&&seg[id].Fi>=i){
add(seg[id].Se,a[seg[id].Fi]+a[seg[id].Se]);
--id;
}
for(auto [r,k,ii]:Q[i])
an[ii]=(ask(r)<=k)?1:0;
}
F(i,m) cout<<an[i]<<"\n";
}
int32_t main(){
#ifdef LOCAL
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
#endif // LOCAL
IOS;
int t=1;
gen();
//cin>>t;
FF(i,1,t+1){
//cout<<"Case #"<<i<<": ";
sol();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Correct |
14 ms |
23776 KB |
Output is correct |
3 |
Correct |
12 ms |
23848 KB |
Output is correct |
4 |
Correct |
12 ms |
23756 KB |
Output is correct |
5 |
Correct |
13 ms |
23756 KB |
Output is correct |
6 |
Correct |
13 ms |
23812 KB |
Output is correct |
7 |
Correct |
13 ms |
23852 KB |
Output is correct |
8 |
Correct |
12 ms |
23824 KB |
Output is correct |
9 |
Correct |
12 ms |
23804 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Correct |
14 ms |
23776 KB |
Output is correct |
3 |
Correct |
12 ms |
23848 KB |
Output is correct |
4 |
Correct |
12 ms |
23756 KB |
Output is correct |
5 |
Correct |
13 ms |
23756 KB |
Output is correct |
6 |
Correct |
13 ms |
23812 KB |
Output is correct |
7 |
Correct |
13 ms |
23852 KB |
Output is correct |
8 |
Correct |
12 ms |
23824 KB |
Output is correct |
9 |
Correct |
12 ms |
23804 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
14 ms |
23896 KB |
Output is correct |
12 |
Correct |
14 ms |
24136 KB |
Output is correct |
13 |
Correct |
17 ms |
24016 KB |
Output is correct |
14 |
Correct |
14 ms |
24140 KB |
Output is correct |
15 |
Correct |
15 ms |
24204 KB |
Output is correct |
16 |
Correct |
14 ms |
24080 KB |
Output is correct |
17 |
Correct |
14 ms |
24092 KB |
Output is correct |
18 |
Correct |
15 ms |
24140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
923 ms |
97432 KB |
Output is correct |
2 |
Correct |
925 ms |
97400 KB |
Output is correct |
3 |
Correct |
938 ms |
97420 KB |
Output is correct |
4 |
Correct |
976 ms |
97452 KB |
Output is correct |
5 |
Correct |
785 ms |
73888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
66 ms |
31060 KB |
Output is correct |
2 |
Correct |
65 ms |
31688 KB |
Output is correct |
3 |
Correct |
62 ms |
28784 KB |
Output is correct |
4 |
Correct |
66 ms |
28748 KB |
Output is correct |
5 |
Correct |
83 ms |
28712 KB |
Output is correct |
6 |
Correct |
52 ms |
29104 KB |
Output is correct |
7 |
Correct |
49 ms |
29152 KB |
Output is correct |
8 |
Correct |
57 ms |
30900 KB |
Output is correct |
9 |
Correct |
39 ms |
27692 KB |
Output is correct |
10 |
Correct |
56 ms |
29804 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Correct |
14 ms |
23776 KB |
Output is correct |
3 |
Correct |
12 ms |
23848 KB |
Output is correct |
4 |
Correct |
12 ms |
23756 KB |
Output is correct |
5 |
Correct |
13 ms |
23756 KB |
Output is correct |
6 |
Correct |
13 ms |
23812 KB |
Output is correct |
7 |
Correct |
13 ms |
23852 KB |
Output is correct |
8 |
Correct |
12 ms |
23824 KB |
Output is correct |
9 |
Correct |
12 ms |
23804 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
14 ms |
23896 KB |
Output is correct |
12 |
Correct |
14 ms |
24136 KB |
Output is correct |
13 |
Correct |
17 ms |
24016 KB |
Output is correct |
14 |
Correct |
14 ms |
24140 KB |
Output is correct |
15 |
Correct |
15 ms |
24204 KB |
Output is correct |
16 |
Correct |
14 ms |
24080 KB |
Output is correct |
17 |
Correct |
14 ms |
24092 KB |
Output is correct |
18 |
Correct |
15 ms |
24140 KB |
Output is correct |
19 |
Correct |
181 ms |
38460 KB |
Output is correct |
20 |
Correct |
161 ms |
38492 KB |
Output is correct |
21 |
Correct |
139 ms |
39588 KB |
Output is correct |
22 |
Correct |
160 ms |
39588 KB |
Output is correct |
23 |
Correct |
147 ms |
39544 KB |
Output is correct |
24 |
Correct |
112 ms |
35000 KB |
Output is correct |
25 |
Correct |
122 ms |
34936 KB |
Output is correct |
26 |
Correct |
153 ms |
34376 KB |
Output is correct |
27 |
Correct |
132 ms |
34376 KB |
Output is correct |
28 |
Correct |
131 ms |
34116 KB |
Output is correct |
29 |
Correct |
147 ms |
33772 KB |
Output is correct |
30 |
Correct |
158 ms |
33648 KB |
Output is correct |
31 |
Correct |
143 ms |
33888 KB |
Output is correct |
32 |
Correct |
135 ms |
33736 KB |
Output is correct |
33 |
Correct |
141 ms |
33756 KB |
Output is correct |
34 |
Correct |
153 ms |
33988 KB |
Output is correct |
35 |
Correct |
103 ms |
33896 KB |
Output is correct |
36 |
Correct |
95 ms |
34000 KB |
Output is correct |
37 |
Correct |
96 ms |
33984 KB |
Output is correct |
38 |
Correct |
102 ms |
34016 KB |
Output is correct |
39 |
Correct |
140 ms |
35032 KB |
Output is correct |
40 |
Correct |
111 ms |
33116 KB |
Output is correct |
41 |
Correct |
117 ms |
35928 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
23756 KB |
Output is correct |
2 |
Correct |
14 ms |
23776 KB |
Output is correct |
3 |
Correct |
12 ms |
23848 KB |
Output is correct |
4 |
Correct |
12 ms |
23756 KB |
Output is correct |
5 |
Correct |
13 ms |
23756 KB |
Output is correct |
6 |
Correct |
13 ms |
23812 KB |
Output is correct |
7 |
Correct |
13 ms |
23852 KB |
Output is correct |
8 |
Correct |
12 ms |
23824 KB |
Output is correct |
9 |
Correct |
12 ms |
23804 KB |
Output is correct |
10 |
Correct |
12 ms |
23756 KB |
Output is correct |
11 |
Correct |
14 ms |
23896 KB |
Output is correct |
12 |
Correct |
14 ms |
24136 KB |
Output is correct |
13 |
Correct |
17 ms |
24016 KB |
Output is correct |
14 |
Correct |
14 ms |
24140 KB |
Output is correct |
15 |
Correct |
15 ms |
24204 KB |
Output is correct |
16 |
Correct |
14 ms |
24080 KB |
Output is correct |
17 |
Correct |
14 ms |
24092 KB |
Output is correct |
18 |
Correct |
15 ms |
24140 KB |
Output is correct |
19 |
Correct |
923 ms |
97432 KB |
Output is correct |
20 |
Correct |
925 ms |
97400 KB |
Output is correct |
21 |
Correct |
938 ms |
97420 KB |
Output is correct |
22 |
Correct |
976 ms |
97452 KB |
Output is correct |
23 |
Correct |
785 ms |
73888 KB |
Output is correct |
24 |
Correct |
66 ms |
31060 KB |
Output is correct |
25 |
Correct |
65 ms |
31688 KB |
Output is correct |
26 |
Correct |
62 ms |
28784 KB |
Output is correct |
27 |
Correct |
66 ms |
28748 KB |
Output is correct |
28 |
Correct |
83 ms |
28712 KB |
Output is correct |
29 |
Correct |
52 ms |
29104 KB |
Output is correct |
30 |
Correct |
49 ms |
29152 KB |
Output is correct |
31 |
Correct |
57 ms |
30900 KB |
Output is correct |
32 |
Correct |
39 ms |
27692 KB |
Output is correct |
33 |
Correct |
56 ms |
29804 KB |
Output is correct |
34 |
Correct |
181 ms |
38460 KB |
Output is correct |
35 |
Correct |
161 ms |
38492 KB |
Output is correct |
36 |
Correct |
139 ms |
39588 KB |
Output is correct |
37 |
Correct |
160 ms |
39588 KB |
Output is correct |
38 |
Correct |
147 ms |
39544 KB |
Output is correct |
39 |
Correct |
112 ms |
35000 KB |
Output is correct |
40 |
Correct |
122 ms |
34936 KB |
Output is correct |
41 |
Correct |
153 ms |
34376 KB |
Output is correct |
42 |
Correct |
132 ms |
34376 KB |
Output is correct |
43 |
Correct |
131 ms |
34116 KB |
Output is correct |
44 |
Correct |
147 ms |
33772 KB |
Output is correct |
45 |
Correct |
158 ms |
33648 KB |
Output is correct |
46 |
Correct |
143 ms |
33888 KB |
Output is correct |
47 |
Correct |
135 ms |
33736 KB |
Output is correct |
48 |
Correct |
141 ms |
33756 KB |
Output is correct |
49 |
Correct |
153 ms |
33988 KB |
Output is correct |
50 |
Correct |
103 ms |
33896 KB |
Output is correct |
51 |
Correct |
95 ms |
34000 KB |
Output is correct |
52 |
Correct |
96 ms |
33984 KB |
Output is correct |
53 |
Correct |
102 ms |
34016 KB |
Output is correct |
54 |
Correct |
140 ms |
35032 KB |
Output is correct |
55 |
Correct |
111 ms |
33116 KB |
Output is correct |
56 |
Correct |
117 ms |
35928 KB |
Output is correct |
57 |
Correct |
952 ms |
97096 KB |
Output is correct |
58 |
Correct |
988 ms |
97044 KB |
Output is correct |
59 |
Correct |
896 ms |
98924 KB |
Output is correct |
60 |
Correct |
900 ms |
98836 KB |
Output is correct |
61 |
Correct |
900 ms |
98856 KB |
Output is correct |
62 |
Correct |
884 ms |
98860 KB |
Output is correct |
63 |
Correct |
550 ms |
74720 KB |
Output is correct |
64 |
Correct |
508 ms |
74468 KB |
Output is correct |
65 |
Correct |
836 ms |
75888 KB |
Output is correct |
66 |
Correct |
758 ms |
75724 KB |
Output is correct |
67 |
Correct |
833 ms |
75552 KB |
Output is correct |
68 |
Correct |
819 ms |
73584 KB |
Output is correct |
69 |
Correct |
844 ms |
73792 KB |
Output is correct |
70 |
Correct |
802 ms |
73896 KB |
Output is correct |
71 |
Correct |
859 ms |
73720 KB |
Output is correct |
72 |
Correct |
819 ms |
73888 KB |
Output is correct |
73 |
Correct |
502 ms |
72440 KB |
Output is correct |
74 |
Correct |
490 ms |
72180 KB |
Output is correct |
75 |
Correct |
447 ms |
72156 KB |
Output is correct |
76 |
Correct |
446 ms |
72536 KB |
Output is correct |
77 |
Correct |
483 ms |
72492 KB |
Output is correct |
78 |
Correct |
676 ms |
80104 KB |
Output is correct |
79 |
Correct |
507 ms |
68920 KB |
Output is correct |
80 |
Correct |
722 ms |
89120 KB |
Output is correct |