結果

問題 No.743 Segments on a Polygon
ユーザー stngstng
提出日時 2022-05-28 18:04:09
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 471 ms / 2,000 ms
コード長 670 bytes
コンパイル時間 177 ms
コンパイル使用メモリ 81,772 KB
実行使用メモリ 87,344 KB
最終ジャッジ日時 2023-10-20 23:28:47
合計ジャッジ時間 6,920 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 456 ms
87,296 KB
testcase_01 AC 453 ms
87,344 KB
testcase_02 AC 451 ms
87,196 KB
testcase_03 AC 471 ms
87,192 KB
testcase_04 AC 442 ms
87,332 KB
testcase_05 AC 439 ms
87,292 KB
testcase_06 AC 443 ms
87,196 KB
testcase_07 AC 435 ms
87,340 KB
testcase_08 AC 438 ms
87,200 KB
testcase_09 AC 191 ms
86,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
 
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
 
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i

n,m = map(int,input().split())

ab = [0]*n

for i in range(n):
    a,b = map(int,input().split())
    if a < b:
        ab[i] = [b,a]
    else:
        ab[i] = [a,b]

ab.sort(reverse=True)
#print(ab)

ans = 0

bit = Bit(m+1)
for i in range(n):
    bit.add(ab[i][1]+1,1)
    ans += (bit.sum(ab[i][0]+1)-bit.sum(ab[i][1]+1))

print(ans)
0