#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 10;
const int inf = 1e9 + 10;
int v[maxn];
bool resp[maxn];
struct evento{
int l, r, k, val, id, t;
evento( int l, int r, int k, int id, int t ) : l(l), r(r), k(k), id(id), t(t) {}
evento( int l, int val, int t ) : l(l), val(val), t(t) {}
bool operator < ( evento e ){
if( l == e.l ) return t < e.t;
return l > e.l;
}
};
vector<evento> line;
stack< pair< int, int > > s;
struct node{
int max_val, max_inv = 0, lz = 0;
node(){}
node operator + ( node n ){
node resp;
resp.max_val = max( max_val, n.max_val );
resp.max_inv = max( max_inv, n.max_inv );
return resp;
}
};
node seg[4*maxn];
void build( int pos, int ini, int fim ){
if( ini == fim ){
seg[pos].max_val = v[ini];
return;
}
int mid = ( ini + fim )/2;
int l = 2*pos, r = 2*pos + 1;
build( l, ini, mid );
build( r, mid + 1, fim );
seg[pos] = seg[l] + seg[r];
}
void refresh( int pos, int ini, int fim ){
if( seg[pos].lz == 0 ) return;
int s = seg[pos].lz;
seg[pos].lz = 0;
seg[pos].max_inv = seg[pos].max_val + s;
if( ini == fim ) return;
int l = 2*pos, r = 2*pos + 1;
seg[l].lz = s;
seg[r].lz = s;
}
void update( int pos, int ini, int fim, int ki, int kf, int val ){
refresh( pos, ini, fim );
if( ki > fim || ini > kf ) return;
if( ki <= ini && fim <= kf ){
seg[pos].lz = val;
refresh( pos, ini, fim );
return;
}
int mid = ( ini + fim )/2;
int l = 2*pos, r = 2*pos + 1;
update( l, ini, mid, ki, kf, val );
update( r, mid + 1, fim, ki, kf, val );
seg[pos] = seg[l] + seg[r];
}
int query( int pos, int ini, int fim, int ki, int kf ){
refresh( pos, ini, fim );
if( ki > fim || ini > kf ) return -1;
if( ki <= ini && fim <= kf ) return seg[pos].max_inv;
int mid = ( ini + fim )/2;
int l = 2*pos, r = 2*pos + 1;
int queryL = query( l, ini, mid, ki, kf );
int queryR = query( r, mid + 1, fim, ki, kf );
return max( queryL, queryR );
}
int main(){
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, m; cin >> n >> m;
for( int i = 1; i <= n; i++ ){
cin >> v[i];
line.push_back( evento( i, v[i], 1 ) );
}
build( 1, 1, n );
for( int i = 1; i <= m; i++ ){
int l, r, k; cin >> l >> r >> k;
line.push_back( evento( l, r, k, i, 2 ) );
}
sort( line.begin(), line.end() );
s.push({ inf, n + 1 });
for( evento e : line ){
if( e.t == 1 ){
while( s.top().first < e.val ) s.pop();
update( 1, 1, n, e.l + 1, s.top().second - 1, e.val );
s.push({ e.val, e.l });
}
else{
int inv = query( 1, 1, n, e.l, e.r );
resp[ e.id ] = ( inv <= e.k );
}
}
for( int i = 1; i <= m; i++ ) cout << resp[i] << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
47188 KB |
Output is correct |
2 |
Correct |
21 ms |
47248 KB |
Output is correct |
3 |
Correct |
21 ms |
47316 KB |
Output is correct |
4 |
Correct |
20 ms |
47316 KB |
Output is correct |
5 |
Correct |
19 ms |
47316 KB |
Output is correct |
6 |
Correct |
22 ms |
47316 KB |
Output is correct |
7 |
Correct |
23 ms |
47348 KB |
Output is correct |
8 |
Correct |
20 ms |
47288 KB |
Output is correct |
9 |
Correct |
21 ms |
47316 KB |
Output is correct |
10 |
Correct |
24 ms |
47360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
47188 KB |
Output is correct |
2 |
Correct |
21 ms |
47248 KB |
Output is correct |
3 |
Correct |
21 ms |
47316 KB |
Output is correct |
4 |
Correct |
20 ms |
47316 KB |
Output is correct |
5 |
Correct |
19 ms |
47316 KB |
Output is correct |
6 |
Correct |
22 ms |
47316 KB |
Output is correct |
7 |
Correct |
23 ms |
47348 KB |
Output is correct |
8 |
Correct |
20 ms |
47288 KB |
Output is correct |
9 |
Correct |
21 ms |
47316 KB |
Output is correct |
10 |
Correct |
24 ms |
47360 KB |
Output is correct |
11 |
Correct |
29 ms |
47636 KB |
Output is correct |
12 |
Correct |
37 ms |
47696 KB |
Output is correct |
13 |
Correct |
28 ms |
47740 KB |
Output is correct |
14 |
Correct |
35 ms |
47884 KB |
Output is correct |
15 |
Correct |
31 ms |
47908 KB |
Output is correct |
16 |
Correct |
31 ms |
47892 KB |
Output is correct |
17 |
Correct |
30 ms |
47892 KB |
Output is correct |
18 |
Correct |
30 ms |
48016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2772 ms |
133144 KB |
Output is correct |
2 |
Correct |
2922 ms |
134272 KB |
Output is correct |
3 |
Correct |
2741 ms |
134160 KB |
Output is correct |
4 |
Correct |
2764 ms |
134056 KB |
Output is correct |
5 |
Correct |
2880 ms |
142208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
256 ms |
55128 KB |
Output is correct |
2 |
Correct |
239 ms |
54976 KB |
Output is correct |
3 |
Correct |
253 ms |
55376 KB |
Output is correct |
4 |
Correct |
256 ms |
55480 KB |
Output is correct |
5 |
Correct |
242 ms |
55472 KB |
Output is correct |
6 |
Correct |
248 ms |
55272 KB |
Output is correct |
7 |
Correct |
239 ms |
55220 KB |
Output is correct |
8 |
Correct |
232 ms |
54792 KB |
Output is correct |
9 |
Correct |
215 ms |
51448 KB |
Output is correct |
10 |
Correct |
235 ms |
54836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
47188 KB |
Output is correct |
2 |
Correct |
21 ms |
47248 KB |
Output is correct |
3 |
Correct |
21 ms |
47316 KB |
Output is correct |
4 |
Correct |
20 ms |
47316 KB |
Output is correct |
5 |
Correct |
19 ms |
47316 KB |
Output is correct |
6 |
Correct |
22 ms |
47316 KB |
Output is correct |
7 |
Correct |
23 ms |
47348 KB |
Output is correct |
8 |
Correct |
20 ms |
47288 KB |
Output is correct |
9 |
Correct |
21 ms |
47316 KB |
Output is correct |
10 |
Correct |
24 ms |
47360 KB |
Output is correct |
11 |
Correct |
29 ms |
47636 KB |
Output is correct |
12 |
Correct |
37 ms |
47696 KB |
Output is correct |
13 |
Correct |
28 ms |
47740 KB |
Output is correct |
14 |
Correct |
35 ms |
47884 KB |
Output is correct |
15 |
Correct |
31 ms |
47908 KB |
Output is correct |
16 |
Correct |
31 ms |
47892 KB |
Output is correct |
17 |
Correct |
30 ms |
47892 KB |
Output is correct |
18 |
Correct |
30 ms |
48016 KB |
Output is correct |
19 |
Correct |
528 ms |
64764 KB |
Output is correct |
20 |
Correct |
602 ms |
64676 KB |
Output is correct |
21 |
Correct |
583 ms |
64544 KB |
Output is correct |
22 |
Correct |
540 ms |
64560 KB |
Output is correct |
23 |
Correct |
547 ms |
64644 KB |
Output is correct |
24 |
Correct |
534 ms |
65996 KB |
Output is correct |
25 |
Correct |
557 ms |
66032 KB |
Output is correct |
26 |
Correct |
599 ms |
66148 KB |
Output is correct |
27 |
Correct |
598 ms |
66400 KB |
Output is correct |
28 |
Correct |
596 ms |
66168 KB |
Output is correct |
29 |
Correct |
549 ms |
66312 KB |
Output is correct |
30 |
Correct |
554 ms |
66248 KB |
Output is correct |
31 |
Correct |
584 ms |
66224 KB |
Output is correct |
32 |
Correct |
555 ms |
66284 KB |
Output is correct |
33 |
Correct |
580 ms |
66312 KB |
Output is correct |
34 |
Correct |
557 ms |
65972 KB |
Output is correct |
35 |
Correct |
528 ms |
65816 KB |
Output is correct |
36 |
Correct |
610 ms |
65656 KB |
Output is correct |
37 |
Correct |
547 ms |
65628 KB |
Output is correct |
38 |
Correct |
561 ms |
65936 KB |
Output is correct |
39 |
Correct |
515 ms |
64228 KB |
Output is correct |
40 |
Correct |
418 ms |
63668 KB |
Output is correct |
41 |
Correct |
545 ms |
63440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
47188 KB |
Output is correct |
2 |
Correct |
21 ms |
47248 KB |
Output is correct |
3 |
Correct |
21 ms |
47316 KB |
Output is correct |
4 |
Correct |
20 ms |
47316 KB |
Output is correct |
5 |
Correct |
19 ms |
47316 KB |
Output is correct |
6 |
Correct |
22 ms |
47316 KB |
Output is correct |
7 |
Correct |
23 ms |
47348 KB |
Output is correct |
8 |
Correct |
20 ms |
47288 KB |
Output is correct |
9 |
Correct |
21 ms |
47316 KB |
Output is correct |
10 |
Correct |
24 ms |
47360 KB |
Output is correct |
11 |
Correct |
29 ms |
47636 KB |
Output is correct |
12 |
Correct |
37 ms |
47696 KB |
Output is correct |
13 |
Correct |
28 ms |
47740 KB |
Output is correct |
14 |
Correct |
35 ms |
47884 KB |
Output is correct |
15 |
Correct |
31 ms |
47908 KB |
Output is correct |
16 |
Correct |
31 ms |
47892 KB |
Output is correct |
17 |
Correct |
30 ms |
47892 KB |
Output is correct |
18 |
Correct |
30 ms |
48016 KB |
Output is correct |
19 |
Correct |
2772 ms |
133144 KB |
Output is correct |
20 |
Correct |
2922 ms |
134272 KB |
Output is correct |
21 |
Correct |
2741 ms |
134160 KB |
Output is correct |
22 |
Correct |
2764 ms |
134056 KB |
Output is correct |
23 |
Correct |
2880 ms |
142208 KB |
Output is correct |
24 |
Correct |
256 ms |
55128 KB |
Output is correct |
25 |
Correct |
239 ms |
54976 KB |
Output is correct |
26 |
Correct |
253 ms |
55376 KB |
Output is correct |
27 |
Correct |
256 ms |
55480 KB |
Output is correct |
28 |
Correct |
242 ms |
55472 KB |
Output is correct |
29 |
Correct |
248 ms |
55272 KB |
Output is correct |
30 |
Correct |
239 ms |
55220 KB |
Output is correct |
31 |
Correct |
232 ms |
54792 KB |
Output is correct |
32 |
Correct |
215 ms |
51448 KB |
Output is correct |
33 |
Correct |
235 ms |
54836 KB |
Output is correct |
34 |
Correct |
528 ms |
64764 KB |
Output is correct |
35 |
Correct |
602 ms |
64676 KB |
Output is correct |
36 |
Correct |
583 ms |
64544 KB |
Output is correct |
37 |
Correct |
540 ms |
64560 KB |
Output is correct |
38 |
Correct |
547 ms |
64644 KB |
Output is correct |
39 |
Correct |
534 ms |
65996 KB |
Output is correct |
40 |
Correct |
557 ms |
66032 KB |
Output is correct |
41 |
Correct |
599 ms |
66148 KB |
Output is correct |
42 |
Correct |
598 ms |
66400 KB |
Output is correct |
43 |
Correct |
596 ms |
66168 KB |
Output is correct |
44 |
Correct |
549 ms |
66312 KB |
Output is correct |
45 |
Correct |
554 ms |
66248 KB |
Output is correct |
46 |
Correct |
584 ms |
66224 KB |
Output is correct |
47 |
Correct |
555 ms |
66284 KB |
Output is correct |
48 |
Correct |
580 ms |
66312 KB |
Output is correct |
49 |
Correct |
557 ms |
65972 KB |
Output is correct |
50 |
Correct |
528 ms |
65816 KB |
Output is correct |
51 |
Correct |
610 ms |
65656 KB |
Output is correct |
52 |
Correct |
547 ms |
65628 KB |
Output is correct |
53 |
Correct |
561 ms |
65936 KB |
Output is correct |
54 |
Correct |
515 ms |
64228 KB |
Output is correct |
55 |
Correct |
418 ms |
63668 KB |
Output is correct |
56 |
Correct |
545 ms |
63440 KB |
Output is correct |
57 |
Correct |
2705 ms |
134744 KB |
Output is correct |
58 |
Correct |
2727 ms |
134816 KB |
Output is correct |
59 |
Correct |
2640 ms |
134760 KB |
Output is correct |
60 |
Correct |
2622 ms |
134788 KB |
Output is correct |
61 |
Correct |
2719 ms |
134840 KB |
Output is correct |
62 |
Correct |
2617 ms |
134752 KB |
Output is correct |
63 |
Correct |
2387 ms |
140888 KB |
Output is correct |
64 |
Correct |
2378 ms |
140960 KB |
Output is correct |
65 |
Correct |
2843 ms |
142836 KB |
Output is correct |
66 |
Correct |
2573 ms |
142844 KB |
Output is correct |
67 |
Correct |
2641 ms |
142744 KB |
Output is correct |
68 |
Correct |
2626 ms |
142864 KB |
Output is correct |
69 |
Correct |
2715 ms |
142980 KB |
Output is correct |
70 |
Correct |
2656 ms |
142924 KB |
Output is correct |
71 |
Correct |
2570 ms |
142960 KB |
Output is correct |
72 |
Correct |
2593 ms |
142904 KB |
Output is correct |
73 |
Correct |
2440 ms |
139412 KB |
Output is correct |
74 |
Correct |
2438 ms |
140388 KB |
Output is correct |
75 |
Correct |
2463 ms |
139456 KB |
Output is correct |
76 |
Correct |
2423 ms |
139400 KB |
Output is correct |
77 |
Correct |
2376 ms |
139488 KB |
Output is correct |
78 |
Correct |
2416 ms |
133940 KB |
Output is correct |
79 |
Correct |
2085 ms |
114008 KB |
Output is correct |
80 |
Correct |
2406 ms |
129828 KB |
Output is correct |