#include<bits/stdc++.h>
using namespace std;
#define ll int
const ll MAXN=1e6+6;
ll w[MAXN];
struct query
{
ll r,k,pos;
};
ll ans[MAXN];
vector<query>v[MAXN];
vector<ll>g[MAXN];
ll t[MAXN],n,m;
ll fen[MAXN];
void update(ll idx,ll val)
{
for(;idx<MAXN;idx+=idx&(-idx))
{
fen[idx]=max(fen[idx],val);
}
}
ll query(ll idx)
{
ll ret=0;
for(;idx>0;idx-=idx&(-idx))
{
ret=max(ret,fen[idx]);
}
return ret;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
for(ll i=1;i<=n;++i)cin>>w[i];
stack<pair<ll,ll> >st;
t[1]=-1;
st.push({w[1],1});
for(ll i=1;i<=n;++i)
{
while(!st.empty()&&st.top().first<=w[i])
{
st.pop();
}
if(st.empty())
{
t[i]=-1;
}
else t[i]=st.top().second;
st.push({w[i],i});
}
for(ll i=1;i<=n;++i)
{
if(t[i]==-1)continue;
g[t[i]].push_back(i);
}
for(ll i=1;i<=m;++i)
{
ll l,r,k;
cin>>l>>r>>k;
v[l].push_back({r,k,i});
}
for(ll i=n;i>=1;--i)
{
for(ll j=0;j<g[i].size();++j)
{
update(g[i][j],w[i]+w[g[i][j]]);
}
for(ll j=0;j<v[i].size();++j)
{
ll t=query(v[i][j].r);
if(t>v[i][j].k)ans[v[i][j].pos]=0;
else ans[v[i][j].pos]=1;
}
}
for(ll i=1;i<=m;++i)cout<<ans[i]<<'\n';
return 0;
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:67:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | for(ll j=0;j<g[i].size();++j)
| ~^~~~~~~~~~~~
sortbooks.cpp:71:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<query>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
71 | for(ll j=0;j<v[i].size();++j)
| ~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
47340 KB |
Output is correct |
2 |
Correct |
29 ms |
47468 KB |
Output is correct |
3 |
Correct |
29 ms |
47340 KB |
Output is correct |
4 |
Correct |
35 ms |
47340 KB |
Output is correct |
5 |
Correct |
30 ms |
47340 KB |
Output is correct |
6 |
Correct |
30 ms |
47440 KB |
Output is correct |
7 |
Correct |
30 ms |
47340 KB |
Output is correct |
8 |
Correct |
31 ms |
47340 KB |
Output is correct |
9 |
Correct |
30 ms |
47340 KB |
Output is correct |
10 |
Correct |
29 ms |
47460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
47340 KB |
Output is correct |
2 |
Correct |
29 ms |
47468 KB |
Output is correct |
3 |
Correct |
29 ms |
47340 KB |
Output is correct |
4 |
Correct |
35 ms |
47340 KB |
Output is correct |
5 |
Correct |
30 ms |
47340 KB |
Output is correct |
6 |
Correct |
30 ms |
47440 KB |
Output is correct |
7 |
Correct |
30 ms |
47340 KB |
Output is correct |
8 |
Correct |
31 ms |
47340 KB |
Output is correct |
9 |
Correct |
30 ms |
47340 KB |
Output is correct |
10 |
Correct |
29 ms |
47460 KB |
Output is correct |
11 |
Correct |
32 ms |
47468 KB |
Output is correct |
12 |
Correct |
33 ms |
47596 KB |
Output is correct |
13 |
Correct |
32 ms |
47596 KB |
Output is correct |
14 |
Correct |
34 ms |
47596 KB |
Output is correct |
15 |
Correct |
34 ms |
47596 KB |
Output is correct |
16 |
Correct |
37 ms |
47596 KB |
Output is correct |
17 |
Correct |
32 ms |
47596 KB |
Output is correct |
18 |
Correct |
32 ms |
47596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1082 ms |
102892 KB |
Output is correct |
2 |
Correct |
1102 ms |
109804 KB |
Output is correct |
3 |
Correct |
1085 ms |
109828 KB |
Output is correct |
4 |
Correct |
1091 ms |
109804 KB |
Output is correct |
5 |
Correct |
967 ms |
89580 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
110 ms |
52972 KB |
Output is correct |
2 |
Correct |
100 ms |
52972 KB |
Output is correct |
3 |
Correct |
96 ms |
50924 KB |
Output is correct |
4 |
Correct |
95 ms |
50924 KB |
Output is correct |
5 |
Correct |
107 ms |
50924 KB |
Output is correct |
6 |
Correct |
81 ms |
50540 KB |
Output is correct |
7 |
Correct |
78 ms |
50540 KB |
Output is correct |
8 |
Correct |
87 ms |
51112 KB |
Output is correct |
9 |
Correct |
66 ms |
49572 KB |
Output is correct |
10 |
Correct |
89 ms |
51112 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
47340 KB |
Output is correct |
2 |
Correct |
29 ms |
47468 KB |
Output is correct |
3 |
Correct |
29 ms |
47340 KB |
Output is correct |
4 |
Correct |
35 ms |
47340 KB |
Output is correct |
5 |
Correct |
30 ms |
47340 KB |
Output is correct |
6 |
Correct |
30 ms |
47440 KB |
Output is correct |
7 |
Correct |
30 ms |
47340 KB |
Output is correct |
8 |
Correct |
31 ms |
47340 KB |
Output is correct |
9 |
Correct |
30 ms |
47340 KB |
Output is correct |
10 |
Correct |
29 ms |
47460 KB |
Output is correct |
11 |
Correct |
32 ms |
47468 KB |
Output is correct |
12 |
Correct |
33 ms |
47596 KB |
Output is correct |
13 |
Correct |
32 ms |
47596 KB |
Output is correct |
14 |
Correct |
34 ms |
47596 KB |
Output is correct |
15 |
Correct |
34 ms |
47596 KB |
Output is correct |
16 |
Correct |
37 ms |
47596 KB |
Output is correct |
17 |
Correct |
32 ms |
47596 KB |
Output is correct |
18 |
Correct |
32 ms |
47596 KB |
Output is correct |
19 |
Correct |
222 ms |
58604 KB |
Output is correct |
20 |
Correct |
226 ms |
58732 KB |
Output is correct |
21 |
Correct |
187 ms |
58220 KB |
Output is correct |
22 |
Correct |
187 ms |
58220 KB |
Output is correct |
23 |
Correct |
197 ms |
58220 KB |
Output is correct |
24 |
Correct |
190 ms |
54112 KB |
Output is correct |
25 |
Correct |
160 ms |
54124 KB |
Output is correct |
26 |
Correct |
181 ms |
54228 KB |
Output is correct |
27 |
Correct |
176 ms |
54136 KB |
Output is correct |
28 |
Correct |
192 ms |
54252 KB |
Output is correct |
29 |
Correct |
195 ms |
54636 KB |
Output is correct |
30 |
Correct |
190 ms |
54636 KB |
Output is correct |
31 |
Correct |
196 ms |
54508 KB |
Output is correct |
32 |
Correct |
194 ms |
54636 KB |
Output is correct |
33 |
Correct |
202 ms |
54508 KB |
Output is correct |
34 |
Correct |
151 ms |
53496 KB |
Output is correct |
35 |
Correct |
153 ms |
53484 KB |
Output is correct |
36 |
Correct |
143 ms |
53484 KB |
Output is correct |
37 |
Correct |
144 ms |
53536 KB |
Output is correct |
38 |
Correct |
148 ms |
53484 KB |
Output is correct |
39 |
Correct |
171 ms |
55204 KB |
Output is correct |
40 |
Correct |
143 ms |
53152 KB |
Output is correct |
41 |
Correct |
168 ms |
54740 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
47340 KB |
Output is correct |
2 |
Correct |
29 ms |
47468 KB |
Output is correct |
3 |
Correct |
29 ms |
47340 KB |
Output is correct |
4 |
Correct |
35 ms |
47340 KB |
Output is correct |
5 |
Correct |
30 ms |
47340 KB |
Output is correct |
6 |
Correct |
30 ms |
47440 KB |
Output is correct |
7 |
Correct |
30 ms |
47340 KB |
Output is correct |
8 |
Correct |
31 ms |
47340 KB |
Output is correct |
9 |
Correct |
30 ms |
47340 KB |
Output is correct |
10 |
Correct |
29 ms |
47460 KB |
Output is correct |
11 |
Correct |
32 ms |
47468 KB |
Output is correct |
12 |
Correct |
33 ms |
47596 KB |
Output is correct |
13 |
Correct |
32 ms |
47596 KB |
Output is correct |
14 |
Correct |
34 ms |
47596 KB |
Output is correct |
15 |
Correct |
34 ms |
47596 KB |
Output is correct |
16 |
Correct |
37 ms |
47596 KB |
Output is correct |
17 |
Correct |
32 ms |
47596 KB |
Output is correct |
18 |
Correct |
32 ms |
47596 KB |
Output is correct |
19 |
Correct |
1082 ms |
102892 KB |
Output is correct |
20 |
Correct |
1102 ms |
109804 KB |
Output is correct |
21 |
Correct |
1085 ms |
109828 KB |
Output is correct |
22 |
Correct |
1091 ms |
109804 KB |
Output is correct |
23 |
Correct |
967 ms |
89580 KB |
Output is correct |
24 |
Correct |
110 ms |
52972 KB |
Output is correct |
25 |
Correct |
100 ms |
52972 KB |
Output is correct |
26 |
Correct |
96 ms |
50924 KB |
Output is correct |
27 |
Correct |
95 ms |
50924 KB |
Output is correct |
28 |
Correct |
107 ms |
50924 KB |
Output is correct |
29 |
Correct |
81 ms |
50540 KB |
Output is correct |
30 |
Correct |
78 ms |
50540 KB |
Output is correct |
31 |
Correct |
87 ms |
51112 KB |
Output is correct |
32 |
Correct |
66 ms |
49572 KB |
Output is correct |
33 |
Correct |
89 ms |
51112 KB |
Output is correct |
34 |
Correct |
222 ms |
58604 KB |
Output is correct |
35 |
Correct |
226 ms |
58732 KB |
Output is correct |
36 |
Correct |
187 ms |
58220 KB |
Output is correct |
37 |
Correct |
187 ms |
58220 KB |
Output is correct |
38 |
Correct |
197 ms |
58220 KB |
Output is correct |
39 |
Correct |
190 ms |
54112 KB |
Output is correct |
40 |
Correct |
160 ms |
54124 KB |
Output is correct |
41 |
Correct |
181 ms |
54228 KB |
Output is correct |
42 |
Correct |
176 ms |
54136 KB |
Output is correct |
43 |
Correct |
192 ms |
54252 KB |
Output is correct |
44 |
Correct |
195 ms |
54636 KB |
Output is correct |
45 |
Correct |
190 ms |
54636 KB |
Output is correct |
46 |
Correct |
196 ms |
54508 KB |
Output is correct |
47 |
Correct |
194 ms |
54636 KB |
Output is correct |
48 |
Correct |
202 ms |
54508 KB |
Output is correct |
49 |
Correct |
151 ms |
53496 KB |
Output is correct |
50 |
Correct |
153 ms |
53484 KB |
Output is correct |
51 |
Correct |
143 ms |
53484 KB |
Output is correct |
52 |
Correct |
144 ms |
53536 KB |
Output is correct |
53 |
Correct |
148 ms |
53484 KB |
Output is correct |
54 |
Correct |
171 ms |
55204 KB |
Output is correct |
55 |
Correct |
143 ms |
53152 KB |
Output is correct |
56 |
Correct |
168 ms |
54740 KB |
Output is correct |
57 |
Correct |
1125 ms |
111308 KB |
Output is correct |
58 |
Correct |
1104 ms |
110956 KB |
Output is correct |
59 |
Correct |
1053 ms |
108780 KB |
Output is correct |
60 |
Correct |
1044 ms |
109044 KB |
Output is correct |
61 |
Correct |
1087 ms |
108944 KB |
Output is correct |
62 |
Correct |
1071 ms |
108908 KB |
Output is correct |
63 |
Correct |
715 ms |
84500 KB |
Output is correct |
64 |
Correct |
671 ms |
84480 KB |
Output is correct |
65 |
Correct |
931 ms |
88732 KB |
Output is correct |
66 |
Correct |
920 ms |
88616 KB |
Output is correct |
67 |
Correct |
928 ms |
88684 KB |
Output is correct |
68 |
Correct |
965 ms |
90860 KB |
Output is correct |
69 |
Correct |
961 ms |
90860 KB |
Output is correct |
70 |
Correct |
947 ms |
90348 KB |
Output is correct |
71 |
Correct |
943 ms |
90348 KB |
Output is correct |
72 |
Correct |
954 ms |
90428 KB |
Output is correct |
73 |
Correct |
587 ms |
83420 KB |
Output is correct |
74 |
Correct |
629 ms |
83472 KB |
Output is correct |
75 |
Correct |
596 ms |
83564 KB |
Output is correct |
76 |
Correct |
592 ms |
83692 KB |
Output is correct |
77 |
Correct |
606 ms |
83692 KB |
Output is correct |
78 |
Correct |
854 ms |
92828 KB |
Output is correct |
79 |
Correct |
645 ms |
80996 KB |
Output is correct |
80 |
Correct |
819 ms |
90976 KB |
Output is correct |