結果
| 問題 |
No.905 Sorted?
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-10-12 23:20:03 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 244 ms / 2,000 ms |
| コード長 | 1,144 bytes |
| コンパイル時間 | 1,602 ms |
| コンパイル使用メモリ | 171,864 KB |
| 実行使用メモリ | 6,356 KB |
| 最終ジャッジ日時 | 2024-11-29 17:55:17 |
| 合計ジャッジ時間 | 6,044 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin>>n;
long long a[n];
for (int i=0; i<n; i++) cin>>a[i];
vector<pair<int, int> > inc;
int i = 0;
while (i < n) {
int s = i;
while (i < n - 1 && a[i] <= a[i+1]) {
++i;
}
inc.emplace_back(s, i - s + 1);
if (s == i) {
++i;
}
}
vector<pair<int, int> > dec;
i = 0;
while (i < n) {
int s = i;
while (i < n - 1 && a[i] >= a[i+1]) {
++i;
}
dec.emplace_back(s, i - s + 1);
if (s == i) {
++i;
}
}
int q;
cin>>q;
for (i=0; i<q; i++) {
int l, r;
cin>>l>>r;
auto it = upper_bound(inc.begin(), inc.end(), make_pair(l, INT_MAX));
int f = 0;
if (it != inc.begin()) {
--it;
int s = (*it).first;
int len =(*it).second;
if (r <= s + len - 1) {
f = 1;
}
}
it = upper_bound(dec.begin(), dec.end(), make_pair(l, INT_MAX));
int g = 0;
if (it != dec.begin()) {
--it;
int s = (*it).first;
int len =(*it).second;
if (r <= s + len - 1) {
g = 1;
}
}
cout<<f<<" "<<g<<endl;
}
}