ABC077 C - Snuke Festival
備忘録
問題
回答
import sys import os import math import bisect ii = lambda: int(sys.stdin.buffer.readline().rstrip()) il = lambda: list(map(int, sys.stdin.buffer.readline().split())) fl = lambda: list(map(float, sys.stdin.buffer.readline().split())) iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)] iss = lambda: sys.stdin.buffer.readline().decode().rstrip() sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split())) isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)] lcm = lambda x, y: x * y / math.gcd(x, y) MOD = 10 ** 9 + 7 MAX = float('inf') def main(): if os.getenv("LOCAL"): sys.stdin = open("input.txt", "r") N = ii() A = sorted(il()) B = sorted(il()) C = sorted(il()) ret = 0 for b in B: al = bisect.bisect_right(A, b-1) cl = len(C) - bisect.bisect_left(C, b+1) ret += al*cl print(ret) if __name__ == '__main__': main()
考え方
中部のパーツリストB
の各パーツを順に、
- パーツリスト
A
のうち、中部のパーツリストより真に小さいパーツの数 - パーツリスト
C
のうち、中部のパーツリストより真に大きいパーツの数
を探索する。
中部のパーツを一意にすることで、
選択することが出来る上部のパーツ数 * 下部のパーツ数
が
ある中部のパーツに対する選択肢の数となる。
あとは上記の探索を全ての中部のパーツに対して行い、
結果の和が回答となる。
リストからパーツ数の探索にはbisect
を使用した。
bisectの挙動については下記を参照のこと。
https://qiita.com/KoyanagiHitoshi/items/32dc42d8c5ee75339e54#61-bisect