#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef int lli;
typedef pair <lli,lli> ii;
typedef pair <lli,ii> iii;
typedef vector <lli> vi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int segt[4000001];
int n,m,ans[1000001]={};
int arr[1000001]={},pg[1000001];
vector<iii> que[1000001];
void up(int node,int l,int r,int in,int v)
{
if(l==r)
{
segt[node]=v;
return;
}
int mi=(l+r)/2;
if(in<=mi)
up(2*node+1,l,mi,in,v);
else
up(2*node+2,mi+1,r,in,v);
segt[node]=max(segt[2*node+1],segt[2*node+2]);
}
int qu(int node,int l,int r,int s,int e)
{
if(r<s||l>e)
return(0);
if(l>=s&&r<=e)
return(segt[node]);
int mi=(l+r)/2;
int q1=qu(2*node+1,l,mi,s,e),q2=qu(2*node+2,mi+1,r,s,e);
return(max(q1,q2));
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
stack<int> s;
for(int i=0;i<n;++i)
pg[i]=-1;
for(int i=0;i<n;++i)
{
cin>>arr[i];
while(s.size())
{
if(arr[s.top()]<=arr[i])
s.pop();
else
break;
}
if(s.size())
pg[i]=s.top();
s.push(i);
}
for(int i=0;i<m;++i)
{
int f,sec,k;
cin>>f>>sec>>k;
f--;
sec--;
que[sec].pb(mp(i,mp(f,k)));
}
for(int i=0;i<n;++i)
{
if(pg[i]!=-1)
up(0,0,n-1,pg[i],arr[pg[i]]+arr[i]);
for(int j=0;j<que[i].size();++j)
if(qu(0,0,n-1,que[i][j].S.F,i)<=que[i][j].S.S)
ans[que[i][j].F]=1;
}
for(int i=0;i<m;++i)
cout<<ans[i]<<'\n';
return(0);
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:82:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j=0;j<que[i].size();++j)
~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23808 KB |
Output is correct |
2 |
Correct |
14 ms |
23808 KB |
Output is correct |
3 |
Correct |
15 ms |
23808 KB |
Output is correct |
4 |
Correct |
15 ms |
23808 KB |
Output is correct |
5 |
Correct |
14 ms |
23808 KB |
Output is correct |
6 |
Correct |
15 ms |
23936 KB |
Output is correct |
7 |
Correct |
15 ms |
23808 KB |
Output is correct |
8 |
Correct |
14 ms |
23808 KB |
Output is correct |
9 |
Correct |
15 ms |
23808 KB |
Output is correct |
10 |
Correct |
15 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23808 KB |
Output is correct |
2 |
Correct |
14 ms |
23808 KB |
Output is correct |
3 |
Correct |
15 ms |
23808 KB |
Output is correct |
4 |
Correct |
15 ms |
23808 KB |
Output is correct |
5 |
Correct |
14 ms |
23808 KB |
Output is correct |
6 |
Correct |
15 ms |
23936 KB |
Output is correct |
7 |
Correct |
15 ms |
23808 KB |
Output is correct |
8 |
Correct |
14 ms |
23808 KB |
Output is correct |
9 |
Correct |
15 ms |
23808 KB |
Output is correct |
10 |
Correct |
15 ms |
23808 KB |
Output is correct |
11 |
Correct |
17 ms |
24064 KB |
Output is correct |
12 |
Correct |
18 ms |
24192 KB |
Output is correct |
13 |
Correct |
18 ms |
24192 KB |
Output is correct |
14 |
Correct |
20 ms |
24320 KB |
Output is correct |
15 |
Correct |
20 ms |
24192 KB |
Output is correct |
16 |
Correct |
19 ms |
24192 KB |
Output is correct |
17 |
Correct |
18 ms |
24192 KB |
Output is correct |
18 |
Correct |
18 ms |
24192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1498 ms |
63784 KB |
Output is correct |
2 |
Correct |
1555 ms |
63864 KB |
Output is correct |
3 |
Correct |
1490 ms |
63892 KB |
Output is correct |
4 |
Correct |
1493 ms |
63720 KB |
Output is correct |
5 |
Correct |
1291 ms |
59512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
125 ms |
28460 KB |
Output is correct |
2 |
Correct |
117 ms |
28892 KB |
Output is correct |
3 |
Correct |
111 ms |
28044 KB |
Output is correct |
4 |
Correct |
113 ms |
28152 KB |
Output is correct |
5 |
Correct |
109 ms |
28084 KB |
Output is correct |
6 |
Correct |
86 ms |
27256 KB |
Output is correct |
7 |
Correct |
93 ms |
27384 KB |
Output is correct |
8 |
Correct |
97 ms |
28084 KB |
Output is correct |
9 |
Correct |
55 ms |
26672 KB |
Output is correct |
10 |
Correct |
91 ms |
27948 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23808 KB |
Output is correct |
2 |
Correct |
14 ms |
23808 KB |
Output is correct |
3 |
Correct |
15 ms |
23808 KB |
Output is correct |
4 |
Correct |
15 ms |
23808 KB |
Output is correct |
5 |
Correct |
14 ms |
23808 KB |
Output is correct |
6 |
Correct |
15 ms |
23936 KB |
Output is correct |
7 |
Correct |
15 ms |
23808 KB |
Output is correct |
8 |
Correct |
14 ms |
23808 KB |
Output is correct |
9 |
Correct |
15 ms |
23808 KB |
Output is correct |
10 |
Correct |
15 ms |
23808 KB |
Output is correct |
11 |
Correct |
17 ms |
24064 KB |
Output is correct |
12 |
Correct |
18 ms |
24192 KB |
Output is correct |
13 |
Correct |
18 ms |
24192 KB |
Output is correct |
14 |
Correct |
20 ms |
24320 KB |
Output is correct |
15 |
Correct |
20 ms |
24192 KB |
Output is correct |
16 |
Correct |
19 ms |
24192 KB |
Output is correct |
17 |
Correct |
18 ms |
24192 KB |
Output is correct |
18 |
Correct |
18 ms |
24192 KB |
Output is correct |
19 |
Correct |
274 ms |
33528 KB |
Output is correct |
20 |
Correct |
305 ms |
33528 KB |
Output is correct |
21 |
Correct |
235 ms |
33144 KB |
Output is correct |
22 |
Correct |
252 ms |
33144 KB |
Output is correct |
23 |
Correct |
264 ms |
33144 KB |
Output is correct |
24 |
Correct |
200 ms |
30968 KB |
Output is correct |
25 |
Correct |
199 ms |
30968 KB |
Output is correct |
26 |
Correct |
206 ms |
31224 KB |
Output is correct |
27 |
Correct |
211 ms |
31224 KB |
Output is correct |
28 |
Correct |
219 ms |
31352 KB |
Output is correct |
29 |
Correct |
230 ms |
31480 KB |
Output is correct |
30 |
Correct |
227 ms |
31480 KB |
Output is correct |
31 |
Correct |
228 ms |
31480 KB |
Output is correct |
32 |
Correct |
229 ms |
31608 KB |
Output is correct |
33 |
Correct |
230 ms |
31480 KB |
Output is correct |
34 |
Correct |
186 ms |
30584 KB |
Output is correct |
35 |
Correct |
183 ms |
30584 KB |
Output is correct |
36 |
Correct |
184 ms |
30712 KB |
Output is correct |
37 |
Correct |
191 ms |
30584 KB |
Output is correct |
38 |
Correct |
185 ms |
30584 KB |
Output is correct |
39 |
Correct |
199 ms |
31920 KB |
Output is correct |
40 |
Correct |
163 ms |
30332 KB |
Output is correct |
41 |
Correct |
197 ms |
31272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
23808 KB |
Output is correct |
2 |
Correct |
14 ms |
23808 KB |
Output is correct |
3 |
Correct |
15 ms |
23808 KB |
Output is correct |
4 |
Correct |
15 ms |
23808 KB |
Output is correct |
5 |
Correct |
14 ms |
23808 KB |
Output is correct |
6 |
Correct |
15 ms |
23936 KB |
Output is correct |
7 |
Correct |
15 ms |
23808 KB |
Output is correct |
8 |
Correct |
14 ms |
23808 KB |
Output is correct |
9 |
Correct |
15 ms |
23808 KB |
Output is correct |
10 |
Correct |
15 ms |
23808 KB |
Output is correct |
11 |
Correct |
17 ms |
24064 KB |
Output is correct |
12 |
Correct |
18 ms |
24192 KB |
Output is correct |
13 |
Correct |
18 ms |
24192 KB |
Output is correct |
14 |
Correct |
20 ms |
24320 KB |
Output is correct |
15 |
Correct |
20 ms |
24192 KB |
Output is correct |
16 |
Correct |
19 ms |
24192 KB |
Output is correct |
17 |
Correct |
18 ms |
24192 KB |
Output is correct |
18 |
Correct |
18 ms |
24192 KB |
Output is correct |
19 |
Correct |
1498 ms |
63784 KB |
Output is correct |
20 |
Correct |
1555 ms |
63864 KB |
Output is correct |
21 |
Correct |
1490 ms |
63892 KB |
Output is correct |
22 |
Correct |
1493 ms |
63720 KB |
Output is correct |
23 |
Correct |
1291 ms |
59512 KB |
Output is correct |
24 |
Correct |
125 ms |
28460 KB |
Output is correct |
25 |
Correct |
117 ms |
28892 KB |
Output is correct |
26 |
Correct |
111 ms |
28044 KB |
Output is correct |
27 |
Correct |
113 ms |
28152 KB |
Output is correct |
28 |
Correct |
109 ms |
28084 KB |
Output is correct |
29 |
Correct |
86 ms |
27256 KB |
Output is correct |
30 |
Correct |
93 ms |
27384 KB |
Output is correct |
31 |
Correct |
97 ms |
28084 KB |
Output is correct |
32 |
Correct |
55 ms |
26672 KB |
Output is correct |
33 |
Correct |
91 ms |
27948 KB |
Output is correct |
34 |
Correct |
274 ms |
33528 KB |
Output is correct |
35 |
Correct |
305 ms |
33528 KB |
Output is correct |
36 |
Correct |
235 ms |
33144 KB |
Output is correct |
37 |
Correct |
252 ms |
33144 KB |
Output is correct |
38 |
Correct |
264 ms |
33144 KB |
Output is correct |
39 |
Correct |
200 ms |
30968 KB |
Output is correct |
40 |
Correct |
199 ms |
30968 KB |
Output is correct |
41 |
Correct |
206 ms |
31224 KB |
Output is correct |
42 |
Correct |
211 ms |
31224 KB |
Output is correct |
43 |
Correct |
219 ms |
31352 KB |
Output is correct |
44 |
Correct |
230 ms |
31480 KB |
Output is correct |
45 |
Correct |
227 ms |
31480 KB |
Output is correct |
46 |
Correct |
228 ms |
31480 KB |
Output is correct |
47 |
Correct |
229 ms |
31608 KB |
Output is correct |
48 |
Correct |
230 ms |
31480 KB |
Output is correct |
49 |
Correct |
186 ms |
30584 KB |
Output is correct |
50 |
Correct |
183 ms |
30584 KB |
Output is correct |
51 |
Correct |
184 ms |
30712 KB |
Output is correct |
52 |
Correct |
191 ms |
30584 KB |
Output is correct |
53 |
Correct |
185 ms |
30584 KB |
Output is correct |
54 |
Correct |
199 ms |
31920 KB |
Output is correct |
55 |
Correct |
163 ms |
30332 KB |
Output is correct |
56 |
Correct |
197 ms |
31272 KB |
Output is correct |
57 |
Correct |
1577 ms |
100788 KB |
Output is correct |
58 |
Correct |
1512 ms |
100984 KB |
Output is correct |
59 |
Correct |
1431 ms |
99228 KB |
Output is correct |
60 |
Correct |
1426 ms |
99320 KB |
Output is correct |
61 |
Correct |
1521 ms |
99304 KB |
Output is correct |
62 |
Correct |
1452 ms |
99180 KB |
Output is correct |
63 |
Correct |
1058 ms |
87160 KB |
Output is correct |
64 |
Correct |
955 ms |
87140 KB |
Output is correct |
65 |
Correct |
1235 ms |
90868 KB |
Output is correct |
66 |
Correct |
1237 ms |
90804 KB |
Output is correct |
67 |
Correct |
1254 ms |
90992 KB |
Output is correct |
68 |
Correct |
1388 ms |
92600 KB |
Output is correct |
69 |
Correct |
1302 ms |
92532 KB |
Output is correct |
70 |
Correct |
1288 ms |
92276 KB |
Output is correct |
71 |
Correct |
1317 ms |
92048 KB |
Output is correct |
72 |
Correct |
1336 ms |
92172 KB |
Output is correct |
73 |
Correct |
949 ms |
83440 KB |
Output is correct |
74 |
Correct |
945 ms |
84260 KB |
Output is correct |
75 |
Correct |
951 ms |
83216 KB |
Output is correct |
76 |
Correct |
922 ms |
83632 KB |
Output is correct |
77 |
Correct |
922 ms |
83352 KB |
Output is correct |
78 |
Correct |
1162 ms |
87212 KB |
Output is correct |
79 |
Correct |
854 ms |
73940 KB |
Output is correct |
80 |
Correct |
1103 ms |
81740 KB |
Output is correct |