結果

問題 No.905 Sorted?
ユーザー MisterMister
提出日時 2020-04-21 20:10:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 169 ms / 2,000 ms
コード長 901 bytes
コンパイル時間 680 ms
コンパイル使用メモリ 77,912 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-17 11:01:04
合計ジャッジ時間 4,060 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 3 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 4 ms
5,376 KB
testcase_08 AC 150 ms
5,376 KB
testcase_09 AC 91 ms
5,376 KB
testcase_10 AC 125 ms
5,376 KB
testcase_11 AC 134 ms
5,376 KB
testcase_12 AC 169 ms
5,376 KB
testcase_13 AC 148 ms
5,376 KB
testcase_14 AC 148 ms
5,376 KB
testcase_15 AC 162 ms
5,376 KB
testcase_16 AC 165 ms
5,376 KB
testcase_17 AC 165 ms
5,376 KB
testcase_18 AC 117 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>

using lint = long long;

void solve() {
    int n;
    std::cin >> n;

    std::vector<lint> xs(n);
    for (auto& x : xs) std::cin >> x;

    std::vector<int> up(n);
    {
        int r = 0;
        for (int l = 0; l < n; ++l) {
            while (r < n &&
                   (r - 1 < l || xs[r - 1] <= xs[r])) ++r;
            up[l] = r;
        }
    }

    std::vector<int> down(n);
    {
        int r = 0;
        for (int l = 0; l < n; ++l) {
            while (r < n &&
                   (r - 1 < l || xs[r - 1] >= xs[r])) ++r;
            down[l] = r;
        }
    }

    int q;
    std::cin >> q;
    while (q--) {
        int l, r;
        std::cin >> l >> r;
        std::cout << (r < up[l]) << " " << (r < down[l]) << std::endl;
    }
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0