#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair< lo,lo > PII;
#define fi first
#define se second
#define int long long
#define mp make_pair
#define endl "\n"
#define pb push_back
#define fio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define FOR for(int i=0;i<n;i++)
#define mid ((start+end)/2)
#define ort ((bas+son)/2)
const lo inf = 3000000000;
const lo KOK = 100000;
const lo LOG = 30;
const lo li = 1000005;
const lo mod = 1000000007;
int n,m,b[li],a[li],k,flag,t,maxi[li],mx,dp[li],mini[li],tree[li*4],anss[li];
int cev;
pair<int,pair<int,pair<int,int>>> p[li];
string s;
vector<int> v[1005];
inline void update(int node,int start,int end,int l,int r,int val){
if(start>end || start>r || end<l)return ;
if(start>=l && end<=r){tree[node]=max(tree[node],val);return ;}
update(node*2,start,mid,l,r,val),update(node*2+1,mid+1,end,l,r,val);
tree[node]=max(tree[node*2],tree[node*2+1]);
}
inline int query(int node,int start,int end,int l,int r){
if(start>end || start>r || end<l)return 0;
if(start>=l && end<=r)return tree[node];
return max(query(node*2,start,mid,l,r),query(node*2+1,mid+1,end,l,r));
}
int32_t main(void){
scanf("%lld %lld",&n,&t);
for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
for(int i=1;i<=t;i++){
scanf("%lld %lld %lld",&p[i].fi,&p[i].se.fi,&p[i].se.se.fi);
p[i].se.se.se=i;
}
sort(p+1,p+t+1);
//~ reverse(p+1,p+t+1);
stack<pair<int,int>> st;
int ind=t;
for(int i=n;i>=1;i--){
int son=i;
while(st.size() && a[i]>st.top().fi){
update(1,1,n,son+1,son+1,a[i]+st.top().fi);
//~ cout<<a[i]+st.top().fi<<endl;
son=st.top().se;
st.pop();
}
if(st.size()==0)son=n;
st.push({a[i],son});
while(ind>0 && p[ind].fi==i){
//~ cout<<p[ind].fi<<endl;
//~ cout<<query(1,1,n,i,p[ind].se.fi)<<"*****"<<endl;
if(query(1,1,n,i,p[ind].se.fi)<=p[ind].se.se.fi)anss[p[ind].se.se.se]=1;
ind--;
}
//~ cout<<ind<<" &&&& "<<endl;
}
for(int i=1;i<=t;i++)printf("%lld\n",anss[i]);
return 0;
}
Compilation message
sortbooks.cpp: In function 'int32_t main()':
sortbooks.cpp:48:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
48 | scanf("%lld %lld",&n,&t);
| ~~~~~^~~~~~~~~~~~~~~~~~~
sortbooks.cpp:49:28: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
49 | for(int i=1;i<=n;i++)scanf("%lld",&a[i]);
| ~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
51 | scanf("%lld %lld %lld",&p[i].fi,&p[i].se.fi,&p[i].se.se.fi);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
376 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
376 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
492 KB |
Output is correct |
12 |
Correct |
5 ms |
620 KB |
Output is correct |
13 |
Correct |
5 ms |
620 KB |
Output is correct |
14 |
Correct |
7 ms |
748 KB |
Output is correct |
15 |
Correct |
7 ms |
748 KB |
Output is correct |
16 |
Correct |
5 ms |
748 KB |
Output is correct |
17 |
Correct |
5 ms |
748 KB |
Output is correct |
18 |
Correct |
5 ms |
748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1589 ms |
58300 KB |
Output is correct |
2 |
Correct |
1602 ms |
58036 KB |
Output is correct |
3 |
Correct |
1584 ms |
58116 KB |
Output is correct |
4 |
Correct |
1595 ms |
58256 KB |
Output is correct |
5 |
Correct |
1322 ms |
65964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
132 ms |
7500 KB |
Output is correct |
2 |
Correct |
125 ms |
7276 KB |
Output is correct |
3 |
Correct |
108 ms |
6968 KB |
Output is correct |
4 |
Correct |
105 ms |
6892 KB |
Output is correct |
5 |
Correct |
106 ms |
6892 KB |
Output is correct |
6 |
Correct |
97 ms |
6252 KB |
Output is correct |
7 |
Correct |
108 ms |
6252 KB |
Output is correct |
8 |
Correct |
122 ms |
7404 KB |
Output is correct |
9 |
Correct |
55 ms |
4460 KB |
Output is correct |
10 |
Correct |
110 ms |
7276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
376 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
492 KB |
Output is correct |
12 |
Correct |
5 ms |
620 KB |
Output is correct |
13 |
Correct |
5 ms |
620 KB |
Output is correct |
14 |
Correct |
7 ms |
748 KB |
Output is correct |
15 |
Correct |
7 ms |
748 KB |
Output is correct |
16 |
Correct |
5 ms |
748 KB |
Output is correct |
17 |
Correct |
5 ms |
748 KB |
Output is correct |
18 |
Correct |
5 ms |
748 KB |
Output is correct |
19 |
Correct |
292 ms |
14336 KB |
Output is correct |
20 |
Correct |
300 ms |
14260 KB |
Output is correct |
21 |
Correct |
272 ms |
14316 KB |
Output is correct |
22 |
Correct |
271 ms |
14316 KB |
Output is correct |
23 |
Correct |
275 ms |
14316 KB |
Output is correct |
24 |
Correct |
222 ms |
13420 KB |
Output is correct |
25 |
Correct |
222 ms |
13420 KB |
Output is correct |
26 |
Correct |
231 ms |
13420 KB |
Output is correct |
27 |
Correct |
230 ms |
13548 KB |
Output is correct |
28 |
Correct |
239 ms |
13420 KB |
Output is correct |
29 |
Correct |
238 ms |
13676 KB |
Output is correct |
30 |
Correct |
238 ms |
13420 KB |
Output is correct |
31 |
Correct |
238 ms |
13696 KB |
Output is correct |
32 |
Correct |
240 ms |
13548 KB |
Output is correct |
33 |
Correct |
238 ms |
13420 KB |
Output is correct |
34 |
Correct |
218 ms |
13548 KB |
Output is correct |
35 |
Correct |
231 ms |
13548 KB |
Output is correct |
36 |
Correct |
217 ms |
13540 KB |
Output is correct |
37 |
Correct |
218 ms |
13676 KB |
Output is correct |
38 |
Correct |
222 ms |
13676 KB |
Output is correct |
39 |
Correct |
231 ms |
13932 KB |
Output is correct |
40 |
Correct |
182 ms |
11756 KB |
Output is correct |
41 |
Correct |
237 ms |
14120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
376 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
492 KB |
Output is correct |
12 |
Correct |
5 ms |
620 KB |
Output is correct |
13 |
Correct |
5 ms |
620 KB |
Output is correct |
14 |
Correct |
7 ms |
748 KB |
Output is correct |
15 |
Correct |
7 ms |
748 KB |
Output is correct |
16 |
Correct |
5 ms |
748 KB |
Output is correct |
17 |
Correct |
5 ms |
748 KB |
Output is correct |
18 |
Correct |
5 ms |
748 KB |
Output is correct |
19 |
Correct |
1589 ms |
58300 KB |
Output is correct |
20 |
Correct |
1602 ms |
58036 KB |
Output is correct |
21 |
Correct |
1584 ms |
58116 KB |
Output is correct |
22 |
Correct |
1595 ms |
58256 KB |
Output is correct |
23 |
Correct |
1322 ms |
65964 KB |
Output is correct |
24 |
Correct |
132 ms |
7500 KB |
Output is correct |
25 |
Correct |
125 ms |
7276 KB |
Output is correct |
26 |
Correct |
108 ms |
6968 KB |
Output is correct |
27 |
Correct |
105 ms |
6892 KB |
Output is correct |
28 |
Correct |
106 ms |
6892 KB |
Output is correct |
29 |
Correct |
97 ms |
6252 KB |
Output is correct |
30 |
Correct |
108 ms |
6252 KB |
Output is correct |
31 |
Correct |
122 ms |
7404 KB |
Output is correct |
32 |
Correct |
55 ms |
4460 KB |
Output is correct |
33 |
Correct |
110 ms |
7276 KB |
Output is correct |
34 |
Correct |
292 ms |
14336 KB |
Output is correct |
35 |
Correct |
300 ms |
14260 KB |
Output is correct |
36 |
Correct |
272 ms |
14316 KB |
Output is correct |
37 |
Correct |
271 ms |
14316 KB |
Output is correct |
38 |
Correct |
275 ms |
14316 KB |
Output is correct |
39 |
Correct |
222 ms |
13420 KB |
Output is correct |
40 |
Correct |
222 ms |
13420 KB |
Output is correct |
41 |
Correct |
231 ms |
13420 KB |
Output is correct |
42 |
Correct |
230 ms |
13548 KB |
Output is correct |
43 |
Correct |
239 ms |
13420 KB |
Output is correct |
44 |
Correct |
238 ms |
13676 KB |
Output is correct |
45 |
Correct |
238 ms |
13420 KB |
Output is correct |
46 |
Correct |
238 ms |
13696 KB |
Output is correct |
47 |
Correct |
240 ms |
13548 KB |
Output is correct |
48 |
Correct |
238 ms |
13420 KB |
Output is correct |
49 |
Correct |
218 ms |
13548 KB |
Output is correct |
50 |
Correct |
231 ms |
13548 KB |
Output is correct |
51 |
Correct |
217 ms |
13540 KB |
Output is correct |
52 |
Correct |
218 ms |
13676 KB |
Output is correct |
53 |
Correct |
222 ms |
13676 KB |
Output is correct |
54 |
Correct |
231 ms |
13932 KB |
Output is correct |
55 |
Correct |
182 ms |
11756 KB |
Output is correct |
56 |
Correct |
237 ms |
14120 KB |
Output is correct |
57 |
Correct |
1623 ms |
66000 KB |
Output is correct |
58 |
Correct |
1604 ms |
65756 KB |
Output is correct |
59 |
Correct |
1569 ms |
65812 KB |
Output is correct |
60 |
Correct |
1576 ms |
65772 KB |
Output is correct |
61 |
Correct |
1573 ms |
65900 KB |
Output is correct |
62 |
Correct |
1568 ms |
65724 KB |
Output is correct |
63 |
Correct |
1211 ms |
65964 KB |
Output is correct |
64 |
Correct |
1206 ms |
65844 KB |
Output is correct |
65 |
Correct |
1296 ms |
65908 KB |
Output is correct |
66 |
Correct |
1298 ms |
66092 KB |
Output is correct |
67 |
Correct |
1345 ms |
65932 KB |
Output is correct |
68 |
Correct |
1379 ms |
65732 KB |
Output is correct |
69 |
Correct |
1335 ms |
65824 KB |
Output is correct |
70 |
Correct |
1344 ms |
65924 KB |
Output is correct |
71 |
Correct |
1336 ms |
65828 KB |
Output is correct |
72 |
Correct |
1346 ms |
66008 KB |
Output is correct |
73 |
Correct |
1188 ms |
65952 KB |
Output is correct |
74 |
Correct |
1193 ms |
65952 KB |
Output is correct |
75 |
Correct |
1186 ms |
66004 KB |
Output is correct |
76 |
Correct |
1191 ms |
66028 KB |
Output is correct |
77 |
Correct |
1159 ms |
65904 KB |
Output is correct |
78 |
Correct |
1257 ms |
65916 KB |
Output is correct |
79 |
Correct |
936 ms |
54124 KB |
Output is correct |
80 |
Correct |
1335 ms |
69372 KB |
Output is correct |