結果

問題 No.2710 How many more?
ユーザー k82bk82b
提出日時 2024-03-31 14:08:23
言語 D
(dmd 2.106.1)
結果
AC  
実行時間 160 ms / 2,000 ms
コード長 830 bytes
コンパイル時間 2,451 ms
コンパイル使用メモリ 201,580 KB
実行使用メモリ 6,696 KB
最終ジャッジ日時 2024-03-31 14:08:28
合計ジャッジ時間 5,441 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 130 ms
6,696 KB
testcase_03 AC 79 ms
6,696 KB
testcase_04 AC 63 ms
6,696 KB
testcase_05 AC 45 ms
6,676 KB
testcase_06 AC 52 ms
6,696 KB
testcase_07 AC 52 ms
6,676 KB
testcase_08 AC 41 ms
6,676 KB
testcase_09 AC 111 ms
6,696 KB
testcase_10 AC 64 ms
6,676 KB
testcase_11 AC 101 ms
6,676 KB
testcase_12 AC 149 ms
6,696 KB
testcase_13 AC 160 ms
6,696 KB
testcase_14 AC 157 ms
6,696 KB
testcase_15 AC 159 ms
6,696 KB
testcase_16 AC 160 ms
6,696 KB
testcase_17 AC 157 ms
6,696 KB
testcase_18 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import std, core.bitop;
bool chmin(T)(ref T SE, T MI) { if (SE > MI) { SE = MI; return true; } else { return false; } }
bool chmax(T)(ref T SE, T MI) { if (SE < MI) { SE = MI; return true; } else { return false; } }
int lowerBound(T)(T[] SE, T MI) { int lo = -1, hi = cast(int)(SE.length); while (hi - lo > 1) { int mid = lo + hi >> 1; (SE[mid] < MI ? lo : hi) = mid; } return hi; }
int upperBound(T)(T[] SE, T MI) { int lo = -1, hi = cast(int)(SE.length); while (hi - lo > 1) { int mid = lo + hi >> 1; (SE[mid] > MI ? hi : lo) = mid; } return hi; }
void main() {
	int N, Q;
	readf("%s %s\n", N, Q);
	auto A = readln.chomp.split.to!(int[]);
	auto B = A.dup;
	B.sort;
	foreach (i; 0 .. Q) {
		int x, y;
		readf("%s %s\n", x, y);
		int idx = B.lowerBound(A[--x]);
		int idy = B.upperBound(A[--y]);
		max(0, idx - idy).writeln;
	}
}
0