結果

問題 No.905 Sorted?
ユーザー m-44m-44
提出日時 2019-10-12 23:20:03
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 1,144 bytes
コンパイル時間 1,496 ms
コンパイル使用メモリ 169,476 KB
実行使用メモリ 5,876 KB
最終ジャッジ日時 2023-08-19 21:43:03
合計ジャッジ時間 5,321 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 4 ms
4,376 KB
testcase_06 AC 3 ms
4,376 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 214 ms
4,376 KB
testcase_09 AC 131 ms
4,376 KB
testcase_10 AC 202 ms
4,932 KB
testcase_11 AC 193 ms
4,380 KB
testcase_12 AC 229 ms
4,376 KB
testcase_13 AC 239 ms
4,996 KB
testcase_14 AC 236 ms
4,912 KB
testcase_15 AC 218 ms
5,876 KB
testcase_16 AC 226 ms
4,380 KB
testcase_17 AC 235 ms
4,776 KB
testcase_18 AC 171 ms
4,792 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main() {
  int n;
  cin>>n;
  long long a[n];
  for (int i=0; i<n; i++) cin>>a[i];
  vector<pair<int, int> > inc;
  int i = 0;
  while (i < n) {
    int s = i;
    while (i < n - 1 && a[i] <= a[i+1]) {
      ++i;
    }
    inc.emplace_back(s, i - s + 1);
    if (s == i) {
      ++i;
    }
  }

  vector<pair<int, int> > dec;
  i = 0;
  while (i < n) {
    int s = i;
    while (i < n - 1 && a[i] >= a[i+1]) {
      ++i;
    }
    dec.emplace_back(s, i - s + 1);
    if (s == i) {
      ++i;
    }
  }

  int q;
  cin>>q;
  for (i=0; i<q; i++) {
    int l, r;
    cin>>l>>r;
    auto it = upper_bound(inc.begin(), inc.end(), make_pair(l, INT_MAX));
    int f = 0;
    if (it != inc.begin()) {
      --it;
      int s = (*it).first;
      int len =(*it).second;
      if (r <= s + len - 1) {
        f = 1;
      }
    }

    it = upper_bound(dec.begin(), dec.end(), make_pair(l, INT_MAX));
    int g = 0;
    if (it != dec.begin()) {
      --it;
      int s = (*it).first;
      int len =(*it).second;
      if (r <= s + len - 1) {
        g = 1;
      }
    }
    cout<<f<<" "<<g<<endl;
  }
}
0