結果

問題 No.905 Sorted?
ユーザー 👑 はまやんはまやんはまやんはまやん
提出日時 2019-10-12 00:51:02
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,489 bytes
コンパイル時間 1,895 ms
コンパイル使用メモリ 203,796 KB
実行使用メモリ 5,888 KB
最終ジャッジ日時 2024-05-04 11:38:26
合計ジャッジ時間 3,577 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 3 ms
5,504 KB
testcase_01 AC 3 ms
5,376 KB
testcase_02 AC 3 ms
5,376 KB
testcase_03 AC 3 ms
5,504 KB
testcase_04 AC 2 ms
5,504 KB
testcase_05 AC 3 ms
5,504 KB
testcase_06 AC 3 ms
5,504 KB
testcase_07 AC 5 ms
5,632 KB
testcase_08 WA -
testcase_09 AC 50 ms
5,632 KB
testcase_10 WA -
testcase_11 AC 59 ms
5,760 KB
testcase_12 AC 76 ms
5,888 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 AC 55 ms
5,760 KB
testcase_16 AC 77 ms
5,888 KB
testcase_17 AC 73 ms
5,888 KB
testcase_18 AC 57 ms
5,760 KB
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 2 ms
5,504 KB
testcase_21 AC 3 ms
5,504 KB
testcase_22 AC 3 ms
5,504 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
#define def 1
template<class V, int NV> struct SegTree { //[l,r)
	V comp(V& l, V& r) { return l * r; };

	vector<V> val; SegTree() { val = vector<V>(NV * 2, def); }
	V get(int x, int y, int l = 0, int r = NV, int k = 1) {
		if (r <= x || y <= l)return def; if (x <= l && r <= y)return val[k];
		auto a = get(x, y, l, (l + r) / 2, k * 2);
		auto b = get(x, y, (l + r) / 2, r, k * 2 + 1);
		return comp(a, b);
	}
	void update(int i, V v) {
		i += NV; val[i] = v;
		while (i > 1) i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]);
	}
	void add(int i, V v) { update(i, val[i + NV] + v); }
	V operator[](int x) { return get(x, x + 1); }
};
/*---------------------------------------------------------------------------------------------------
            ∧_∧
      ∧_∧  (´<_` )  Welcome to My Coding Space!
     ( ´_ゝ`) /  ⌒i     @hamayanhamayan
    /   \     | |
    /   / ̄ ̄ ̄ ̄/  |
  __(__ニつ/     _/ .| .|____
     \/____/ (u ⊃
---------------------------------------------------------------------------------------------------*/














int N, A[101010];
SegTree<int, 1 << 17> stup, stdwn;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N;
	rep(i, 0, N) cin >> A[i];

	rep(i, 0, N - 1) {
		if (A[i] <= A[i + 1]) stup.update(i, 1);
		else stup.update(i, 0);

		if (A[i] >= A[i + 1]) stdwn.update(i, 1);
		else stdwn.update(i, 0);
	}

	int Q; cin >> Q;
	rep(q, 0, Q) {
		int l, r; cin >> l >> r;
		
		int f = stup.get(l, r);
		int g = stdwn.get(l, r);

		printf("%d %d\n", f, g);
	}
}





0