結果
問題 | No.743 Segments on a Polygon |
ユーザー | 双六 |
提出日時 | 2020-07-24 18:47:03 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 760 ms / 2,000 ms |
コード長 | 1,259 bytes |
コンパイル時間 | 596 ms |
コンパイル使用メモリ | 86,824 KB |
実行使用メモリ | 100,860 KB |
最終ジャッジ日時 | 2023-09-07 22:37:12 |
合計ジャッジ時間 | 9,500 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 735 ms
100,240 KB |
testcase_01 | AC | 754 ms
100,856 KB |
testcase_02 | AC | 743 ms
100,796 KB |
testcase_03 | AC | 738 ms
100,688 KB |
testcase_04 | AC | 760 ms
100,860 KB |
testcase_05 | AC | 734 ms
100,376 KB |
testcase_06 | AC | 731 ms
100,380 KB |
testcase_07 | AC | 719 ms
100,444 KB |
testcase_08 | AC | 732 ms
100,528 KB |
testcase_09 | AC | 357 ms
100,140 KB |
ソースコード
import sys; input = sys.stdin.buffer.readline sys.setrecursionlimit(10**7) from collections import defaultdict con = 10 ** 9 + 7; INF = float("inf") def getlist(): return list(map(int, input().split())) class SegmentTree(object): #N:処理する区間の長さ def __init__(self, N): self.N0 = 2 ** (N - 1).bit_length() self.data = [0] * (2 * self.N0) #k番目の値をxに更新 def update(self, k, x): k += self.N0 - 1 self.data[k] = x while k > 0: k = (k - 1) // 2 self.data[k] = self.data[2 * k + 1] + self.data[2 * k + 2] #区間[l, r]の和 def query(self, l, r): L = l + self.N0; R = r + self.N0 + 1 m = 0 while L < R: if R & 1: R -= 1 m = m + self.data[R - 1] if L & 1: m = m + self.data[L - 1] L += 1 L >>= 1; R >>= 1 return m #処理内容 def main(): N, M = getlist() SegL = SegmentTree(M) SegR = SegmentTree(M) L = [] for i in range(N): l, r = list(sorted(getlist())) L.append([l, r]) SegL.update(l, 1) SegR.update(r, 1) L.sort() ans = 0 for l, r in L: val = abs(SegL.query(l, r) - SegR.query(l, r)) ans += val SegL.update(l, 0) SegR.update(r, 0) SegL.update(r, 1) SegR.update(l, 1) # print(ans) print(int(ans // 2)) if __name__ == '__main__': main()