Submission #154501

# Submission time Handle Problem Language Result Execution time Memory
154501 2019-09-22T10:17:07 Z muhammad_hokimiyon Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
1769 ms 37500 KB
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define fi first
#define se second
#define LL long long

using namespace std;

const int N = 1e6 + 7;
const LL mod = 1e9 + 7;
const int B = sqrt(1e5);

int n,q;
int a[N];
int l[N];
int r[N];
int k[N];
int ord[N];
int nxt[N];
int t[4 * N];
stack < int > s;

void add( int x , int l , int r , int pos , int xx )
{
    if( !( l <= pos && r >= pos ) )return;
    t[x] = max( t[x] , xx );
    int m = (l + r) / 2;
    if( l == r )return;
    add(x * 2 , l , m , pos , x);
    add(x * 2 + 1 , m + 1 , r , pos , x);
}

int get( int x , int l , int r , int tl , int tr )
{
    if( l >= tl && r <= tr )return t[x];
    if( l > tr || r < tl )return -1;
    int m = (l + r) / 2;
    return max( get(x * 2 , l , m , tl , tr ) ,
        get( x * 2 + 1  , m + 1 , r , tl , tr) );
}

bool cmp( int x , int y ){
    return r[x] < r[y];
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //freopen( "input.txt" , "r" , stdin );
    //freopen( "output.txt" , "w" , stdout );

    cin >> n >> q;
    for( int i = 0; i < n; i++ ){
        cin >> a[i];
    }
    for( int i = 0; i < q; i++ ){
        cin >> l[i] >> r[i] >> k[i];
        l[i]--,r[i]--;
        ord[i] = i;
    }
    int cnt = 0;
    sort( ord , ord + q , cmp );
    for( int i = 0; i < n; i++ ){
        while( !s.empty() && a[s.top()] <= a[i] ){
            s.pop();
        }
        if( !s.empty() ){
            nxt[i] = s.top();
        }
        s.push(i);
    }
    for( int i = 0; i < q; i++ ){
        int y = ord[i];
        while( cnt < r[y] ){
            cnt++;
            if( nxt[cnt] > 0 ){
                add( 1 , 0 , n - 1 , nxt[cnt] , a[nxt[cnt]] + a[cnt] );
            }
        }
        if( get(1 , 0 , n - 1, l[i] , r[i]) <= k[i] )cout << 1 << "\n";
        else cout << 0 << "\n";
    }
}

# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1769 ms 37500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 136 ms 5880 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 2 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -