結果

問題 No.905 Sorted?
ユーザー phocomphocom
提出日時 2019-10-11 21:34:37
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 231 ms / 2,000 ms
コード長 2,386 bytes
コンパイル時間 854 ms
コンパイル使用メモリ 95,744 KB
実行使用メモリ 4,740 KB
最終ジャッジ日時 2023-08-16 17:17:31
合計ジャッジ時間 4,434 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 4 ms
4,380 KB
testcase_06 AC 3 ms
4,380 KB
testcase_07 AC 7 ms
4,380 KB
testcase_08 AC 197 ms
4,380 KB
testcase_09 AC 122 ms
4,376 KB
testcase_10 AC 192 ms
4,720 KB
testcase_11 AC 182 ms
4,380 KB
testcase_12 AC 214 ms
4,376 KB
testcase_13 AC 220 ms
4,740 KB
testcase_14 AC 225 ms
4,736 KB
testcase_15 AC 208 ms
4,520 KB
testcase_16 AC 224 ms
4,712 KB
testcase_17 AC 231 ms
4,544 KB
testcase_18 AC 168 ms
4,636 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 1 ms
4,380 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define MAX (1 << 29)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) { return s; }

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x);
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x);
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i) cin >> vec[i];
}

int main() {
  int N;
  cin >> N;
  vector<ll> A(N);
  FOR(i, N) cin >> A[i];
  int Q;
  cin >> Q;
  vector<int> C1(N), C2(N);
  FOR(i, N - 1) {
    if (A[i] > A[i + 1])
      C1[i + 1] = C1[i] + 1;
    else
      C1[i + 1] = C1[i];
    if (A[i] < A[i + 1])
      C2[i + 1] = C2[i] + 1;
    else
      C2[i + 1] = C2[i];
  }
  FOR(i, Q) {
    int l, r;
    cin >> l >> r;
    if (C1[l] == C1[r])
      cout << 1;
    else
      cout << 0;
    cout << " ";
    if (C2[l] == C2[r])
      cout << 1;
    else
      cout << 0;
    cout << endl;
  }
  return 0;
}
0