結果
問題 | No.743 Segments on a Polygon |
ユーザー |
![]() |
提出日時 | 2020-12-04 23:28:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 273 ms / 2,000 ms |
コード長 | 1,346 bytes |
コンパイル時間 | 319 ms |
コンパイル使用メモリ | 82,048 KB |
実行使用メモリ | 86,528 KB |
最終ジャッジ日時 | 2024-09-15 09:09:43 |
合計ジャッジ時間 | 4,628 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 10 |
ソースコード
import sysinput = sys.stdin.buffer.readlinesys.setrecursionlimit(10 ** 7)class fenwick_tree(object):def __init__(self, n):self.n = nself.log = n.bit_length()self.data = [0] * ndef __sum(self, r):s = 0while r > 0:s += self.data[r - 1]r -= r & -rreturn sdef add(self, p, x):""" a[p] += xを行う"""p += 1while p <= self.n:self.data[p - 1] += xp += p & -pdef sum(self, l, r):"""a[l] + a[l+1] + .. + a[r-1]を返す"""return self.__sum(r) - self.__sum(l)def lower_bound(self, x):"""a[0] + a[1] + .. a[i] >= x となる最小のiを返す"""if x <= 0:return -1i = 0k = 1 << self.logwhile k:if i + k <= self.n and self.data[i + k - 1] < x:x -= self.data[i + k - 1]i += kk >>= 1return iN, M = map(int, input().split())AB = []for _ in range(N):a, b = map(int, input().split())if a > b:a, b = b, aAB.append((a, b))AB.sort(key=lambda x: x[1])ans = 0left = fenwick_tree(M)right = fenwick_tree(M)for a, b in AB:ans += left.sum(0, a) - right.sum(0, a + 1)left.add(a, 1)right.add(b, 1)print(ans)