結果
| 問題 | No.905 Sorted? | 
| コンテスト | |
| ユーザー |  iqueue02 | 
| 提出日時 | 2019-10-22 21:29:31 | 
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 239 ms / 2,000 ms | 
| コード長 | 681 bytes | 
| コンパイル時間 | 1,568 ms | 
| コンパイル使用メモリ | 170,264 KB | 
| 実行使用メモリ | 5,376 KB | 
| 最終ジャッジ日時 | 2024-07-04 20:27:51 | 
| 合計ジャッジ時間 | 5,733 ms | 
| ジャッジサーバーID (参考情報) | judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 23 | 
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n;
  cin  >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  vector<int> up(n,0), low(n,0);
  for (int i = 1; i < n; i++) {
    if (a[i-1] <= a[i]) up[i] = 1;
    if (a[i-1] >= a[i]) low[i] = 1;
  }
  rep(i,n-1) up[i+1] += up[i], low[i+1] += low[i];
  int q;
  cin >> q;
  while (q--) {
    int l, r;
    cin >> l >> r;
    vector<int> res(2,0);
    if (up[r] -  up[l] == r - l) res[0]++;
    if (low[r] - low[l] == r - l) res[1]++;
    cout << res[0] << " " << res[1] << endl; 
  }
  return 0;
}
            
            
            
        