結果
| 問題 |
No.905 Sorted?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-11-16 17:15:58 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 229 ms / 2,000 ms |
| コード長 | 1,045 bytes |
| コンパイル時間 | 1,957 ms |
| コンパイル使用メモリ | 170,520 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-25 01:05:28 |
| 合計ジャッジ時間 | 6,197 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#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;
}
}
}