#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define ll long long
#define ld long double
const int N=1e6+50;
const ll inf=1e17;
vector<array<ll,3>>Qs[N];
int res[N],a[N];
int root,nc,lc[2*N],rc[2*N];
ll maks[2*N],lazy[2*N];
void update(int &c,ll x){if(!c)c=++nc;maks[c]+=x;lazy[c]+=x;}
void push(int &c){update(lc[c],lazy[c]),update(rc[c],lazy[c]);lazy[c]=0;}
void Update(int &c,int ss,int se,int qs,int qe,ll x){
if(!c)c=++nc;
if(qs>qe||qe<ss||se<qs)return;
if(qs<=ss&&se<=qe){update(c,x);return;}
int mid=ss+se>>1;push(c);
Update(lc[c],ss,mid,qs,qe,x),Update(rc[c],mid+1,se,qs,qe,x);
maks[c]=max(maks[lc[c]],maks[rc[c]]);
}
ll Get(int &c,int ss,int se,int qs,int qe){
if(!c)c=++nc;
if(qs>qe||qe<ss||se<qs)return -inf;
if(qs<=ss&&se<=qe)return maks[c];
int mid=ss+se>>1;push(c);
return max(Get(lc[c],ss,mid,qs,qe),Get(rc[c],mid+1,se,qs,qe));
}
int main(){
int n,q;scanf("%i%i",&n,&q);
for(int i=1;i<=n;i++) scanf("%i",&a[i]);
for(ll i=1,l,r,k;i<=q;i++) scanf("%lld%lld%lld",&l,&r,&k),Qs[l].pb({r,k,i});
maks[0]=-inf;
for(int i=1;i<=n;i++) Update(root,1,n,i,i,a[i]);
vector<int>mono={n+1};
for(int i=n;i>=1;i--){
while(mono.size()>1&&a[mono.back()]<a[i]){
int prosli=mono.back();mono.pop_back();
Update(root,1,n,prosli,mono.back()-1,-a[prosli]);
Update(root,1,n,prosli,prosli,inf);
}
Update(root,1,n,i,mono.back()-1,a[i]);
Update(root,1,n,i,i,-inf);
mono.pb(i);
for(auto j:Qs[i]){
ll x=Get(root,1,n,i,j[0]);
//printf("%i %i: %i\n",i,j[0],x);
if(x<=j[1]) res[j[2]]=1;
}
}
for(int i=1;i<=q;i++) printf("%i\n",res[i]);
return 0;
}
Compilation message
sortbooks.cpp: In function 'void Update(int&, int, int, int, int, long long int)':
sortbooks.cpp:20:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
20 | int mid=ss+se>>1;push(c);
| ^
sortbooks.cpp: In function 'long long int Get(int&, int, int, int, int)':
sortbooks.cpp:28:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
28 | int mid=ss+se>>1;push(c);
| ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:32:18: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
32 | int n,q;scanf("%i%i",&n,&q);
| ~~~~~^~~~~~~~~~~~~~
sortbooks.cpp:33:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | for(int i=1;i<=n;i++) scanf("%i",&a[i]);
| ~~~~~^~~~~~~~~~~~
sortbooks.cpp:34:37: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
34 | for(ll i=1,l,r,k;i<=q;i++) scanf("%lld%lld%lld",&l,&r,&k),Qs[l].pb({r,k,i});
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23888 KB |
Output is correct |
2 |
Correct |
17 ms |
23732 KB |
Output is correct |
3 |
Correct |
16 ms |
23888 KB |
Output is correct |
4 |
Correct |
17 ms |
23888 KB |
Output is correct |
5 |
Correct |
17 ms |
23888 KB |
Output is correct |
6 |
Correct |
16 ms |
23888 KB |
Output is correct |
7 |
Correct |
17 ms |
23888 KB |
Output is correct |
8 |
Correct |
16 ms |
23888 KB |
Output is correct |
9 |
Correct |
16 ms |
23888 KB |
Output is correct |
10 |
Correct |
18 ms |
23936 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23888 KB |
Output is correct |
2 |
Correct |
17 ms |
23732 KB |
Output is correct |
3 |
Correct |
16 ms |
23888 KB |
Output is correct |
4 |
Correct |
17 ms |
23888 KB |
Output is correct |
5 |
Correct |
17 ms |
23888 KB |
Output is correct |
6 |
Correct |
16 ms |
23888 KB |
Output is correct |
7 |
Correct |
17 ms |
23888 KB |
Output is correct |
8 |
Correct |
16 ms |
23888 KB |
Output is correct |
9 |
Correct |
16 ms |
23888 KB |
Output is correct |
10 |
Correct |
18 ms |
23936 KB |
Output is correct |
11 |
Correct |
19 ms |
24144 KB |
Output is correct |
12 |
Correct |
23 ms |
24412 KB |
Output is correct |
13 |
Correct |
25 ms |
24200 KB |
Output is correct |
14 |
Correct |
25 ms |
24396 KB |
Output is correct |
15 |
Correct |
25 ms |
24400 KB |
Output is correct |
16 |
Correct |
26 ms |
24400 KB |
Output is correct |
17 |
Correct |
23 ms |
24392 KB |
Output is correct |
18 |
Correct |
23 ms |
24400 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2712 ms |
140892 KB |
Output is correct |
2 |
Correct |
2468 ms |
141936 KB |
Output is correct |
3 |
Correct |
2490 ms |
142024 KB |
Output is correct |
4 |
Correct |
2520 ms |
141964 KB |
Output is correct |
5 |
Correct |
2247 ms |
150052 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
204 ms |
34628 KB |
Output is correct |
2 |
Correct |
213 ms |
35144 KB |
Output is correct |
3 |
Correct |
162 ms |
35304 KB |
Output is correct |
4 |
Correct |
155 ms |
35312 KB |
Output is correct |
5 |
Correct |
155 ms |
35268 KB |
Output is correct |
6 |
Correct |
135 ms |
34764 KB |
Output is correct |
7 |
Correct |
133 ms |
34716 KB |
Output is correct |
8 |
Correct |
160 ms |
34552 KB |
Output is correct |
9 |
Correct |
48 ms |
28708 KB |
Output is correct |
10 |
Correct |
158 ms |
34556 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23888 KB |
Output is correct |
2 |
Correct |
17 ms |
23732 KB |
Output is correct |
3 |
Correct |
16 ms |
23888 KB |
Output is correct |
4 |
Correct |
17 ms |
23888 KB |
Output is correct |
5 |
Correct |
17 ms |
23888 KB |
Output is correct |
6 |
Correct |
16 ms |
23888 KB |
Output is correct |
7 |
Correct |
17 ms |
23888 KB |
Output is correct |
8 |
Correct |
16 ms |
23888 KB |
Output is correct |
9 |
Correct |
16 ms |
23888 KB |
Output is correct |
10 |
Correct |
18 ms |
23936 KB |
Output is correct |
11 |
Correct |
19 ms |
24144 KB |
Output is correct |
12 |
Correct |
23 ms |
24412 KB |
Output is correct |
13 |
Correct |
25 ms |
24200 KB |
Output is correct |
14 |
Correct |
25 ms |
24396 KB |
Output is correct |
15 |
Correct |
25 ms |
24400 KB |
Output is correct |
16 |
Correct |
26 ms |
24400 KB |
Output is correct |
17 |
Correct |
23 ms |
24392 KB |
Output is correct |
18 |
Correct |
23 ms |
24400 KB |
Output is correct |
19 |
Correct |
424 ms |
48236 KB |
Output is correct |
20 |
Correct |
439 ms |
48200 KB |
Output is correct |
21 |
Correct |
416 ms |
49224 KB |
Output is correct |
22 |
Correct |
409 ms |
49224 KB |
Output is correct |
23 |
Correct |
384 ms |
49412 KB |
Output is correct |
24 |
Correct |
323 ms |
50064 KB |
Output is correct |
25 |
Correct |
301 ms |
50108 KB |
Output is correct |
26 |
Correct |
332 ms |
49784 KB |
Output is correct |
27 |
Correct |
318 ms |
49864 KB |
Output is correct |
28 |
Correct |
315 ms |
49348 KB |
Output is correct |
29 |
Correct |
362 ms |
49092 KB |
Output is correct |
30 |
Correct |
369 ms |
49260 KB |
Output is correct |
31 |
Correct |
375 ms |
49092 KB |
Output is correct |
32 |
Correct |
372 ms |
49096 KB |
Output is correct |
33 |
Correct |
381 ms |
49096 KB |
Output is correct |
34 |
Correct |
292 ms |
49020 KB |
Output is correct |
35 |
Correct |
306 ms |
48852 KB |
Output is correct |
36 |
Correct |
298 ms |
48828 KB |
Output is correct |
37 |
Correct |
288 ms |
48840 KB |
Output is correct |
38 |
Correct |
275 ms |
49092 KB |
Output is correct |
39 |
Correct |
309 ms |
48124 KB |
Output is correct |
40 |
Correct |
220 ms |
42660 KB |
Output is correct |
41 |
Correct |
324 ms |
46580 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
23888 KB |
Output is correct |
2 |
Correct |
17 ms |
23732 KB |
Output is correct |
3 |
Correct |
16 ms |
23888 KB |
Output is correct |
4 |
Correct |
17 ms |
23888 KB |
Output is correct |
5 |
Correct |
17 ms |
23888 KB |
Output is correct |
6 |
Correct |
16 ms |
23888 KB |
Output is correct |
7 |
Correct |
17 ms |
23888 KB |
Output is correct |
8 |
Correct |
16 ms |
23888 KB |
Output is correct |
9 |
Correct |
16 ms |
23888 KB |
Output is correct |
10 |
Correct |
18 ms |
23936 KB |
Output is correct |
11 |
Correct |
19 ms |
24144 KB |
Output is correct |
12 |
Correct |
23 ms |
24412 KB |
Output is correct |
13 |
Correct |
25 ms |
24200 KB |
Output is correct |
14 |
Correct |
25 ms |
24396 KB |
Output is correct |
15 |
Correct |
25 ms |
24400 KB |
Output is correct |
16 |
Correct |
26 ms |
24400 KB |
Output is correct |
17 |
Correct |
23 ms |
24392 KB |
Output is correct |
18 |
Correct |
23 ms |
24400 KB |
Output is correct |
19 |
Correct |
2712 ms |
140892 KB |
Output is correct |
20 |
Correct |
2468 ms |
141936 KB |
Output is correct |
21 |
Correct |
2490 ms |
142024 KB |
Output is correct |
22 |
Correct |
2520 ms |
141964 KB |
Output is correct |
23 |
Correct |
2247 ms |
150052 KB |
Output is correct |
24 |
Correct |
204 ms |
34628 KB |
Output is correct |
25 |
Correct |
213 ms |
35144 KB |
Output is correct |
26 |
Correct |
162 ms |
35304 KB |
Output is correct |
27 |
Correct |
155 ms |
35312 KB |
Output is correct |
28 |
Correct |
155 ms |
35268 KB |
Output is correct |
29 |
Correct |
135 ms |
34764 KB |
Output is correct |
30 |
Correct |
133 ms |
34716 KB |
Output is correct |
31 |
Correct |
160 ms |
34552 KB |
Output is correct |
32 |
Correct |
48 ms |
28708 KB |
Output is correct |
33 |
Correct |
158 ms |
34556 KB |
Output is correct |
34 |
Correct |
424 ms |
48236 KB |
Output is correct |
35 |
Correct |
439 ms |
48200 KB |
Output is correct |
36 |
Correct |
416 ms |
49224 KB |
Output is correct |
37 |
Correct |
409 ms |
49224 KB |
Output is correct |
38 |
Correct |
384 ms |
49412 KB |
Output is correct |
39 |
Correct |
323 ms |
50064 KB |
Output is correct |
40 |
Correct |
301 ms |
50108 KB |
Output is correct |
41 |
Correct |
332 ms |
49784 KB |
Output is correct |
42 |
Correct |
318 ms |
49864 KB |
Output is correct |
43 |
Correct |
315 ms |
49348 KB |
Output is correct |
44 |
Correct |
362 ms |
49092 KB |
Output is correct |
45 |
Correct |
369 ms |
49260 KB |
Output is correct |
46 |
Correct |
375 ms |
49092 KB |
Output is correct |
47 |
Correct |
372 ms |
49096 KB |
Output is correct |
48 |
Correct |
381 ms |
49096 KB |
Output is correct |
49 |
Correct |
292 ms |
49020 KB |
Output is correct |
50 |
Correct |
306 ms |
48852 KB |
Output is correct |
51 |
Correct |
298 ms |
48828 KB |
Output is correct |
52 |
Correct |
288 ms |
48840 KB |
Output is correct |
53 |
Correct |
275 ms |
49092 KB |
Output is correct |
54 |
Correct |
309 ms |
48124 KB |
Output is correct |
55 |
Correct |
220 ms |
42660 KB |
Output is correct |
56 |
Correct |
324 ms |
46580 KB |
Output is correct |
57 |
Correct |
2454 ms |
146216 KB |
Output is correct |
58 |
Correct |
2516 ms |
146248 KB |
Output is correct |
59 |
Correct |
2467 ms |
147872 KB |
Output is correct |
60 |
Correct |
2310 ms |
147592 KB |
Output is correct |
61 |
Correct |
2466 ms |
147040 KB |
Output is correct |
62 |
Correct |
2422 ms |
147868 KB |
Output is correct |
63 |
Correct |
1581 ms |
149340 KB |
Output is correct |
64 |
Correct |
1461 ms |
149200 KB |
Output is correct |
65 |
Correct |
1859 ms |
152504 KB |
Output is correct |
66 |
Correct |
2062 ms |
152496 KB |
Output is correct |
67 |
Correct |
2185 ms |
152232 KB |
Output is correct |
68 |
Correct |
2094 ms |
150444 KB |
Output is correct |
69 |
Correct |
2073 ms |
150412 KB |
Output is correct |
70 |
Correct |
1964 ms |
150452 KB |
Output is correct |
71 |
Correct |
2194 ms |
150436 KB |
Output is correct |
72 |
Correct |
2081 ms |
150440 KB |
Output is correct |
73 |
Correct |
1433 ms |
145580 KB |
Output is correct |
74 |
Correct |
1398 ms |
146288 KB |
Output is correct |
75 |
Correct |
1502 ms |
145388 KB |
Output is correct |
76 |
Correct |
1468 ms |
145596 KB |
Output is correct |
77 |
Correct |
1517 ms |
145376 KB |
Output is correct |
78 |
Correct |
1867 ms |
145424 KB |
Output is correct |
79 |
Correct |
1136 ms |
110516 KB |
Output is correct |
80 |
Correct |
1964 ms |
138624 KB |
Output is correct |