#include<bits/stdc++.h>
using namespace std ;
#define maxn 1000009
#define ll long long
#define pb push_back
#define fi first
#define se second
#define left id<<1
#define right id<<1|1
#define re exit(0);
#define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1
const int mod = 1e9+7 ;
const int INF = 1e9 ;
typedef vector<int> vi ;
typedef pair<int,int> pii ;
typedef vector<pii> vii ;
template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ; }
template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ; }
void add ( int &a , int b )
{
a += b ;
if ( a >= mod ) a -= mod ;
if ( a < 0 ) a += mod ;
}
void rf ()
{
freopen ("bai1.inp","r",stdin) ;
}
int _pow ( int a , int n )
{
if ( n == 0 ) return 1 ;
int res = _pow (a,n/2) ;
if ( n % 2 ) return 1ll*res*res%mod*a%mod ;
else return 1ll*res*res%mod ;
}
int n , q ;
int a [maxn] ;
int answer [maxn] ;
struct shape {
int pos,id,k ;
};
vector<shape> event [maxn] ;
int T [maxn*4] ;
void update ( int id , int l , int r , int pos , int w )
{
if ( l > pos || r < pos ) return ;
if ( l == r )
{
T [id] = w ;
return ;
}
int mid = (l+r)/2 ;
update (left,l,mid,pos,w) ; update (right,mid+1,r,pos,w) ;
T [id] = max (T[left],T[right]) ;
}
int get ( int id , int l , int r , int u , int v )
{
if ( l > v || r < u ) return 0 ;
if ( u <= l && r <= v ) return T [id] ;
int mid = (l+r)/2 ;
return max (get(left,l,mid,u,v),get(right,mid+1,r,u,v)) ;
}
int main ()
{
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
// rf () ;
cin >> n >> q ;
for ( int i = 1 ; i <= n ; i ++ ) cin >> a [i] ;
for ( int i = 1 ; i <= q ; i ++ )
{
int l , r , k ; cin >> l >> r >> k ;
event [r] . pb ({l,i,k}) ;
}
stack<int> S ;
for ( int i = 1 ; i <= n ; i ++ )
{
while ( !S.empty() && a[S.top()] <= a[i]) S.pop() ;
if (S.size()) update (1,1,n,S.top(),a[S.top()]+a[i]) ;
S.push(i) ;
for ( auto x : event [i] )
{
int pos = x.pos , id = x.id , k = x.k ;
if ( get (1,1,n,pos,i) <= k ) answer [id] = 1 ;
else answer [id] = 0 ;
}
}
for ( int i = 1 ; i <= q ; i ++ ) cout << answer [i] << "\n" ;
}
Compilation message
sortbooks.cpp: In function 'void rf()':
sortbooks.cpp:31:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | freopen ("bai1.inp","r",stdin) ;
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
26972 KB |
Output is correct |
2 |
Correct |
3 ms |
26972 KB |
Output is correct |
3 |
Correct |
4 ms |
27084 KB |
Output is correct |
4 |
Correct |
4 ms |
26972 KB |
Output is correct |
5 |
Correct |
4 ms |
26976 KB |
Output is correct |
6 |
Correct |
4 ms |
26972 KB |
Output is correct |
7 |
Correct |
4 ms |
26972 KB |
Output is correct |
8 |
Correct |
4 ms |
26972 KB |
Output is correct |
9 |
Correct |
4 ms |
27088 KB |
Output is correct |
10 |
Correct |
4 ms |
26968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
26972 KB |
Output is correct |
2 |
Correct |
3 ms |
26972 KB |
Output is correct |
3 |
Correct |
4 ms |
27084 KB |
Output is correct |
4 |
Correct |
4 ms |
26972 KB |
Output is correct |
5 |
Correct |
4 ms |
26976 KB |
Output is correct |
6 |
Correct |
4 ms |
26972 KB |
Output is correct |
7 |
Correct |
4 ms |
26972 KB |
Output is correct |
8 |
Correct |
4 ms |
26972 KB |
Output is correct |
9 |
Correct |
4 ms |
27088 KB |
Output is correct |
10 |
Correct |
4 ms |
26968 KB |
Output is correct |
11 |
Correct |
6 ms |
27228 KB |
Output is correct |
12 |
Correct |
5 ms |
27228 KB |
Output is correct |
13 |
Correct |
6 ms |
27228 KB |
Output is correct |
14 |
Correct |
7 ms |
27228 KB |
Output is correct |
15 |
Correct |
7 ms |
27336 KB |
Output is correct |
16 |
Correct |
5 ms |
27156 KB |
Output is correct |
17 |
Correct |
5 ms |
27228 KB |
Output is correct |
18 |
Correct |
7 ms |
27228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
794 ms |
96492 KB |
Output is correct |
2 |
Correct |
793 ms |
97620 KB |
Output is correct |
3 |
Correct |
775 ms |
97360 KB |
Output is correct |
4 |
Correct |
801 ms |
97616 KB |
Output is correct |
5 |
Correct |
641 ms |
89332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
59 ms |
37516 KB |
Output is correct |
2 |
Correct |
54 ms |
37456 KB |
Output is correct |
3 |
Correct |
46 ms |
35412 KB |
Output is correct |
4 |
Correct |
50 ms |
35408 KB |
Output is correct |
5 |
Correct |
52 ms |
35412 KB |
Output is correct |
6 |
Correct |
40 ms |
36944 KB |
Output is correct |
7 |
Correct |
40 ms |
36944 KB |
Output is correct |
8 |
Correct |
50 ms |
35080 KB |
Output is correct |
9 |
Correct |
24 ms |
32020 KB |
Output is correct |
10 |
Correct |
45 ms |
35080 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
26972 KB |
Output is correct |
2 |
Correct |
3 ms |
26972 KB |
Output is correct |
3 |
Correct |
4 ms |
27084 KB |
Output is correct |
4 |
Correct |
4 ms |
26972 KB |
Output is correct |
5 |
Correct |
4 ms |
26976 KB |
Output is correct |
6 |
Correct |
4 ms |
26972 KB |
Output is correct |
7 |
Correct |
4 ms |
26972 KB |
Output is correct |
8 |
Correct |
4 ms |
26972 KB |
Output is correct |
9 |
Correct |
4 ms |
27088 KB |
Output is correct |
10 |
Correct |
4 ms |
26968 KB |
Output is correct |
11 |
Correct |
6 ms |
27228 KB |
Output is correct |
12 |
Correct |
5 ms |
27228 KB |
Output is correct |
13 |
Correct |
6 ms |
27228 KB |
Output is correct |
14 |
Correct |
7 ms |
27228 KB |
Output is correct |
15 |
Correct |
7 ms |
27336 KB |
Output is correct |
16 |
Correct |
5 ms |
27156 KB |
Output is correct |
17 |
Correct |
5 ms |
27228 KB |
Output is correct |
18 |
Correct |
7 ms |
27228 KB |
Output is correct |
19 |
Correct |
130 ms |
44628 KB |
Output is correct |
20 |
Correct |
128 ms |
44628 KB |
Output is correct |
21 |
Correct |
114 ms |
43860 KB |
Output is correct |
22 |
Correct |
125 ms |
43904 KB |
Output is correct |
23 |
Correct |
113 ms |
43884 KB |
Output is correct |
24 |
Correct |
89 ms |
41556 KB |
Output is correct |
25 |
Correct |
95 ms |
41552 KB |
Output is correct |
26 |
Correct |
97 ms |
41888 KB |
Output is correct |
27 |
Correct |
102 ms |
41812 KB |
Output is correct |
28 |
Correct |
101 ms |
41908 KB |
Output is correct |
29 |
Correct |
110 ms |
42320 KB |
Output is correct |
30 |
Correct |
111 ms |
42324 KB |
Output is correct |
31 |
Correct |
117 ms |
42216 KB |
Output is correct |
32 |
Correct |
106 ms |
42340 KB |
Output is correct |
33 |
Correct |
109 ms |
42224 KB |
Output is correct |
34 |
Correct |
86 ms |
43108 KB |
Output is correct |
35 |
Correct |
96 ms |
43200 KB |
Output is correct |
36 |
Correct |
96 ms |
42876 KB |
Output is correct |
37 |
Correct |
85 ms |
42832 KB |
Output is correct |
38 |
Correct |
84 ms |
43092 KB |
Output is correct |
39 |
Correct |
94 ms |
41232 KB |
Output is correct |
40 |
Correct |
73 ms |
39684 KB |
Output is correct |
41 |
Correct |
106 ms |
40196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
26972 KB |
Output is correct |
2 |
Correct |
3 ms |
26972 KB |
Output is correct |
3 |
Correct |
4 ms |
27084 KB |
Output is correct |
4 |
Correct |
4 ms |
26972 KB |
Output is correct |
5 |
Correct |
4 ms |
26976 KB |
Output is correct |
6 |
Correct |
4 ms |
26972 KB |
Output is correct |
7 |
Correct |
4 ms |
26972 KB |
Output is correct |
8 |
Correct |
4 ms |
26972 KB |
Output is correct |
9 |
Correct |
4 ms |
27088 KB |
Output is correct |
10 |
Correct |
4 ms |
26968 KB |
Output is correct |
11 |
Correct |
6 ms |
27228 KB |
Output is correct |
12 |
Correct |
5 ms |
27228 KB |
Output is correct |
13 |
Correct |
6 ms |
27228 KB |
Output is correct |
14 |
Correct |
7 ms |
27228 KB |
Output is correct |
15 |
Correct |
7 ms |
27336 KB |
Output is correct |
16 |
Correct |
5 ms |
27156 KB |
Output is correct |
17 |
Correct |
5 ms |
27228 KB |
Output is correct |
18 |
Correct |
7 ms |
27228 KB |
Output is correct |
19 |
Correct |
794 ms |
96492 KB |
Output is correct |
20 |
Correct |
793 ms |
97620 KB |
Output is correct |
21 |
Correct |
775 ms |
97360 KB |
Output is correct |
22 |
Correct |
801 ms |
97616 KB |
Output is correct |
23 |
Correct |
641 ms |
89332 KB |
Output is correct |
24 |
Correct |
59 ms |
37516 KB |
Output is correct |
25 |
Correct |
54 ms |
37456 KB |
Output is correct |
26 |
Correct |
46 ms |
35412 KB |
Output is correct |
27 |
Correct |
50 ms |
35408 KB |
Output is correct |
28 |
Correct |
52 ms |
35412 KB |
Output is correct |
29 |
Correct |
40 ms |
36944 KB |
Output is correct |
30 |
Correct |
40 ms |
36944 KB |
Output is correct |
31 |
Correct |
50 ms |
35080 KB |
Output is correct |
32 |
Correct |
24 ms |
32020 KB |
Output is correct |
33 |
Correct |
45 ms |
35080 KB |
Output is correct |
34 |
Correct |
130 ms |
44628 KB |
Output is correct |
35 |
Correct |
128 ms |
44628 KB |
Output is correct |
36 |
Correct |
114 ms |
43860 KB |
Output is correct |
37 |
Correct |
125 ms |
43904 KB |
Output is correct |
38 |
Correct |
113 ms |
43884 KB |
Output is correct |
39 |
Correct |
89 ms |
41556 KB |
Output is correct |
40 |
Correct |
95 ms |
41552 KB |
Output is correct |
41 |
Correct |
97 ms |
41888 KB |
Output is correct |
42 |
Correct |
102 ms |
41812 KB |
Output is correct |
43 |
Correct |
101 ms |
41908 KB |
Output is correct |
44 |
Correct |
110 ms |
42320 KB |
Output is correct |
45 |
Correct |
111 ms |
42324 KB |
Output is correct |
46 |
Correct |
117 ms |
42216 KB |
Output is correct |
47 |
Correct |
106 ms |
42340 KB |
Output is correct |
48 |
Correct |
109 ms |
42224 KB |
Output is correct |
49 |
Correct |
86 ms |
43108 KB |
Output is correct |
50 |
Correct |
96 ms |
43200 KB |
Output is correct |
51 |
Correct |
96 ms |
42876 KB |
Output is correct |
52 |
Correct |
85 ms |
42832 KB |
Output is correct |
53 |
Correct |
84 ms |
43092 KB |
Output is correct |
54 |
Correct |
94 ms |
41232 KB |
Output is correct |
55 |
Correct |
73 ms |
39684 KB |
Output is correct |
56 |
Correct |
106 ms |
40196 KB |
Output is correct |
57 |
Correct |
779 ms |
97752 KB |
Output is correct |
58 |
Correct |
728 ms |
97888 KB |
Output is correct |
59 |
Correct |
688 ms |
96364 KB |
Output is correct |
60 |
Correct |
741 ms |
96132 KB |
Output is correct |
61 |
Correct |
726 ms |
96340 KB |
Output is correct |
62 |
Correct |
725 ms |
96288 KB |
Output is correct |
63 |
Correct |
452 ms |
84732 KB |
Output is correct |
64 |
Correct |
439 ms |
84816 KB |
Output is correct |
65 |
Correct |
541 ms |
87888 KB |
Output is correct |
66 |
Correct |
567 ms |
87792 KB |
Output is correct |
67 |
Correct |
569 ms |
87904 KB |
Output is correct |
68 |
Correct |
616 ms |
89424 KB |
Output is correct |
69 |
Correct |
616 ms |
89428 KB |
Output is correct |
70 |
Correct |
597 ms |
89172 KB |
Output is correct |
71 |
Correct |
587 ms |
89172 KB |
Output is correct |
72 |
Correct |
612 ms |
89172 KB |
Output is correct |
73 |
Correct |
420 ms |
84820 KB |
Output is correct |
74 |
Correct |
413 ms |
85584 KB |
Output is correct |
75 |
Correct |
436 ms |
84656 KB |
Output is correct |
76 |
Correct |
427 ms |
84928 KB |
Output is correct |
77 |
Correct |
420 ms |
84560 KB |
Output is correct |
78 |
Correct |
569 ms |
86008 KB |
Output is correct |
79 |
Correct |
408 ms |
72948 KB |
Output is correct |
80 |
Correct |
551 ms |
80120 KB |
Output is correct |