#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<ll,ll>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=1e6+10;
const ll inf=1e18;
const ll mod=1e9+7;
ll n,q;
struct IT
{
ll st[4*maxN];
void update(ll pos,ll val,ll id=1,ll l=1,ll r=n)
{
if(l==r)
{
st[id]=val;
return;
}
ll mid=l+r>>1;
if(pos<=mid) update(pos,val,id*2,l,mid);
else update(pos,val,id*2+1,mid+1,r);
st[id]=max(st[id*2],st[id*2+1]);
}
ll get(ll i,ll j,ll id=1,ll l=1,ll r=n)
{
if(i>j||j<l||r<i) return -inf;
if(i<=l&&r<=j) return st[id];
ll mid=l+r>>1;
return max(get(i,j,id*2,l,mid),get(i,j,id*2+1,mid+1,r));
}
}it1,it2;
ll a[maxN],k[maxN],ans[maxN];
vector<pli>hoi[maxN];
void solve()
{
cin >> n >> q;
for(int i=1;i<=n;i++) cin >> a[i];
for(int i=1;i<=q;i++)
{
ll l,r;
cin >> l >> r>> k[i];
hoi[r].pb({l,i});
}
deque<int>dq;
for(int i=1;i<=n;i++) it1.update(i,a[i]),it2.update(i,-inf);
for(int i=1;i<=n;i++)
{
while(!dq.empty()&&a[i]>=a[dq.back()])
{
ll id=dq.back();
it2.update(id,it1.get(id+1,i-1)+a[id]);
dq.pop_back();
}
for(auto zz:hoi[i])
{
ans[zz.se]=it2.get(zz.fi,i);
ll cc=lower_bound(dq.begin(),dq.end(),zz.fi)-dq.begin();
if(cc<dq.size())
{
ans[zz.se]=max(ans[zz.se],a[dq[cc]]+it1.get(dq[cc]+1,i));
}
}
dq.push_back(i);
}
for(int i=1;i<=q;i++)
{
//cout << ans[i]<<'\n';
if(k[i]>=ans[i]) cout << 1<<'\n';
else cout << 0<<'\n';
}
}
int main()
{
fastio
//freopen(TASKNAME".INP","r",stdin);
//freopen(TASKNAME".OUT","w",stdout);
solve();
}
Compilation message
sortbooks.cpp: In member function 'void IT::update(ll, ll, ll, ll, ll)':
sortbooks.cpp:24:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
24 | ll mid=l+r>>1;
| ~^~
sortbooks.cpp: In member function 'll IT::get(ll, ll, ll, ll, ll)':
sortbooks.cpp:33:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
33 | ll mid=l+r>>1;
| ~^~
sortbooks.cpp: In function 'void solve()':
sortbooks.cpp:63:18: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::deque<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | if(cc<dq.size())
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23816 KB |
Output is correct |
2 |
Correct |
13 ms |
23804 KB |
Output is correct |
3 |
Correct |
15 ms |
23800 KB |
Output is correct |
4 |
Correct |
17 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23816 KB |
Output is correct |
6 |
Correct |
13 ms |
23892 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
14 ms |
23856 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23872 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23816 KB |
Output is correct |
2 |
Correct |
13 ms |
23804 KB |
Output is correct |
3 |
Correct |
15 ms |
23800 KB |
Output is correct |
4 |
Correct |
17 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23816 KB |
Output is correct |
6 |
Correct |
13 ms |
23892 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
14 ms |
23856 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23872 KB |
Output is correct |
11 |
Correct |
21 ms |
24008 KB |
Output is correct |
12 |
Correct |
16 ms |
24276 KB |
Output is correct |
13 |
Correct |
19 ms |
24300 KB |
Output is correct |
14 |
Correct |
22 ms |
24424 KB |
Output is correct |
15 |
Correct |
18 ms |
24472 KB |
Output is correct |
16 |
Correct |
16 ms |
24452 KB |
Output is correct |
17 |
Correct |
14 ms |
24296 KB |
Output is correct |
18 |
Correct |
18 ms |
24368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1988 ms |
140128 KB |
Output is correct |
2 |
Correct |
2019 ms |
141152 KB |
Output is correct |
3 |
Correct |
1867 ms |
141008 KB |
Output is correct |
4 |
Correct |
1784 ms |
141172 KB |
Output is correct |
5 |
Correct |
1502 ms |
141284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
165 ms |
34976 KB |
Output is correct |
2 |
Correct |
124 ms |
34792 KB |
Output is correct |
3 |
Correct |
101 ms |
34988 KB |
Output is correct |
4 |
Correct |
113 ms |
34924 KB |
Output is correct |
5 |
Correct |
111 ms |
34996 KB |
Output is correct |
6 |
Correct |
93 ms |
34448 KB |
Output is correct |
7 |
Correct |
86 ms |
34564 KB |
Output is correct |
8 |
Correct |
110 ms |
34460 KB |
Output is correct |
9 |
Correct |
50 ms |
28800 KB |
Output is correct |
10 |
Correct |
113 ms |
34432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23816 KB |
Output is correct |
2 |
Correct |
13 ms |
23804 KB |
Output is correct |
3 |
Correct |
15 ms |
23800 KB |
Output is correct |
4 |
Correct |
17 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23816 KB |
Output is correct |
6 |
Correct |
13 ms |
23892 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
14 ms |
23856 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23872 KB |
Output is correct |
11 |
Correct |
21 ms |
24008 KB |
Output is correct |
12 |
Correct |
16 ms |
24276 KB |
Output is correct |
13 |
Correct |
19 ms |
24300 KB |
Output is correct |
14 |
Correct |
22 ms |
24424 KB |
Output is correct |
15 |
Correct |
18 ms |
24472 KB |
Output is correct |
16 |
Correct |
16 ms |
24452 KB |
Output is correct |
17 |
Correct |
14 ms |
24296 KB |
Output is correct |
18 |
Correct |
18 ms |
24368 KB |
Output is correct |
19 |
Correct |
333 ms |
48876 KB |
Output is correct |
20 |
Correct |
294 ms |
48952 KB |
Output is correct |
21 |
Correct |
304 ms |
48340 KB |
Output is correct |
22 |
Correct |
251 ms |
48328 KB |
Output is correct |
23 |
Correct |
269 ms |
48384 KB |
Output is correct |
24 |
Correct |
199 ms |
48292 KB |
Output is correct |
25 |
Correct |
231 ms |
48300 KB |
Output is correct |
26 |
Correct |
220 ms |
48716 KB |
Output is correct |
27 |
Correct |
226 ms |
48524 KB |
Output is correct |
28 |
Correct |
222 ms |
48716 KB |
Output is correct |
29 |
Correct |
236 ms |
48824 KB |
Output is correct |
30 |
Correct |
236 ms |
48860 KB |
Output is correct |
31 |
Correct |
253 ms |
48796 KB |
Output is correct |
32 |
Correct |
239 ms |
48844 KB |
Output is correct |
33 |
Correct |
256 ms |
48824 KB |
Output is correct |
34 |
Correct |
186 ms |
47820 KB |
Output is correct |
35 |
Correct |
198 ms |
47840 KB |
Output is correct |
36 |
Correct |
194 ms |
47504 KB |
Output is correct |
37 |
Correct |
183 ms |
47568 KB |
Output is correct |
38 |
Correct |
230 ms |
47812 KB |
Output is correct |
39 |
Correct |
226 ms |
46988 KB |
Output is correct |
40 |
Correct |
185 ms |
41280 KB |
Output is correct |
41 |
Correct |
216 ms |
46492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
23816 KB |
Output is correct |
2 |
Correct |
13 ms |
23804 KB |
Output is correct |
3 |
Correct |
15 ms |
23800 KB |
Output is correct |
4 |
Correct |
17 ms |
23764 KB |
Output is correct |
5 |
Correct |
14 ms |
23816 KB |
Output is correct |
6 |
Correct |
13 ms |
23892 KB |
Output is correct |
7 |
Correct |
13 ms |
23892 KB |
Output is correct |
8 |
Correct |
14 ms |
23856 KB |
Output is correct |
9 |
Correct |
13 ms |
23764 KB |
Output is correct |
10 |
Correct |
13 ms |
23872 KB |
Output is correct |
11 |
Correct |
21 ms |
24008 KB |
Output is correct |
12 |
Correct |
16 ms |
24276 KB |
Output is correct |
13 |
Correct |
19 ms |
24300 KB |
Output is correct |
14 |
Correct |
22 ms |
24424 KB |
Output is correct |
15 |
Correct |
18 ms |
24472 KB |
Output is correct |
16 |
Correct |
16 ms |
24452 KB |
Output is correct |
17 |
Correct |
14 ms |
24296 KB |
Output is correct |
18 |
Correct |
18 ms |
24368 KB |
Output is correct |
19 |
Correct |
1988 ms |
140128 KB |
Output is correct |
20 |
Correct |
2019 ms |
141152 KB |
Output is correct |
21 |
Correct |
1867 ms |
141008 KB |
Output is correct |
22 |
Correct |
1784 ms |
141172 KB |
Output is correct |
23 |
Correct |
1502 ms |
141284 KB |
Output is correct |
24 |
Correct |
165 ms |
34976 KB |
Output is correct |
25 |
Correct |
124 ms |
34792 KB |
Output is correct |
26 |
Correct |
101 ms |
34988 KB |
Output is correct |
27 |
Correct |
113 ms |
34924 KB |
Output is correct |
28 |
Correct |
111 ms |
34996 KB |
Output is correct |
29 |
Correct |
93 ms |
34448 KB |
Output is correct |
30 |
Correct |
86 ms |
34564 KB |
Output is correct |
31 |
Correct |
110 ms |
34460 KB |
Output is correct |
32 |
Correct |
50 ms |
28800 KB |
Output is correct |
33 |
Correct |
113 ms |
34432 KB |
Output is correct |
34 |
Correct |
333 ms |
48876 KB |
Output is correct |
35 |
Correct |
294 ms |
48952 KB |
Output is correct |
36 |
Correct |
304 ms |
48340 KB |
Output is correct |
37 |
Correct |
251 ms |
48328 KB |
Output is correct |
38 |
Correct |
269 ms |
48384 KB |
Output is correct |
39 |
Correct |
199 ms |
48292 KB |
Output is correct |
40 |
Correct |
231 ms |
48300 KB |
Output is correct |
41 |
Correct |
220 ms |
48716 KB |
Output is correct |
42 |
Correct |
226 ms |
48524 KB |
Output is correct |
43 |
Correct |
222 ms |
48716 KB |
Output is correct |
44 |
Correct |
236 ms |
48824 KB |
Output is correct |
45 |
Correct |
236 ms |
48860 KB |
Output is correct |
46 |
Correct |
253 ms |
48796 KB |
Output is correct |
47 |
Correct |
239 ms |
48844 KB |
Output is correct |
48 |
Correct |
256 ms |
48824 KB |
Output is correct |
49 |
Correct |
186 ms |
47820 KB |
Output is correct |
50 |
Correct |
198 ms |
47840 KB |
Output is correct |
51 |
Correct |
194 ms |
47504 KB |
Output is correct |
52 |
Correct |
183 ms |
47568 KB |
Output is correct |
53 |
Correct |
230 ms |
47812 KB |
Output is correct |
54 |
Correct |
226 ms |
46988 KB |
Output is correct |
55 |
Correct |
185 ms |
41280 KB |
Output is correct |
56 |
Correct |
216 ms |
46492 KB |
Output is correct |
57 |
Correct |
1772 ms |
141432 KB |
Output is correct |
58 |
Correct |
1737 ms |
141424 KB |
Output is correct |
59 |
Correct |
1612 ms |
140492 KB |
Output is correct |
60 |
Correct |
1669 ms |
140492 KB |
Output is correct |
61 |
Correct |
1695 ms |
140400 KB |
Output is correct |
62 |
Correct |
1699 ms |
140504 KB |
Output is correct |
63 |
Correct |
1034 ms |
138108 KB |
Output is correct |
64 |
Correct |
1072 ms |
138100 KB |
Output is correct |
65 |
Correct |
1748 ms |
140308 KB |
Output is correct |
66 |
Correct |
1360 ms |
140600 KB |
Output is correct |
67 |
Correct |
1342 ms |
140364 KB |
Output is correct |
68 |
Correct |
1435 ms |
141412 KB |
Output is correct |
69 |
Correct |
1491 ms |
141328 KB |
Output is correct |
70 |
Correct |
1425 ms |
141268 KB |
Output is correct |
71 |
Correct |
1525 ms |
141120 KB |
Output is correct |
72 |
Correct |
1427 ms |
141216 KB |
Output is correct |
73 |
Correct |
993 ms |
133160 KB |
Output is correct |
74 |
Correct |
1073 ms |
133840 KB |
Output is correct |
75 |
Correct |
980 ms |
133076 KB |
Output is correct |
76 |
Correct |
1000 ms |
133376 KB |
Output is correct |
77 |
Correct |
981 ms |
132964 KB |
Output is correct |
78 |
Correct |
1275 ms |
133064 KB |
Output is correct |
79 |
Correct |
905 ms |
105776 KB |
Output is correct |
80 |
Correct |
1428 ms |
130020 KB |
Output is correct |