結果
問題 | No.2735 Demarcation |
ユーザー | 👑 AngrySadEight |
提出日時 | 2024-04-10 16:02:31 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 592 ms / 1,500 ms |
コード長 | 2,359 bytes |
コンパイル時間 | 476 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 260,984 KB |
最終ジャッジ日時 | 2024-10-11 11:49:35 |
合計ジャッジ時間 | 11,352 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 45 ms
52,992 KB |
testcase_01 | AC | 45 ms
52,224 KB |
testcase_02 | AC | 43 ms
52,096 KB |
testcase_03 | AC | 42 ms
52,224 KB |
testcase_04 | AC | 329 ms
212,376 KB |
testcase_05 | AC | 214 ms
89,344 KB |
testcase_06 | AC | 355 ms
201,760 KB |
testcase_07 | AC | 592 ms
236,216 KB |
testcase_08 | AC | 525 ms
229,912 KB |
testcase_09 | AC | 276 ms
128,520 KB |
testcase_10 | AC | 320 ms
165,864 KB |
testcase_11 | AC | 145 ms
109,952 KB |
testcase_12 | AC | 170 ms
85,120 KB |
testcase_13 | AC | 279 ms
95,660 KB |
testcase_14 | AC | 567 ms
204,392 KB |
testcase_15 | AC | 349 ms
89,728 KB |
testcase_16 | AC | 404 ms
202,208 KB |
testcase_17 | AC | 429 ms
154,884 KB |
testcase_18 | AC | 249 ms
109,636 KB |
testcase_19 | AC | 525 ms
235,456 KB |
testcase_20 | AC | 589 ms
226,124 KB |
testcase_21 | AC | 328 ms
197,956 KB |
testcase_22 | AC | 318 ms
241,800 KB |
testcase_23 | AC | 182 ms
112,580 KB |
testcase_24 | AC | 234 ms
164,000 KB |
testcase_25 | AC | 282 ms
190,708 KB |
testcase_26 | AC | 251 ms
177,984 KB |
testcase_27 | AC | 276 ms
185,132 KB |
testcase_28 | AC | 406 ms
260,984 KB |
testcase_29 | AC | 390 ms
260,956 KB |
ソースコード
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) 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)