結果

問題 No.878 Range High-Element Query
ユーザー e869120e869120
提出日時 2019-09-06 21:54:30
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 63 ms / 2,000 ms
コード長 837 bytes
コンパイル時間 603 ms
コンパイル使用メモリ 74,000 KB
実行使用メモリ 10,820 KB
最終ジャッジ日時 2023-09-06 23:40:28
合計ジャッジ時間 2,250 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,588 KB
testcase_01 AC 3 ms
7,588 KB
testcase_02 AC 4 ms
7,704 KB
testcase_03 AC 4 ms
7,784 KB
testcase_04 AC 4 ms
7,640 KB
testcase_05 AC 4 ms
7,684 KB
testcase_06 AC 3 ms
7,728 KB
testcase_07 AC 3 ms
7,784 KB
testcase_08 AC 4 ms
7,608 KB
testcase_09 AC 4 ms
7,808 KB
testcase_10 AC 4 ms
7,656 KB
testcase_11 AC 63 ms
10,612 KB
testcase_12 AC 43 ms
9,668 KB
testcase_13 AC 50 ms
10,000 KB
testcase_14 AC 38 ms
9,440 KB
testcase_15 AC 43 ms
9,764 KB
testcase_16 AC 61 ms
10,412 KB
testcase_17 AC 63 ms
10,820 KB
testcase_18 AC 62 ms
10,524 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable: 4996)

int N, Q, A[1 << 17], T[1 << 17], L[1 << 17], R[1 << 17], ans[1 << 17];
vector<pair<int, int>> E[1 << 17];
vector<pair<int, int>> Z;

int main() {
	scanf("%d%d", &N, &Q);
	for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
	for (int i = 1; i <= Q; i++) {
		scanf("%d%d%d", &T[i], &L[i], &R[i]);
		E[L[i]].push_back(make_pair(R[i], i));
	}
	for (int i = N; i >= 1; i--) {
		while (Z.size() >= 1 && Z[Z.size() - 1].second < A[i]) Z.pop_back();
		Z.push_back(make_pair(-i, A[i]));

		for (int j = 0; j < E[i].size(); j++) {
			int pos1 = lower_bound(Z.begin(), Z.end(), make_pair(-E[i][j].first, -1)) - Z.begin();
			ans[E[i][j].second] = Z.size() - pos1;
		}
	}
	for (int i = 1; i <= Q; i++) printf("%d\n", ans[i]);
	return 0;
}
0