#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
struct qqq
{
long long l,k,num;
qqq(){}
qqq(long long li, long long ki, long long ni)
{
l = li;
k = ki;
num = ni;
}
};
const long long maxn = 1e6+5;
long long n,m,w[maxn];
pair<long long,long long> inv[maxn];
vector<qqq> q[maxn];
long long ans[maxn],tree[4*maxn];
long long ql,qr,val;
void make_inv()
{
w[0] = 1e9+1;
stack<long long>s1;
s1.push(0);
for(long long i = 1; i <= n; i++)
{
while(!s1.empty()&&w[s1.top()]<=w[i]) s1.pop();
inv[i].first = w[i] + w[s1.top()];
inv[i].second = s1.top();
s1.push(i);
}
}
void read()
{
cin >> n >> m;
for(long long i = 1; i <= n; i++) cin >> w[i];
make_inv();
long long l,r,k;
for(long long i = 1; i <= m; i++)
{
cin >> l >> r >> k;
q[r].push_back({l,k,i});
}
}
void update(long long v, long long l, long long r)
{
if(r<ql||qr<l||l>r) return;
if(ql<=l&&r<=qr)
{
tree[v] = max(tree[v],val);
return;
}
long long mid = (l+r)/2;
update(v*2+0,l,mid+0);
update(v*2+1,mid+1,r);
tree[v] = max(tree[v*2+0],tree[v*2+1]);
}
long long query(long long v, long long l, long long r)
{
if(r<ql||qr<l||l>r) return 0;
if(ql<=l&&r<=qr)return tree[v];
long long mid = (l+r)/2;
return max(query(v*2+0,l,mid+0),query(v*2+1,mid+1,r));
}
void solve()
{
for(long long i = 1; i <= n; i++)
{
if(inv[i].second != 0)
{
ql = qr = inv[i].second;
val = inv[i].first;
update(1,1,n);
}
for(qqq nb : q[i])
{
ql = nb.l;
qr = i;
ans[nb.num] = (nb.k >= query(1,1,n));
}
}
for(long long i = 1; i <= m; i++) cout << ans[i] << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
read();
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
31068 KB |
Output is correct |
2 |
Correct |
4 ms |
31068 KB |
Output is correct |
3 |
Correct |
4 ms |
31068 KB |
Output is correct |
4 |
Correct |
4 ms |
31256 KB |
Output is correct |
5 |
Correct |
5 ms |
31192 KB |
Output is correct |
6 |
Correct |
5 ms |
31068 KB |
Output is correct |
7 |
Correct |
5 ms |
31068 KB |
Output is correct |
8 |
Correct |
4 ms |
31068 KB |
Output is correct |
9 |
Correct |
5 ms |
31068 KB |
Output is correct |
10 |
Correct |
5 ms |
31068 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
31068 KB |
Output is correct |
2 |
Correct |
4 ms |
31068 KB |
Output is correct |
3 |
Correct |
4 ms |
31068 KB |
Output is correct |
4 |
Correct |
4 ms |
31256 KB |
Output is correct |
5 |
Correct |
5 ms |
31192 KB |
Output is correct |
6 |
Correct |
5 ms |
31068 KB |
Output is correct |
7 |
Correct |
5 ms |
31068 KB |
Output is correct |
8 |
Correct |
4 ms |
31068 KB |
Output is correct |
9 |
Correct |
5 ms |
31068 KB |
Output is correct |
10 |
Correct |
5 ms |
31068 KB |
Output is correct |
11 |
Correct |
6 ms |
31324 KB |
Output is correct |
12 |
Correct |
7 ms |
31452 KB |
Output is correct |
13 |
Correct |
7 ms |
31580 KB |
Output is correct |
14 |
Correct |
8 ms |
31696 KB |
Output is correct |
15 |
Correct |
9 ms |
31700 KB |
Output is correct |
16 |
Correct |
7 ms |
31444 KB |
Output is correct |
17 |
Correct |
7 ms |
31324 KB |
Output is correct |
18 |
Correct |
6 ms |
31324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
976 ms |
106488 KB |
Output is correct |
2 |
Correct |
984 ms |
106580 KB |
Output is correct |
3 |
Correct |
952 ms |
106304 KB |
Output is correct |
4 |
Correct |
997 ms |
106436 KB |
Output is correct |
5 |
Correct |
783 ms |
90120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
71 ms |
38736 KB |
Output is correct |
2 |
Correct |
66 ms |
40784 KB |
Output is correct |
3 |
Correct |
62 ms |
38592 KB |
Output is correct |
4 |
Correct |
59 ms |
38740 KB |
Output is correct |
5 |
Correct |
64 ms |
38584 KB |
Output is correct |
6 |
Correct |
54 ms |
38492 KB |
Output is correct |
7 |
Correct |
50 ms |
38492 KB |
Output is correct |
8 |
Correct |
56 ms |
38144 KB |
Output is correct |
9 |
Correct |
29 ms |
35644 KB |
Output is correct |
10 |
Correct |
57 ms |
37932 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
31068 KB |
Output is correct |
2 |
Correct |
4 ms |
31068 KB |
Output is correct |
3 |
Correct |
4 ms |
31068 KB |
Output is correct |
4 |
Correct |
4 ms |
31256 KB |
Output is correct |
5 |
Correct |
5 ms |
31192 KB |
Output is correct |
6 |
Correct |
5 ms |
31068 KB |
Output is correct |
7 |
Correct |
5 ms |
31068 KB |
Output is correct |
8 |
Correct |
4 ms |
31068 KB |
Output is correct |
9 |
Correct |
5 ms |
31068 KB |
Output is correct |
10 |
Correct |
5 ms |
31068 KB |
Output is correct |
11 |
Correct |
6 ms |
31324 KB |
Output is correct |
12 |
Correct |
7 ms |
31452 KB |
Output is correct |
13 |
Correct |
7 ms |
31580 KB |
Output is correct |
14 |
Correct |
8 ms |
31696 KB |
Output is correct |
15 |
Correct |
9 ms |
31700 KB |
Output is correct |
16 |
Correct |
7 ms |
31444 KB |
Output is correct |
17 |
Correct |
7 ms |
31324 KB |
Output is correct |
18 |
Correct |
6 ms |
31324 KB |
Output is correct |
19 |
Correct |
170 ms |
50772 KB |
Output is correct |
20 |
Correct |
159 ms |
50664 KB |
Output is correct |
21 |
Correct |
181 ms |
51284 KB |
Output is correct |
22 |
Correct |
149 ms |
51296 KB |
Output is correct |
23 |
Correct |
142 ms |
51184 KB |
Output is correct |
24 |
Correct |
113 ms |
47188 KB |
Output is correct |
25 |
Correct |
116 ms |
47076 KB |
Output is correct |
26 |
Correct |
123 ms |
46980 KB |
Output is correct |
27 |
Correct |
134 ms |
46928 KB |
Output is correct |
28 |
Correct |
128 ms |
46676 KB |
Output is correct |
29 |
Correct |
137 ms |
46844 KB |
Output is correct |
30 |
Correct |
136 ms |
46676 KB |
Output is correct |
31 |
Correct |
140 ms |
46680 KB |
Output is correct |
32 |
Correct |
129 ms |
46676 KB |
Output is correct |
33 |
Correct |
139 ms |
46672 KB |
Output is correct |
34 |
Correct |
107 ms |
46416 KB |
Output is correct |
35 |
Correct |
149 ms |
46420 KB |
Output is correct |
36 |
Correct |
116 ms |
46140 KB |
Output is correct |
37 |
Correct |
102 ms |
46160 KB |
Output is correct |
38 |
Correct |
149 ms |
46416 KB |
Output is correct |
39 |
Correct |
128 ms |
46084 KB |
Output is correct |
40 |
Correct |
92 ms |
43512 KB |
Output is correct |
41 |
Correct |
118 ms |
44284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
31068 KB |
Output is correct |
2 |
Correct |
4 ms |
31068 KB |
Output is correct |
3 |
Correct |
4 ms |
31068 KB |
Output is correct |
4 |
Correct |
4 ms |
31256 KB |
Output is correct |
5 |
Correct |
5 ms |
31192 KB |
Output is correct |
6 |
Correct |
5 ms |
31068 KB |
Output is correct |
7 |
Correct |
5 ms |
31068 KB |
Output is correct |
8 |
Correct |
4 ms |
31068 KB |
Output is correct |
9 |
Correct |
5 ms |
31068 KB |
Output is correct |
10 |
Correct |
5 ms |
31068 KB |
Output is correct |
11 |
Correct |
6 ms |
31324 KB |
Output is correct |
12 |
Correct |
7 ms |
31452 KB |
Output is correct |
13 |
Correct |
7 ms |
31580 KB |
Output is correct |
14 |
Correct |
8 ms |
31696 KB |
Output is correct |
15 |
Correct |
9 ms |
31700 KB |
Output is correct |
16 |
Correct |
7 ms |
31444 KB |
Output is correct |
17 |
Correct |
7 ms |
31324 KB |
Output is correct |
18 |
Correct |
6 ms |
31324 KB |
Output is correct |
19 |
Correct |
976 ms |
106488 KB |
Output is correct |
20 |
Correct |
984 ms |
106580 KB |
Output is correct |
21 |
Correct |
952 ms |
106304 KB |
Output is correct |
22 |
Correct |
997 ms |
106436 KB |
Output is correct |
23 |
Correct |
783 ms |
90120 KB |
Output is correct |
24 |
Correct |
71 ms |
38736 KB |
Output is correct |
25 |
Correct |
66 ms |
40784 KB |
Output is correct |
26 |
Correct |
62 ms |
38592 KB |
Output is correct |
27 |
Correct |
59 ms |
38740 KB |
Output is correct |
28 |
Correct |
64 ms |
38584 KB |
Output is correct |
29 |
Correct |
54 ms |
38492 KB |
Output is correct |
30 |
Correct |
50 ms |
38492 KB |
Output is correct |
31 |
Correct |
56 ms |
38144 KB |
Output is correct |
32 |
Correct |
29 ms |
35644 KB |
Output is correct |
33 |
Correct |
57 ms |
37932 KB |
Output is correct |
34 |
Correct |
170 ms |
50772 KB |
Output is correct |
35 |
Correct |
159 ms |
50664 KB |
Output is correct |
36 |
Correct |
181 ms |
51284 KB |
Output is correct |
37 |
Correct |
149 ms |
51296 KB |
Output is correct |
38 |
Correct |
142 ms |
51184 KB |
Output is correct |
39 |
Correct |
113 ms |
47188 KB |
Output is correct |
40 |
Correct |
116 ms |
47076 KB |
Output is correct |
41 |
Correct |
123 ms |
46980 KB |
Output is correct |
42 |
Correct |
134 ms |
46928 KB |
Output is correct |
43 |
Correct |
128 ms |
46676 KB |
Output is correct |
44 |
Correct |
137 ms |
46844 KB |
Output is correct |
45 |
Correct |
136 ms |
46676 KB |
Output is correct |
46 |
Correct |
140 ms |
46680 KB |
Output is correct |
47 |
Correct |
129 ms |
46676 KB |
Output is correct |
48 |
Correct |
139 ms |
46672 KB |
Output is correct |
49 |
Correct |
107 ms |
46416 KB |
Output is correct |
50 |
Correct |
149 ms |
46420 KB |
Output is correct |
51 |
Correct |
116 ms |
46140 KB |
Output is correct |
52 |
Correct |
102 ms |
46160 KB |
Output is correct |
53 |
Correct |
149 ms |
46416 KB |
Output is correct |
54 |
Correct |
128 ms |
46084 KB |
Output is correct |
55 |
Correct |
92 ms |
43512 KB |
Output is correct |
56 |
Correct |
118 ms |
44284 KB |
Output is correct |
57 |
Correct |
972 ms |
139996 KB |
Output is correct |
58 |
Correct |
1018 ms |
140008 KB |
Output is correct |
59 |
Correct |
943 ms |
140880 KB |
Output is correct |
60 |
Correct |
978 ms |
140648 KB |
Output is correct |
61 |
Correct |
991 ms |
140884 KB |
Output is correct |
62 |
Correct |
950 ms |
140884 KB |
Output is correct |
63 |
Correct |
625 ms |
124500 KB |
Output is correct |
64 |
Correct |
582 ms |
124644 KB |
Output is correct |
65 |
Correct |
756 ms |
124488 KB |
Output is correct |
66 |
Correct |
791 ms |
124500 KB |
Output is correct |
67 |
Correct |
793 ms |
124496 KB |
Output is correct |
68 |
Correct |
802 ms |
123696 KB |
Output is correct |
69 |
Correct |
784 ms |
123752 KB |
Output is correct |
70 |
Correct |
820 ms |
123876 KB |
Output is correct |
71 |
Correct |
770 ms |
123732 KB |
Output is correct |
72 |
Correct |
760 ms |
123732 KB |
Output is correct |
73 |
Correct |
531 ms |
122480 KB |
Output is correct |
74 |
Correct |
545 ms |
118864 KB |
Output is correct |
75 |
Correct |
553 ms |
122192 KB |
Output is correct |
76 |
Correct |
596 ms |
122448 KB |
Output is correct |
77 |
Correct |
556 ms |
121956 KB |
Output is correct |
78 |
Correct |
726 ms |
120340 KB |
Output is correct |
79 |
Correct |
542 ms |
99568 KB |
Output is correct |
80 |
Correct |
796 ms |
112108 KB |
Output is correct |