Submission #497600

# Submission time Handle Problem Language Result Execution time Memory
497600 2021-12-23T10:33:12 Z vinnipuh01 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
880 ms 92312 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 par[ 1000001 ][ 21 ], mp[ 1000001 ];

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 ];
	}
	for ( int i = 1; i <= n; i ++ ) {
		while ( st.size() && a[ st.top() ] <= a[ i ] )
			st.pop();
		if ( !st.size() ) {
			par[ i ][ 0 ] = 0;
		}
		else {
			par[ i ][ 0 ] = st.top(), mp[ st.top() ] = i;
		}
		st.push( i );
	}
	for ( int i = 1; i <= n; i ++ ) {
		for ( int j = 1; j <= lg; j ++ )
			par[ i ][ j ] = par[ par[ i ][ j - 1 ] ][ j - 1 ];
	}
	int l, r, x;
	while ( m -- ) {
		cin >> l >> r >> x;
		for ( int i = lg; i >= 0; i -- ) {
			if ( par[ r ][ i ] >= l )
				num = r, r = par[ r ][ i ];
		}
		if ( par[ r ][ 0 ] >= l ) {
			r = par[ r ][ 0 ];
		}
		sum = 0;
		if ( mp[ r ] <= r )
			sum = a[ r ] + a[ mp[ r ] ];
		cout << ( x >= sum ) << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 880 ms 92312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 63 ms 9404 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -