結果
| 問題 |
No.905 Sorted?
|
| コンテスト | |
| ユーザー |
tnakao0123
|
| 提出日時 | 2019-10-12 03:39:30 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,420 bytes |
| コンパイル時間 | 637 ms |
| コンパイル使用メモリ | 88,780 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-11-26 09:57:11 |
| 合計ジャッジ時間 | 3,275 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 19 WA * 4 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:93:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
93 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
main.cpp:94:36: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
94 | for (int i = 0; i < n; i++) scanf("%d", as + i);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:103:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
103 | scanf("%d", &qn);
| ~~~~~^~~~~~~~~~~
main.cpp:107:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
107 | scanf("%d%d", &l, &r);
| ~~~~~^~~~~~~~~~~~~~~~
ソースコード
/* -*- coding: utf-8 -*-
*
* 905.cc: No.905 Sorted? - yukicoder
*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
using namespace std;
/* constant */
const int MAX_N = 100000;
const int MAX_E2 = 1 << 18; // = 262144
const int INF = 1 << 30;
/* typedef */
typedef pair<int,int> pii;
template <typename T, const int MAX_E2>
struct SegTreeMinMax {
int n, e2;
T mins[MAX_E2], maxs[MAX_E2], mindef, maxdef;
SegTreeMinMax() {}
void init(int _n, T _mindef, T _maxdef) {
n = _n; mindef = _mindef; maxdef = _maxdef;
for (e2 = 1; e2 < n; e2 <<= 1);
fill(mins, mins + MAX_E2, mindef);
fill(maxs, maxs + MAX_E2, maxdef);
}
T &get_min(int i) { return mins[e2 - 1 + i]; }
T &get_max(int i) { return maxs[e2 - 1 + i]; }
void set(int i, T v) { get_min(i) = get_max(i) = v; }
void set_all() {
for (int j = e2 - 2; j >= 0; j--) {
int j0 = j * 2 + 1, j1 = j0 + 1;
mins[j] = min<T>(mins[j0], mins[j1]);
maxs[j] = max<T>(maxs[j0], maxs[j1]);
}
}
typedef pair<T,T> ptt;
ptt get_range(int r0, int r1, int k, int i0, int i1) {
if (r1 <= i0 || i1 <= r0) return ptt(mindef, maxdef);
if (r0 <= i0 && i1 <= r1) return ptt(mins[k], maxs[k]);
int im = (i0 + i1) / 2;
ptt v0 = get_range(r0, r1, k * 2 + 1, i0, im);
ptt v1 = get_range(r0, r1, k * 2 + 2, im, i1);
return ptt(min<T>(v0.first, v1.first), max<T>(v0.second, v1.second));
}
ptt get_range(int r0, int r1) { return get_range(r0, r1, 0, 0, e2); }
};
/* global variables */
int as[MAX_N];
SegTreeMinMax<int,MAX_E2> st;
/* subroutines */
inline int cmpi(int a, int b) {
if (a < b) return -1;
if (a > b) return 1;
return 0;
}
/* main */
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", as + i);
st.init(n - 1, INF, -INF);
for (int i = 0; i + 1 < n; i++)
st.set(i, cmpi(as[i + 1], as[i]));
st.set_all();
int qn;
scanf("%d", &qn);
while (qn--) {
int l, r;
scanf("%d%d", &l, &r);
if (l == r) puts("1 1");
else {
pii v = st.get_range(l, r);
printf("%d %d\n", (v.first >= 0) ? 1 : 0, (v.second <= 0) ? 1 : 0);
}
}
return 0;
}
tnakao0123