Submission #497621

# Submission time Handle Problem Language Result Execution time Memory
497621 2021-12-23T11:54:42 Z vinnipuh01 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
1265 ms 42148 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 ];

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 ) {
		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;
		if ( v.size() ) {
			gett( 1, 1, n, l[ v.back().second ], r[ v.back().second ] );
			cout << ( x[ v.back().second ] >= num ) << "\n";
			v.pop_back();
		}
	}
}

/*
9 1
5 2 2 8 3 4 8 9 10 
1 9 5


*/
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1265 ms 42148 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 95 ms 6184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -