結果

問題 No.905 Sorted?
ユーザー Konton7Konton7
提出日時 2020-01-17 15:05:40
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 250 ms / 2,000 ms
コード長 1,094 bytes
コンパイル時間 2,089 ms
コンパイル使用メモリ 192,020 KB
最終ジャッジ日時 2025-01-08 18:11:44
ジャッジサーバーID
(参考情報)
judge5 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

// #define DEBUG

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    int n, q, s1, s2, l, r;
    cin >> n;
    ll a[n];
    bool lt[n-1], gt[n-1];
    int lt_acum[n], gt_acum[n];
    s1 = s2 = lt_acum[0] = gt_acum[0] = 0;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    for (int i = 0; i < n-1; i++){
        lt[i] = a[i+1] <= a[i];
        s1 += lt[i];
        lt_acum[i+1] = s1;
        gt[i] = a[i+1] >= a[i];
        s2 += gt[i];
        gt_acum[i+1] = s2;
    }

    // for (int i = 0; i < n; i++)
    // {
    //     cout << gt_acum[i] << " ";
    // }
    // cout << endl;
    // for (int i = 0; i < n; i++)
    // {
    //     cout << lt_acum[i] << " ";
    // }
    // cout << endl;


    cin >> q;
    for (int i = 0; i < q; i++){
        cin >> l >> r;
        printf( "%d %d\n", (gt_acum[r] - gt_acum[l] == r - l) ? 1 : 0, ( (lt_acum[r] - lt_acum[l] == r - l) ? 1 : 0 ) );
    }


    return 0;
}
0