結果

問題 No.905 Sorted?
ユーザー betrue12betrue12
提出日時 2019-10-11 21:53:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 319 ms / 2,000 ms
コード長 1,691 bytes
コンパイル時間 1,811 ms
コンパイル使用メモリ 173,804 KB
実行使用メモリ 8,216 KB
最終ジャッジ日時 2023-08-16 17:40:25
合計ジャッジ時間 6,417 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,384 KB
testcase_01 AC 2 ms
4,384 KB
testcase_02 AC 2 ms
4,384 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 5 ms
4,384 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 8 ms
4,376 KB
testcase_08 AC 284 ms
5,344 KB
testcase_09 AC 179 ms
5,516 KB
testcase_10 AC 269 ms
7,764 KB
testcase_11 AC 244 ms
7,720 KB
testcase_12 AC 282 ms
7,772 KB
testcase_13 AC 283 ms
7,800 KB
testcase_14 AC 319 ms
7,688 KB
testcase_15 AC 260 ms
7,764 KB
testcase_16 AC 304 ms
8,216 KB
testcase_17 AC 305 ms
7,816 KB
testcase_18 AC 224 ms
7,732 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,384 KB
testcase_22 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

template<typename T>
struct Segtree {
    int n;
    T e;
    vector<T> dat;
    typedef function<T(T a, T b)> Func;
    Func f;

    Segtree(){}
    Segtree(int n_input, Func f_input, T e_input){
        initialize(n_input, f_input, e_input);
    }
    void initialize(int n_input, Func f_input, T e_input){
        f = f_input;
        e = e_input;
        n = 1;
        while(n < n_input) n <<= 1;
        dat.resize(2*n-1, e);
    }

    void update(int k, T a){
        k += n - 1;
        dat[k] = a;
        while(k > 0){
            k = (k - 1)/2;
            dat[k] = f(dat[2*k+1], dat[2*k+2]);
        }
    }

    T get(int k){
        return dat[k+n-1];
    }

    T between(int a, int b){
        return query(a, b+1, 0, 0, n);
    }

    T query(int a, int b, int k, int l, int r){
        if(r<=a || b<=l) return e;
        if(a<=l && r<=b) return dat[k];
        T vl = query(a, b, 2*k+1, l, (l+r)/2);
        T vr = query(a, b, 2*k+2, (l+r)/2, r);
        return f(vl, vr);
    }
};

int main(){
    int N;
    int64_t A[100000];
    cin >> N;
    for(int i=0; i<N; i++) cin >> A[i];
    Segtree<int64_t> stmax(N-1, [](int64_t a, int64_t b){ return max(a, b); }, -2e18);
    Segtree<int64_t> stmin(N-1, [](int64_t a, int64_t b){ return min(a, b); }, 2e18);
    for(int i=0; i<N-1; i++){
        int64_t d = A[i+1] - A[i];
        stmax.update(i, d);
        stmin.update(i, d);
    }
    int Q;
    cin >> Q;
    while(Q--){
        int l, r;
        cin >> l >> r;
        r--;
        int ans1 = (stmin.between(l, r) >= 0);
        int ans2 = (stmax.between(l, r) <= 0);
        cout << ans1 << " " << ans2 << endl;
    }
}
0