Submission #497604

#TimeUsernameProblemLanguageResultExecution timeMemory
497604vinnipuh01Hedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
815 ms92304 KiB
#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; num = r; for ( int i = lg; i >= 0; i -- ) { if ( par[ r ][ i ] >= l ) num = r, r = par[ r ][ i ]; } sum = 0; if ( mp[ r ] <= num ) sum = a[ r ] + a[ mp[ r ] ]; cout << ( x >= sum ) << "\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...