Submission #497644

# Submission time Handle Problem Language Result Execution time Memory
497644 2021-12-23T12:50:23 Z vinnipuh01 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1313 ms 55284 KB
#include <iostream>
#include <bits/stdc++.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <deque>
#include <set>
#include <stack>
#include <string>
#include <map>
#include <queue>
 
using namespace std;
 
const long long oo = 1000000000000000000;
 
long long sum, ans = 0, mx = 0, mn = 1000000000, num, pos;
 
 
/*
    ViHHiPuh
 
   (( `'-""``""-'` ))
     )-__-_.._-__-(
   / --- (o _ o) --- \
   \ .-* ( .0. ) *-. /
   _'-. ,_ '=' _, .-'_
  / `;#'#'# - #'#'#;` \
 \_)) -----'#'----- ((_/
      # --------- #
  '# ------- ------ #'
  /..-'# ------- #'-.\
  _\...-\'# -- #'/-.../_
  ((____)- '#' -(____))
 
 
    cout << fixed << setprecision(6) << x;
 
 
    freopen ( "sum.in", "r", stdin )
*/

stack <int> st;
int lg = 20;
int t[ 4000001 ], mp[ 1000001 ], an[ 1000001 ];

vector <pair<int, int> > v;

void upd( int v, int tl, int tr, int pos, int x ) {
	if ( tl > pos || tr < pos )
		return;
	if ( tl == tr ) {
		t[ v ] = max( x, t[ v ] );
		return;
	}
	int mid = ( tl + tr ) / 2;
	upd( v + v, tl, mid, pos, x );
	upd( v + v + 1, mid + 1, tr, pos, x );
	t[ v ] = max( t[ v + v ], t[ v + v + 1 ] );
}

void gett( int v, int tl, int tr ,int l, int r ) {
	if ( tl > r || tr < l )
		return;
	if ( tl >= l && tr <= r ) {
//		cout << tl << " " << tr << " " << t[ v ] << "\n";
		num = max( num, t[ v ] + 0ll );
		return;
	}
	int mid = ( tl + tr ) / 2;
	gett( v + v, tl, mid, l, r );
	gett( v + v + 1, mid + 1, tr, l, r );
}

int main () {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
	int n, m;
	cin >> n >> m;
	int a[ n + 1 ];
	for ( int i = 1; i <= n; i ++ ) {
		cin >> a[ i ];
	}
	int l[ m + 1 ], r[ m + 1 ], x[ m + 1 ];
	for ( int i = 1; i <= m;  i++ ) {
		cin >> l[ i ] >> r[ i ] >> x[ i ];
		v.push_back( { r[ i ], i } );
	}
	sort( v.begin(), v.end() );
	reverse( v.begin(), v.end() );
	for ( int i = 1; i <= n; i ++ ) {
		while ( st.size() && a[ st.top() ] <= a[ i ] )
			st.pop();
		if ( !st.size() ) {
			mp[ i ] = 0;
		}
		else {
			mp[ i ] = st.top();
		}
		st.push( i );
		sum = 0;
		if ( mp[ i ] ) {
			sum = a[ i ] + a[ mp[ i ] ];
			upd( 1, 1, n, mp[ i ], sum );
		}
		num = 0;
		while ( v.size() && v.back().first == i ) {
			num = 0;
			gett( 1, 1, n, l[ v.back().second ], r[ v.back().second ] );
			an[ v.back().second ] = ( x[ v.back().second ] >= num );
			v.pop_back();
		}
	}
	for ( int i = 1; i <= m; i ++ )
		cout << an[ i ] << "\n";
}

