結果
問題 | No.2735 Demarcation |
ユーザー | 👑 AngrySadEight |
提出日時 | 2024-04-03 17:46:28 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,458 bytes |
コンパイル時間 | 273 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 261,160 KB |
最終ジャッジ日時 | 2024-10-11 11:43:55 |
合計ジャッジ時間 | 11,740 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 43 ms
52,736 KB |
testcase_01 | AC | 43 ms
52,352 KB |
testcase_02 | AC | 43 ms
52,480 KB |
testcase_03 | AC | 42 ms
52,352 KB |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | WA | - |
testcase_15 | WA | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 349 ms
197,668 KB |
testcase_22 | AC | 336 ms
241,952 KB |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
ソースコード
N = int(input()) X = list(map(int, input().split())) for i in range(N): X[i] -= 1 diff_sum = [0 for _ in range(N)] for i in range(N - 1): if X[i] != X[i + 1]: diff_sum[i + 1] = diff_sum[i] else: diff_sum[i + 1] = diff_sum[i] + 1 kinds = [0 for _ in range(N)] Q = int(input()) for _ in range(Q): l, r, S = map(int, input().split()) l -= 1 r -= 1 if r - l >= 90: diffs = diff_sum[r] - diff_sum[l] if diffs >= 60: print(0) else: if S >= (1 << diffs): print(1 << diffs) else: print(0) else: vec = [0 for _ in range(r - l + 1)] for j in range(l, r + 1): vec[j - l] = X[j] len_vec = len(vec) ans = [0 for _ in range(len_vec + 2)] ok = 0 ng = len_vec + 2 while ng - ok > 1: mid = (ok + ng) // 2 prev_idx = [-1 for _ in range(len_vec + 1)] now_kind = 0 left = 0 right = 0 while True: if now_kind <= mid: if right == len_vec: prev_idx[right] = left break else: prev_idx[right] = left if kinds[vec[right]] == 0: now_kind += 1 kinds[vec[right]] += 1 right += 1 else: kinds[vec[left]] -= 1 if kinds[vec[left]] == 0: now_kind -= 1 left += 1 dp = [0 for _ in range(len_vec + 1)] dp_sum = [0 for _ in range(len_vec + 1)] dp[0] = 1 dp_sum[0] = 1 infin = False for j in range(1, len_vec + 1): sum_val = dp_sum[j - 1] if prev_idx[j] > 0: sum_val -= dp_sum[prev_idx[j] - 1] if sum_val > S: infin = True break dp[j] = sum_val dp_sum[j] = dp[j] + dp_sum[j - 1] if infin: ng = mid else: ok = mid ans[mid] = dp[len_vec] for j in range(len_vec): kinds[vec[j]] = 0 if ok >= len_vec: print(-1) else: print(ans[ok])