Submission #497594

# Submission time Handle Problem Language Result Execution time Memory
497594 2021-12-23T10:25:45 Z vinnipuh01 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
842 ms 93304 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 ] = i, mp[ i ] = i;
		}
		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 = a[ r ] + a[ mp[ r ] ];
		cout << ( x >= sum ) << "\n";
	}
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 842 ms 93304 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 67 ms 10432 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Incorrect 1 ms 332 KB Output isn't correct
4 Halted 0 ms 0 KB -