답안 #154499

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
154499 2019-09-22T10:13:25 Z muhammad_hokimiyon Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
0 / 100
1397 ms 47568 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 , min(tr , m) ) ,
        get( x * 2 + 1  , m + 1 , r , min(tl , m + 1) , 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 = 1; i <= n; i++ ){
        cin >> a[i];
    }
    for( int i = 1; i <= q; i++ ){
        cin >> l[i] >> r[i] >> k[i];
        ord[i] = i;
    }
    int cnt = 0;
    sort( ord + 1 , ord + q + 1 , cmp );
    for( int i = 1; 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 = 1; i <= q; i++ ){
        int y = ord[i];
        while( cnt < r[y] ){
            cnt++;
            if( nxt[cnt] > 0 ){
                add( 1 , 1 , n , nxt[cnt] , a[nxt[cnt]] + a[cnt] );
            }
        }
        if( get(1 , 1 , n , l[i] , r[i]) <= k[i] )cout << 1 << "\n";
        else cout << 0 << "\n";
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 3 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 3 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1397 ms 47568 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 107 ms 5876 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 3 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Incorrect 3 ms 376 KB Output isn't correct
4 Halted 0 ms 0 KB -