/*
2 1
5 1 
2 2 2

*/
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 3 ms 556 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
14 Correct 5 ms 840 KB Output is correct
15 Correct 5 ms 712 KB Output is correct
16 Correct 4 ms 656 KB Output is correct
17 Correct 4 ms 680 KB Output is correct
18 Correct 4 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1190 ms 41980 KB Output is correct
2 Correct 1313 ms 46508 KB Output is correct
3 Correct 1243 ms 46484 KB Output is correct
4 Correct 1229 ms 55284 KB Output is correct
5 Correct 975 ms 48452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 92 ms 4824 KB Output is correct
2 Correct 85 ms 6820 KB Output is correct
3 Correct 81 ms 5712 KB Output is correct
4 Correct 70 ms 5792 KB Output is correct
5 Correct 69 ms 5696 KB Output is correct
6 Correct 74 ms 5624 KB Output is correct
7 Correct 75 ms 5648 KB Output is correct
8 Correct 71 ms 5524 KB Output is correct
9 Correct 41 ms 4340 KB Output is correct
10 Correct 77 ms 5552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 3 ms 556 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
14 Correct 5 ms 840 KB Output is correct
15 Correct 5 ms 712 KB Output is correct
16 Correct 4 ms 656 KB Output is correct
17 Correct 4 ms 680 KB Output is correct
18 Correct 4 ms 588 KB Output is correct
19 Correct 203 ms 15668 KB Output is correct
20 Correct 199 ms 15704 KB Output is correct
21 Correct 220 ms 15484 KB Output is correct
22 Correct 209 ms 15516 KB Output is correct
23 Correct 193 ms 15668 KB Output is correct
24 Correct 161 ms 13364 KB Output is correct
25 Correct 160 ms 13604 KB Output is correct
26 Correct 168 ms 13596 KB Output is correct
27 Correct 154 ms 13568 KB Output is correct
28 Correct 178 ms 13660 KB Output is correct
29 Correct 162 ms 13628 KB Output is correct
30 Correct 190 ms 13748 KB Output is correct
31 Correct 181 ms 13700 KB Output is correct
32 Correct 184 ms 13712 KB Output is correct
33 Correct 185 ms 13632 KB Output is correct
34 Correct 157 ms 13336 KB Output is correct
35 Correct 158 ms 13336 KB Output is correct
36 Correct 153 ms 13204 KB Output is correct
37 Correct 155 ms 13084 KB Output is correct
38 Correct 153 ms 13264 KB Output is correct
39 Correct 156 ms 12964 KB Output is correct
40 Correct 121 ms 11032 KB Output is correct
41 Correct 163 ms 11932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 3 ms 556 KB Output is correct
13 Correct 4 ms 588 KB Output is correct
14 Correct 5 ms 840 KB Output is correct
15 Correct 5 ms 712 KB Output is correct
16 Correct 4 ms 656 KB Output is correct
17 Correct 4 ms 680 KB Output is correct
18 Correct 4 ms 588 KB Output is correct
19 Correct 1190 ms 41980 KB Output is correct
20 Correct 1313 ms 46508 KB Output is correct
21 Correct 1243 ms 46484 KB Output is correct
22 Correct 1229 ms 55284 KB Output is correct
23 Correct 975 ms 48452 KB Output is correct
24 Correct 92 ms 4824 KB Output is correct
25 Correct 85 ms 6820 KB Output is correct
26 Correct 81 ms 5712 KB Output is correct
27 Correct 70 ms 5792 KB Output is correct
28 Correct 69 ms 5696 KB Output is correct
29 Correct 74 ms 5624 KB Output is correct
30 Correct 75 ms 5648 KB Output is correct
31 Correct 71 ms 5524 KB Output is correct
32 Correct 41 ms 4340 KB Output is correct
33 Correct 77 ms 5552 KB Output is correct
34 Correct 203 ms 15668 KB Output is correct
35 Correct 199 ms 15704 KB Output is correct
36 Correct 220 ms 15484 KB Output is correct
37 Correct 209 ms 15516 KB Output is correct
38 Correct 193 ms 15668 KB Output is correct
39 Correct 161 ms 13364 KB Output is correct
40 Correct 160 ms 13604 KB Output is correct
41 Correct 168 ms 13596 KB Output is correct
42 Correct 154 ms 13568 KB Output is correct
43 Correct 178 ms 13660 KB Output is correct
44 Correct 162 ms 13628 KB Output is correct
45 Correct 190 ms 13748 KB Output is correct
46 Correct 181 ms 13700 KB Output is correct
47 Correct 184 ms 13712 KB Output is correct
48 Correct 185 ms 13632 KB Output is correct
49 Correct 157 ms 13336 KB Output is correct
50 Correct 158 ms 13336 KB Output is correct
51 Correct 153 ms 13204 KB Output is correct
52 Correct 155 ms 13084 KB Output is correct
53 Correct 153 ms 13264 KB Output is correct
54 Correct 156 ms 12964 KB Output is correct
55 Correct 121 ms 11032 KB Output is correct
56 Correct 163 ms 11932 KB Output is correct
57 Correct 1255 ms 50284 KB Output is correct
58 Correct 1225 ms 50936 KB Output is correct
59 Correct 1193 ms 51048 KB Output is correct
60 Correct 1213 ms 50864 KB Output is correct
61 Correct 1167 ms 50944 KB Output is correct
62 Correct 1141 ms 50876 KB Output is correct
63 Correct 888 ms 42208 KB Output is correct
64 Correct 889 ms 42272 KB Output is correct
65 Correct 878 ms 42840 KB Output is correct
66 Correct 894 ms 42812 KB Output is correct
67 Correct 902 ms 42912 KB Output is correct
68 Correct 922 ms 42748 KB Output is correct
69 Correct 921 ms 42792 KB Output is correct
70 Correct 917 ms 42868 KB Output is correct
71 Correct 914 ms 42824 KB Output is correct
72 Correct 922 ms 42696 KB Output is correct
73 Correct 844 ms 42144 KB Output is correct
74 Correct 861 ms 42168 KB Output is correct
75 Correct 836 ms 41944 KB Output is correct
76 Correct 851 ms 41928 KB Output is correct
77 Correct 871 ms 41900 KB Output is correct
78 Correct 835 ms 44140 KB Output is correct
79 Correct 615 ms 47556 KB Output is correct
80 Correct 834 ms 40972 KB Output is correct