結果

問題 No.905 Sorted?
ユーザー 沙耶花沙耶花
提出日時 2019-10-11 22:09:01
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 246 ms / 2,000 ms
コード長 1,391 bytes
コンパイル時間 1,556 ms
コンパイル使用メモリ 172,032 KB
実行使用メモリ 5,080 KB
最終ジャッジ日時 2023-08-16 18:05:52
合計ジャッジ時間 5,361 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 3 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 7 ms
4,376 KB
testcase_08 AC 227 ms
4,376 KB
testcase_09 AC 136 ms
4,376 KB
testcase_10 AC 203 ms
4,800 KB
testcase_11 AC 196 ms
4,376 KB
testcase_12 AC 235 ms
4,376 KB
testcase_13 AC 246 ms
5,080 KB
testcase_14 AC 244 ms
4,928 KB
testcase_15 AC 216 ms
4,904 KB
testcase_16 AC 216 ms
4,376 KB
testcase_17 AC 223 ms
4,972 KB
testcase_18 AC 166 ms
4,944 KB
testcase_19 AC 1 ms
4,380 KB
testcase_20 AC 1 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 1000000000000000000




int main(){
	
	int N;
	cin>>N;
	
	vector<long long> A(N);
	for(int i=0;i<N;i++){
		cin>>A[i];
	}
	
	vector<pair<int,int>> f,g;
	int last = 0;
	for(int i=0;i<N;i++){
		if(i==0)continue;
		if(A[i]<A[i-1]){
			f.emplace_back(last,i-1);
			last=i;
		}
	}
	f.emplace_back(last,N-1);
	
	last=0;
	for(int i=0;i<N;i++){
		if(i==0)continue;
		if(A[i]>A[i-1]){
			g.emplace_back(last,i-1);
			last=i;
		}
	}
	g.emplace_back(last,N-1);
	/*
	for(int i=0;i<f.size();i++){
		cout<<f[i].first<<','<<f[i].second<<endl;
	}
	cout<<endl;
	for(int i=0;i<g.size();i++){
		cout<<g[i].first<<','<<g[i].second<<endl;
	}
	cout<<endl;
	*/
	int Q;
	cin>>Q;
	
	for(int i=0;i<Q;i++){
		int l,r;
		cin>>l>>r;
		
		auto it1 = lower_bound(f.begin(),f.end(),make_pair(l,0));
		auto it2 = lower_bound(f.begin(),f.end(),make_pair(r,0));

		if(it1==f.end()||(*it1).first>l)it1--;
		if(it2==f.end()||(*it2).first>r)it2--;
		
		if(it1==it2)cout<<1;
		else cout<<0;
		
		cout<<' ';
		
		it1 = lower_bound(g.begin(),g.end(),make_pair(l,0));
		it2 = lower_bound(g.begin(),g.end(),make_pair(r,0));
		
		if(it1==g.end()||(*it1).first>l)it1--;
		if(it2==g.end()||(*it2).first>r)it2--;
		
		if(it1==it2)cout<<1;
		else cout<<0;
		
		cout<<endl;
	}
		
		
	
    return 0;
}

0