結果
問題 | No.728 ギブ and テイク |
ユーザー | mkawa2 |
提出日時 | 2022-01-29 18:36:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,445 ms / 3,000 ms |
コード長 | 1,582 bytes |
コンパイル時間 | 1,103 ms |
コンパイル使用メモリ | 87,168 KB |
実行使用メモリ | 278,312 KB |
最終ジャッジ日時 | 2023-08-30 18:22:10 |
合計ジャッジ時間 | 16,977 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 78 ms
71,100 KB |
testcase_01 | AC | 80 ms
71,352 KB |
testcase_02 | AC | 79 ms
71,204 KB |
testcase_03 | AC | 80 ms
71,108 KB |
testcase_04 | AC | 81 ms
71,108 KB |
testcase_05 | AC | 80 ms
71,320 KB |
testcase_06 | AC | 80 ms
71,316 KB |
testcase_07 | AC | 80 ms
71,212 KB |
testcase_08 | AC | 93 ms
75,288 KB |
testcase_09 | AC | 78 ms
71,128 KB |
testcase_10 | AC | 79 ms
71,108 KB |
testcase_11 | AC | 90 ms
76,172 KB |
testcase_12 | AC | 91 ms
75,892 KB |
testcase_13 | AC | 237 ms
90,676 KB |
testcase_14 | AC | 292 ms
105,344 KB |
testcase_15 | AC | 240 ms
87,640 KB |
testcase_16 | AC | 273 ms
102,784 KB |
testcase_17 | AC | 244 ms
99,568 KB |
testcase_18 | AC | 1,075 ms
278,312 KB |
testcase_19 | AC | 1,164 ms
273,300 KB |
testcase_20 | AC | 1,328 ms
272,748 KB |
testcase_21 | AC | 1,177 ms
257,852 KB |
testcase_22 | AC | 536 ms
151,464 KB |
testcase_23 | AC | 407 ms
135,012 KB |
testcase_24 | AC | 889 ms
259,180 KB |
testcase_25 | AC | 875 ms
257,372 KB |
testcase_26 | AC | 512 ms
137,928 KB |
testcase_27 | AC | 1,445 ms
273,016 KB |
testcase_28 | AC | 882 ms
272,368 KB |
testcase_29 | AC | 78 ms
71,340 KB |
testcase_30 | AC | 75 ms
71,260 KB |
testcase_31 | AC | 78 ms
71,072 KB |
testcase_32 | AC | 78 ms
71,100 KB |
ソースコード
import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() # dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] # inf = (1<<63)-1 inf = (1 << 32)-1 # md = 10**9+7 md = 998244353 class BitSum: def __init__(self, n): self.n = n+1 self.table = [0]*self.n def add(self, i, x): i += 1 while i < self.n: self.table[i] += x i += i & -i def sum(self, i): i += 1 res = 0 while i > 0: res += self.table[i] i -= i & -i return res from heapq import * n = II() aa = LI() lr = LLI(n) st = set() alr = [] for a, (l, r) in zip(aa, lr): alr.append((a, l, r)) st.add(a) st.add(a+r) enc = {a: i for i, a in enumerate(sorted(st))} alr.sort(key=lambda x: -x[0]) hp = [] bit = BitSum(len(enc)) ans = 0 for a, l, r in alr: while hp and -hp[0][0] > a: _, i = heappop(hp) bit.add(i, -1) i = enc[a+r] ans += bit.sum(i) i = enc[a] bit.add(i, 1) heappush(hp, (-a+l, i)) print(ans)