結果

問題 No.905 Sorted?
ユーザー recososorecososo
提出日時 2019-11-16 17:15:58
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 224 ms / 2,000 ms
コード長 1,045 bytes
コンパイル時間 1,804 ms
コンパイル使用メモリ 171,528 KB
実行使用メモリ 4,928 KB
最終ジャッジ日時 2023-10-25 05:41:29
合計ジャッジ時間 6,609 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 2 ms
4,348 KB
testcase_02 AC 2 ms
4,348 KB
testcase_03 AC 2 ms
4,348 KB
testcase_04 AC 2 ms
4,348 KB
testcase_05 AC 4 ms
4,348 KB
testcase_06 AC 2 ms
4,348 KB
testcase_07 AC 6 ms
4,348 KB
testcase_08 AC 196 ms
4,348 KB
testcase_09 AC 122 ms
4,348 KB
testcase_10 AC 188 ms
4,928 KB
testcase_11 AC 178 ms
4,664 KB
testcase_12 AC 204 ms
4,400 KB
testcase_13 AC 217 ms
4,928 KB
testcase_14 AC 224 ms
4,928 KB
testcase_15 AC 207 ms
4,928 KB
testcase_16 AC 221 ms
4,928 KB
testcase_17 AC 218 ms
4,928 KB
testcase_18 AC 159 ms
4,928 KB
testcase_19 AC 2 ms
4,348 KB
testcase_20 AC 1 ms
4,348 KB
testcase_21 AC 2 ms
4,348 KB
testcase_22 AC 2 ms
4,348 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int nmax=100005;
int par[nmax],par2[nmax];
void init(int x){
  for(int i=0;i<x;i++){
    par[i]=i;
    par2[i]=i;
  }
}
int root(int x){
  if(par[x]==x){
    return x;
  }
  return par[x]=root(par[x]);
}
int root2(int x){
  if(par2[x]==x){
    return x;
  }
  return par2[x]=root2(par2[x]);
}
void unite(int x,int y){
  x=root(x);
  y=root(y);
  if(x==y){
    return;
  }
  par[y]=x;
}
void unite2(int x,int y){
  x=root2(x);
  y=root2(y);
  if(x==y){
    return;
  }
  par2[y]=x;
}
int main(){
  int n;cin >> n;
  init(n);
  vector<long long> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(i){
      if(a[i-1]<=a[i]){
        unite(i-1,i);
      }
      if(a[i-1]>=a[i]){
        unite2(i-1,i);
      }
    }
  }
  int q;cin >> q;
  for(int i=0;i<q;i++){
    int l,r;cin >> l >> r;
    if(root(l)==root(r)){
      cout << 1;
    }
    else{
      cout << 0;
    }
    cout << " ";
    if(root2(l)==root2(r)){
      cout << 1 << endl;
    }
    else{
      cout << 0 << endl;
    }
  }
}
0