結果

問題 No.905 Sorted?
ユーザー milanis48663220milanis48663220
提出日時 2019-10-11 21:49:26
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 303 ms / 2,000 ms
コード長 1,069 bytes
コンパイル時間 549 ms
コンパイル使用メモリ 65,412 KB
実行使用メモリ 7,296 KB
最終ジャッジ日時 2024-05-04 01:25:08
合計ジャッジ時間 3,748 ms
ジャッジサーバーID
(参考情報)
judge3 / 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 152 ms
5,376 KB
testcase_09 AC 93 ms
5,376 KB
testcase_10 AC 136 ms
6,528 KB
testcase_11 AC 147 ms
5,888 KB
testcase_12 AC 171 ms
5,632 KB
testcase_13 AC 155 ms
6,528 KB
testcase_14 AC 155 ms
6,528 KB
testcase_15 AC 303 ms
7,296 KB
testcase_16 AC 170 ms
5,760 KB
testcase_17 AC 177 ms
6,528 KB
testcase_18 AC 121 ms
6,528 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 1 ms
5,376 KB
testcase_22 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>

using namespace std;

long A[100000];
long pos[100001];
long neg[100001];
long pos_sum[100001];
long neg_sum[100001];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
        if(i >= 1){
            if(A[i] > A[i-1]) pos[i-1] = 1;
            if(A[i] < A[i-1]) neg[i-1] = 1;
            pos_sum[i] = pos_sum[i-1]+pos[i-1];
            neg_sum[i] = neg_sum[i-1]+neg[i-1];
        }
    }
    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++){
        int l, r;
        cin >> l >> r;
        if(l == r){
            cout << 1 << ' ' << 1 << endl;
        }else{
            if(neg_sum[r] > neg_sum[l]){
                cout << 0;
            }else{
                cout << 1;
            }
            cout << ' ';
            if(pos_sum[r] > pos_sum[l]){
                cout << 0;
            }else{
                cout << 1;
            }
            cout << endl;
        }
    }

}
0