#include <bits/stdc++.h>
#define MAXN 1000007
using namespace std;
int seg[4*MAXN],a[MAXN],ans[MAXN];
vector<int> ul[MAXN],uk[MAXN],ind[MAXN];
void upd(int l,int r,int x,int v,int ind)
{
if(l==r) {seg[ind]=v; return;}
int s=(l+r)/2;
if(x<=s) upd(l,s,x,v,2*ind);
else upd(s+1,r,x,v,2*ind+1);
seg[ind]=max(seg[2*ind],seg[2*ind+1]);
}
int nmax(int l,int r,int lt,int rt,int ind)
{
if(l>=lt && r<=rt) return seg[ind];
if(l>rt || r<lt) return 0;
int s=(l+r)/2;
return max(nmax(l,s,lt,rt,2*ind),nmax(s+1,r,lt,rt,2*ind+1));
}
int main()
{
int n,m;
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++) scanf("%d",&a[i]);
a[0]=1000000007;
for(int i=0;i<m;i++)
{
int t1,t2,t3;
scanf("%d%d%d",&t1,&t2,&t3);
ul[t2].push_back(t1); uk[t2].push_back(t3); ind[t2].push_back(i);
}
stack<int> st; st.push(0);
for(int i=1;i<=n;i++)
{
while(a[st.top()]<=a[i]) st.pop();
upd(0,n,st.top(),a[i]+a[st.top()],1);
st.push(i);
for(int j=0;j<ul[i].size();j++) ans[ind[i][j]]=(nmax(0,n,ul[i][j],i,1)>uk[i][j]?0:1);
}
for(int i=0;i<m;i++) printf("%d\n",ans[i]);
}
Compilation message
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:39:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for(int j=0;j<ul[i].size();j++) ans[ind[i][j]]=(nmax(0,n,ul[i][j],i,1)>uk[i][j]?0:1);
| ~^~~~~~~~~~~~~
sortbooks.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | scanf("%d%d",&n,&m);
| ~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:25:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | for(int i=1;i<=n;i++) scanf("%d",&a[i]);
| ~~~~~^~~~~~~~~~~~
sortbooks.cpp:30:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
30 | scanf("%d%d%d",&t1,&t2,&t3);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
70732 KB |
Output is correct |
2 |
Correct |
36 ms |
70748 KB |
Output is correct |
3 |
Correct |
39 ms |
70700 KB |
Output is correct |
4 |
Correct |
43 ms |
70736 KB |
Output is correct |
5 |
Correct |
37 ms |
70688 KB |
Output is correct |
6 |
Correct |
39 ms |
70772 KB |
Output is correct |
7 |
Correct |
40 ms |
70768 KB |
Output is correct |
8 |
Correct |
37 ms |
70800 KB |
Output is correct |
9 |
Correct |
38 ms |
70724 KB |
Output is correct |
10 |
Correct |
37 ms |
70724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
70732 KB |
Output is correct |
2 |
Correct |
36 ms |
70748 KB |
Output is correct |
3 |
Correct |
39 ms |
70700 KB |
Output is correct |
4 |
Correct |
43 ms |
70736 KB |
Output is correct |
5 |
Correct |
37 ms |
70688 KB |
Output is correct |
6 |
Correct |
39 ms |
70772 KB |
Output is correct |
7 |
Correct |
40 ms |
70768 KB |
Output is correct |
8 |
Correct |
37 ms |
70800 KB |
Output is correct |
9 |
Correct |
38 ms |
70724 KB |
Output is correct |
10 |
Correct |
37 ms |
70724 KB |
Output is correct |
11 |
Correct |
46 ms |
70876 KB |
Output is correct |
12 |
Correct |
40 ms |
71024 KB |
Output is correct |
13 |
Correct |
40 ms |
71140 KB |
Output is correct |
14 |
Correct |
45 ms |
71260 KB |
Output is correct |
15 |
Correct |
48 ms |
71192 KB |
Output is correct |
16 |
Correct |
45 ms |
71172 KB |
Output is correct |
17 |
Correct |
54 ms |
71024 KB |
Output is correct |
18 |
Correct |
46 ms |
71132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2171 ms |
143344 KB |
Output is correct |
2 |
Correct |
2156 ms |
144348 KB |
Output is correct |
3 |
Correct |
2208 ms |
144324 KB |
Output is correct |
4 |
Correct |
2201 ms |
144284 KB |
Output is correct |
5 |
Correct |
1917 ms |
136292 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
194 ms |
78328 KB |
Output is correct |
2 |
Correct |
190 ms |
77252 KB |
Output is correct |
3 |
Correct |
164 ms |
77824 KB |
Output is correct |
4 |
Correct |
178 ms |
78324 KB |
Output is correct |
5 |
Correct |
195 ms |
78740 KB |
Output is correct |
6 |
Correct |
126 ms |
75312 KB |
Output is correct |
7 |
Correct |
125 ms |
75268 KB |
Output is correct |
8 |
Correct |
144 ms |
77964 KB |
Output is correct |
9 |
Correct |
83 ms |
74056 KB |
Output is correct |
10 |
Correct |
161 ms |
77952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
70732 KB |
Output is correct |
2 |
Correct |
36 ms |
70748 KB |
Output is correct |
3 |
Correct |
39 ms |
70700 KB |
Output is correct |
4 |
Correct |
43 ms |
70736 KB |
Output is correct |
5 |
Correct |
37 ms |
70688 KB |
Output is correct |
6 |
Correct |
39 ms |
70772 KB |
Output is correct |
7 |
Correct |
40 ms |
70768 KB |
Output is correct |
8 |
Correct |
37 ms |
70800 KB |
Output is correct |
9 |
Correct |
38 ms |
70724 KB |
Output is correct |
10 |
Correct |
37 ms |
70724 KB |
Output is correct |
11 |
Correct |
46 ms |
70876 KB |
Output is correct |
12 |
Correct |
40 ms |
71024 KB |
Output is correct |
13 |
Correct |
40 ms |
71140 KB |
Output is correct |
14 |
Correct |
45 ms |
71260 KB |
Output is correct |
15 |
Correct |
48 ms |
71192 KB |
Output is correct |
16 |
Correct |
45 ms |
71172 KB |
Output is correct |
17 |
Correct |
54 ms |
71024 KB |
Output is correct |
18 |
Correct |
46 ms |
71132 KB |
Output is correct |
19 |
Correct |
417 ms |
85372 KB |
Output is correct |
20 |
Correct |
398 ms |
91020 KB |
Output is correct |
21 |
Correct |
255 ms |
85608 KB |
Output is correct |
22 |
Correct |
327 ms |
85592 KB |
Output is correct |
23 |
Correct |
265 ms |
85780 KB |
Output is correct |
24 |
Correct |
252 ms |
83012 KB |
Output is correct |
25 |
Correct |
223 ms |
83100 KB |
Output is correct |
26 |
Correct |
368 ms |
85528 KB |
Output is correct |
27 |
Correct |
285 ms |
85392 KB |
Output is correct |
28 |
Correct |
329 ms |
86396 KB |
Output is correct |
29 |
Correct |
405 ms |
89028 KB |
Output is correct |
30 |
Correct |
360 ms |
89088 KB |
Output is correct |
31 |
Correct |
399 ms |
88900 KB |
Output is correct |
32 |
Correct |
362 ms |
88828 KB |
Output is correct |
33 |
Correct |
363 ms |
88832 KB |
Output is correct |
34 |
Correct |
220 ms |
82420 KB |
Output is correct |
35 |
Correct |
216 ms |
82240 KB |
Output is correct |
36 |
Correct |
284 ms |
82124 KB |
Output is correct |
37 |
Correct |
208 ms |
82132 KB |
Output is correct |
38 |
Correct |
225 ms |
82432 KB |
Output is correct |
39 |
Correct |
300 ms |
87164 KB |
Output is correct |
40 |
Correct |
318 ms |
84656 KB |
Output is correct |
41 |
Correct |
294 ms |
86484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
36 ms |
70732 KB |
Output is correct |
2 |
Correct |
36 ms |
70748 KB |
Output is correct |
3 |
Correct |
39 ms |
70700 KB |
Output is correct |
4 |
Correct |
43 ms |
70736 KB |
Output is correct |
5 |
Correct |
37 ms |
70688 KB |
Output is correct |
6 |
Correct |
39 ms |
70772 KB |
Output is correct |
7 |
Correct |
40 ms |
70768 KB |
Output is correct |
8 |
Correct |
37 ms |
70800 KB |
Output is correct |
9 |
Correct |
38 ms |
70724 KB |
Output is correct |
10 |
Correct |
37 ms |
70724 KB |
Output is correct |
11 |
Correct |
46 ms |
70876 KB |
Output is correct |
12 |
Correct |
40 ms |
71024 KB |
Output is correct |
13 |
Correct |
40 ms |
71140 KB |
Output is correct |
14 |
Correct |
45 ms |
71260 KB |
Output is correct |
15 |
Correct |
48 ms |
71192 KB |
Output is correct |
16 |
Correct |
45 ms |
71172 KB |
Output is correct |
17 |
Correct |
54 ms |
71024 KB |
Output is correct |
18 |
Correct |
46 ms |
71132 KB |
Output is correct |
19 |
Correct |
2171 ms |
143344 KB |
Output is correct |
20 |
Correct |
2156 ms |
144348 KB |
Output is correct |
21 |
Correct |
2208 ms |
144324 KB |
Output is correct |
22 |
Correct |
2201 ms |
144284 KB |
Output is correct |
23 |
Correct |
1917 ms |
136292 KB |
Output is correct |
24 |
Correct |
194 ms |
78328 KB |
Output is correct |
25 |
Correct |
190 ms |
77252 KB |
Output is correct |
26 |
Correct |
164 ms |
77824 KB |
Output is correct |
27 |
Correct |
178 ms |
78324 KB |
Output is correct |
28 |
Correct |
195 ms |
78740 KB |
Output is correct |
29 |
Correct |
126 ms |
75312 KB |
Output is correct |
30 |
Correct |
125 ms |
75268 KB |
Output is correct |
31 |
Correct |
144 ms |
77964 KB |
Output is correct |
32 |
Correct |
83 ms |
74056 KB |
Output is correct |
33 |
Correct |
161 ms |
77952 KB |
Output is correct |
34 |
Correct |
417 ms |
85372 KB |
Output is correct |
35 |
Correct |
398 ms |
91020 KB |
Output is correct |
36 |
Correct |
255 ms |
85608 KB |
Output is correct |
37 |
Correct |
327 ms |
85592 KB |
Output is correct |
38 |
Correct |
265 ms |
85780 KB |
Output is correct |
39 |
Correct |
252 ms |
83012 KB |
Output is correct |
40 |
Correct |
223 ms |
83100 KB |
Output is correct |
41 |
Correct |
368 ms |
85528 KB |
Output is correct |
42 |
Correct |
285 ms |
85392 KB |
Output is correct |
43 |
Correct |
329 ms |
86396 KB |
Output is correct |
44 |
Correct |
405 ms |
89028 KB |
Output is correct |
45 |
Correct |
360 ms |
89088 KB |
Output is correct |
46 |
Correct |
399 ms |
88900 KB |
Output is correct |
47 |
Correct |
362 ms |
88828 KB |
Output is correct |
48 |
Correct |
363 ms |
88832 KB |
Output is correct |
49 |
Correct |
220 ms |
82420 KB |
Output is correct |
50 |
Correct |
216 ms |
82240 KB |
Output is correct |
51 |
Correct |
284 ms |
82124 KB |
Output is correct |
52 |
Correct |
208 ms |
82132 KB |
Output is correct |
53 |
Correct |
225 ms |
82432 KB |
Output is correct |
54 |
Correct |
300 ms |
87164 KB |
Output is correct |
55 |
Correct |
318 ms |
84656 KB |
Output is correct |
56 |
Correct |
294 ms |
86484 KB |
Output is correct |
57 |
Correct |
2078 ms |
147376 KB |
Output is correct |
58 |
Correct |
2045 ms |
147212 KB |
Output is correct |
59 |
Correct |
1956 ms |
134876 KB |
Output is correct |
60 |
Correct |
1908 ms |
134788 KB |
Output is correct |
61 |
Correct |
1816 ms |
134808 KB |
Output is correct |
62 |
Correct |
1726 ms |
134832 KB |
Output is correct |
63 |
Correct |
1030 ms |
108280 KB |
Output is correct |
64 |
Correct |
1052 ms |
108068 KB |
Output is correct |
65 |
Correct |
1718 ms |
124980 KB |
Output is correct |
66 |
Correct |
1653 ms |
125128 KB |
Output is correct |
67 |
Correct |
1663 ms |
125980 KB |
Output is correct |
68 |
Correct |
1873 ms |
138944 KB |
Output is correct |
69 |
Correct |
1811 ms |
138504 KB |
Output is correct |
70 |
Correct |
1736 ms |
135776 KB |
Output is correct |
71 |
Correct |
1777 ms |
134724 KB |
Output is correct |
72 |
Correct |
1830 ms |
134180 KB |
Output is correct |
73 |
Correct |
945 ms |
103428 KB |
Output is correct |
74 |
Correct |
951 ms |
102708 KB |
Output is correct |
75 |
Correct |
940 ms |
102056 KB |
Output is correct |
76 |
Correct |
949 ms |
101700 KB |
Output is correct |
77 |
Correct |
923 ms |
100440 KB |
Output is correct |
78 |
Correct |
1565 ms |
129208 KB |
Output is correct |
79 |
Correct |
1134 ms |
117268 KB |
Output is correct |
80 |
Correct |
1461 ms |
127252 KB |
Output is correct |