結果
問題 | No.2735 Demarcation |
ユーザー | 👑 AngrySadEight |
提出日時 | 2024-04-10 17:22:56 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 601 ms / 1,500 ms |
コード長 | 2,330 bytes |
コンパイル時間 | 402 ms |
コンパイル使用メモリ | 81,792 KB |
実行使用メモリ | 260,952 KB |
最終ジャッジ日時 | 2024-10-11 11:51:38 |
合計ジャッジ時間 | 12,161 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
52,480 KB |
testcase_01 | AC | 43 ms
52,352 KB |
testcase_02 | AC | 44 ms
52,480 KB |
testcase_03 | AC | 44 ms
52,224 KB |
testcase_04 | AC | 318 ms
211,872 KB |
testcase_05 | AC | 219 ms
89,352 KB |
testcase_06 | AC | 343 ms
202,024 KB |
testcase_07 | AC | 592 ms
235,660 KB |
testcase_08 | AC | 541 ms
229,920 KB |
testcase_09 | AC | 287 ms
128,392 KB |
testcase_10 | AC | 316 ms
165,248 KB |
testcase_11 | AC | 152 ms
109,760 KB |
testcase_12 | AC | 178 ms
84,864 KB |
testcase_13 | AC | 284 ms
95,744 KB |
testcase_14 | AC | 564 ms
204,716 KB |
testcase_15 | AC | 354 ms
89,216 KB |
testcase_16 | AC | 370 ms
202,264 KB |
testcase_17 | AC | 448 ms
154,408 KB |
testcase_18 | AC | 252 ms
109,184 KB |
testcase_19 | AC | 498 ms
235,740 KB |
testcase_20 | AC | 601 ms
226,372 KB |
testcase_21 | AC | 324 ms
197,764 KB |
testcase_22 | AC | 307 ms
242,428 KB |
testcase_23 | AC | 159 ms
112,372 KB |
testcase_24 | AC | 215 ms
164,208 KB |
testcase_25 | AC | 309 ms
189,836 KB |
testcase_26 | AC | 270 ms
177,912 KB |
testcase_27 | AC | 299 ms
185,660 KB |
testcase_28 | AC | 434 ms
260,952 KB |
testcase_29 | AC | 373 ms
260,448 KB |
ソースコード
N = int(input()) X = list(map(int, input().split())) 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 + 1)] 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) 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) 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 for j in range(len_vec): kinds[vec[j]] = 0 if ok >= len_vec: print(-1) else: print(ok)