結果

問題 No.647 明太子
ユーザー mkawa2mkawa2
提出日時 2021-09-20 23:12:41
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 53 ms / 4,500 ms
コード長 2,237 bytes
コンパイル時間 190 ms
コンパイル使用メモリ 11,192 KB
実行使用メモリ 11,612 KB
最終ジャッジ日時 2023-09-15 23:21:26
合計ジャッジ時間 2,075 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
8,440 KB
testcase_01 AC 17 ms
8,504 KB
testcase_02 AC 17 ms
8,452 KB
testcase_03 AC 17 ms
8,548 KB
testcase_04 AC 16 ms
8,436 KB
testcase_05 AC 17 ms
8,588 KB
testcase_06 AC 17 ms
8,512 KB
testcase_07 AC 16 ms
8,524 KB
testcase_08 AC 17 ms
8,524 KB
testcase_09 AC 18 ms
8,628 KB
testcase_10 AC 20 ms
8,800 KB
testcase_11 AC 19 ms
8,540 KB
testcase_12 AC 20 ms
8,804 KB
testcase_13 AC 21 ms
8,856 KB
testcase_14 AC 50 ms
11,448 KB
testcase_15 AC 22 ms
9,140 KB
testcase_16 AC 19 ms
8,820 KB
testcase_17 AC 53 ms
11,504 KB
testcase_18 AC 53 ms
11,612 KB
testcase_19 AC 36 ms
11,416 KB
testcase_20 AC 33 ms
10,728 KB
testcase_21 AC 26 ms
9,596 KB
testcase_22 AC 39 ms
10,820 KB
testcase_23 AC 18 ms
8,512 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
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 = 10**16
# md = 998244353
md = 10**9+7

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

    # [0,i]の和
    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

    # [l,r)の和
    def sumlr(self, l, r):
        if l >= r: return 0
        if l == 0: return self.sum(r-1)
        return self.sum(r-1)-self.sum(l-1)

    # 数列を度数分布とみたときに、x番目がどのインデックスにあるかを返す
    # xが大きすぎるときは配列の長さnを返す
    def rank(self, x):
        idx = 0
        for lv in range((self.n-1).bit_length()-1, -1, -1):
            mid = idx+(1 << lv)
            if mid >= self.n: continue
            if self.table[mid] < x:
                x -= self.table[mid]
                idx += 1 << lv
        return idx

n = II()
ab = LLI(n)
m = II()
xyk = []
by = set()
for i in range(m):
    x, y = LI()
    xyk.append((x, y, i+1))
    by.add(y)

for a, b in ab: by.add(b)
enc = {b: i for i, b in enumerate(sorted(by))}

bit = BitSum(len(enc))
xyk.sort(key=lambda x: -x[0])
ab.sort(key=lambda x: x[0])

ans = []
mx = 0
for x, y, k in xyk:
    while ab and ab[-1][0] >= x:
        a, b = ab.pop()
        b = enc[b]
        bit.add(b, 1)
    y = enc[y]
    cur = bit.sum(y)
    if cur == mx:
        ans.append(k)
    if cur > mx:
        mx = cur
        ans = [k]

if mx == 0:
    print(0)
else:
    ans.sort()
    for a in ans: print(a)
0