結果
問題 | No.1031 いたずら好きなお姉ちゃん |
ユーザー | maspy |
提出日時 | 2020-04-17 23:09:22 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 664 ms / 3,500 ms |
コード長 | 2,100 bytes |
コンパイル時間 | 169 ms |
コンパイル使用メモリ | 82,072 KB |
実行使用メモリ | 116,032 KB |
最終ジャッジ日時 | 2024-10-03 15:07:51 |
合計ジャッジ時間 | 20,024 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
53,984 KB |
testcase_01 | AC | 35 ms
53,172 KB |
testcase_02 | AC | 34 ms
53,660 KB |
testcase_03 | AC | 103 ms
77,776 KB |
testcase_04 | AC | 106 ms
77,308 KB |
testcase_05 | AC | 105 ms
78,056 KB |
testcase_06 | AC | 104 ms
77,808 KB |
testcase_07 | AC | 102 ms
77,924 KB |
testcase_08 | AC | 100 ms
77,908 KB |
testcase_09 | AC | 105 ms
78,344 KB |
testcase_10 | AC | 101 ms
77,308 KB |
testcase_11 | AC | 286 ms
107,368 KB |
testcase_12 | AC | 288 ms
104,736 KB |
testcase_13 | AC | 329 ms
113,240 KB |
testcase_14 | AC | 304 ms
108,344 KB |
testcase_15 | AC | 319 ms
110,672 KB |
testcase_16 | AC | 282 ms
106,924 KB |
testcase_17 | AC | 317 ms
111,656 KB |
testcase_18 | AC | 332 ms
110,524 KB |
testcase_19 | AC | 350 ms
112,172 KB |
testcase_20 | AC | 326 ms
113,520 KB |
testcase_21 | AC | 321 ms
111,152 KB |
testcase_22 | AC | 300 ms
106,856 KB |
testcase_23 | AC | 298 ms
107,564 KB |
testcase_24 | AC | 342 ms
111,516 KB |
testcase_25 | AC | 327 ms
113,232 KB |
testcase_26 | AC | 310 ms
110,620 KB |
testcase_27 | AC | 308 ms
109,496 KB |
testcase_28 | AC | 331 ms
113,640 KB |
testcase_29 | AC | 345 ms
113,868 KB |
testcase_30 | AC | 334 ms
111,352 KB |
testcase_31 | AC | 350 ms
112,900 KB |
testcase_32 | AC | 361 ms
114,028 KB |
testcase_33 | AC | 355 ms
112,912 KB |
testcase_34 | AC | 304 ms
116,032 KB |
testcase_35 | AC | 500 ms
113,972 KB |
testcase_36 | AC | 431 ms
114,008 KB |
testcase_37 | AC | 470 ms
114,276 KB |
testcase_38 | AC | 602 ms
111,132 KB |
testcase_39 | AC | 512 ms
112,912 KB |
testcase_40 | AC | 549 ms
113,392 KB |
testcase_41 | AC | 532 ms
111,672 KB |
testcase_42 | AC | 551 ms
113,520 KB |
testcase_43 | AC | 526 ms
113,228 KB |
testcase_44 | AC | 506 ms
112,908 KB |
testcase_45 | AC | 483 ms
111,328 KB |
testcase_46 | AC | 651 ms
113,104 KB |
testcase_47 | AC | 482 ms
113,692 KB |
testcase_48 | AC | 496 ms
115,076 KB |
testcase_49 | AC | 617 ms
113,612 KB |
testcase_50 | AC | 664 ms
113,368 KB |
testcase_51 | AC | 298 ms
114,688 KB |
testcase_52 | AC | 277 ms
115,408 KB |
testcase_53 | AC | 272 ms
115,444 KB |
testcase_54 | AC | 34 ms
53,636 KB |
testcase_55 | AC | 32 ms
53,028 KB |
ソースコード
#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines class SegTree: """ segment tree with point modification and range product access. """ data_unit = 1 << 30 data_f = min def __init__(self, N): self.N = N self.data = [self.data_unit] * (N + N) def build(self, raw_data): data = self.data f = self.data_f N = self.N data[N:] = raw_data[:] for i in range(N - 1, 0, -1): data[i] = f(data[i << 1], data[i << 1 | 1]) def set_val(self, i, x): data = self.data f = self.data_f i += self.N data[i] = x while i > 1: i >>= 1 data[i] = f(data[i << 1], data[i << 1 | 1]) def fold(self, L, R): """ compute for [L, R) """ vL = vR = self.data_unit data = self.data f = self.data_f L += self.N R += self.N while L < R: if L & 1: vL = f(vL, data[L]) L += 1 if R & 1: R -= 1 vR = f(data[R], vR) L >>= 1 R >>= 1 return f(vL, vR) N, *A = map(int, read().split()) def solve(A): # 小・大の順 A = [0] + A + [N + 1] stack = [N + 1] seg = SegTree(len(A)) seg.build(A) next_high = [N + 1] * (N + 2) for n in range(N, -1, -1): x = A[n] while x > A[stack[-1]]: stack.pop() next_high[n] = stack[-1] stack.append(n) dp = [None] * 17 dp[0] = next_high for n in range(1, 17): prev = dp[n - 1] dp[n] = [prev[prev[i]] for i in range(N + 2)] def bin_search(i): a = A[i] R = len(A) - 2 ret = 0 for n in range(16, -1, -1): m = dp[n][i] if m <= R and seg.fold(i + 1, m) >= a: ret += 1 << n i = m return ret return sum(bin_search(i) for i in range(1, N + 1)) print(solve(A) + solve(A[::-1]))