From 16d353aaac8a72fe95f5623b7dccec88185da3cc Mon Sep 17 00:00:00 2001 From: RauPro <00012119@uca.edu.sv> Date: Fri, 3 May 2024 16:42:04 -0600 Subject: [PATCH] Add 12571 --- .../12571 - Brother & Sisters!.py | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 ICPC Preparation/Data Structure/ Bit Manipulation/12571 - Brother & Sisters!.py diff --git a/ICPC Preparation/Data Structure/ Bit Manipulation/12571 - Brother & Sisters!.py b/ICPC Preparation/Data Structure/ Bit Manipulation/12571 - Brother & Sisters!.py new file mode 100644 index 0000000..357ebdb --- /dev/null +++ b/ICPC Preparation/Data Structure/ Bit Manipulation/12571 - Brother & Sisters!.py @@ -0,0 +1,92 @@ +import os +import sys +from collections import * +from heapq import * +from math import gcd, floor, ceil, sqrt +from copy import deepcopy +from itertools import permutations, combinations, product +from bisect import bisect_left, bisect_right +from functools import lru_cache, reduce +import operator + +# Para mejorar el rendimiento de la entrada/salida +input = lambda: sys.stdin.readline().strip() +flush = lambda: sys.stdout.flush() +print = lambda *args, **kwargs: sys.stdout.write(' '.join(map(str, args)) + kwargs.get("end", "\n")) + +# Optimización de la recursión para Python +sys.setrecursionlimit(100000) + + +# Funciones para lectura de múltiples tipos de datos +def ints(): return map(int, input().split()) +def strs(): return input().split() +def chars(): return list(input().strip()) +def mat(n): return [list(ints()) for _ in range(n)] # Matriz de n x m donde m es el número de enteros en una línea + + +# Constantes útiles +INF = float('inf') +MOD = 1000000007 # Modulo por defecto, cambiar si se necesita otro + + +# Algunas funciones útiles +def add(x, y, mod=MOD): return (x + y) % mod +def sub(x, y, mod=MOD): return (x - y) % mod +def mul(x, y, mod=MOD): return (x * y) % mod + + +# Fast power - a^b % mod +def powmod(a, b, mod=MOD): + res = 1 + a = a % mod + while b > 0: + if b % 2: + res = mul(res, a, mod) + a = mul(a, a, mod) + b //= 2 + return res + + +# Inverso multiplicativo de a modulo m (cuando m es primo) +def invmod(a, mod=MOD): return powmod(a, mod - 2, mod) + + +# GCD y LCM +def lcm(a, b): return a * b // gcd(a, b) + + +# Factorial con memoización +@lru_cache(maxsize=None) +def factorial(n): return n * factorial(n - 1) if n else 1 + + +# Combinaciones con memoización (nCr) +@lru_cache(maxsize=None) +def comb(n, r): + if r == 0 or r == n: return 1 + return comb(n - 1, r - 1) + comb(n - 1, r) + + +def main(): + t = int(input()) + for _ in range(t): + n, q = ints() + x = list(ints()) + solve(n,q, x) + + +def solve(n,q ,x ): + mapper = defaultdict(lambda: 0) + arr = [] + for it in x: + for i in range(1, 230): + if i & it > mapper[i]: + mapper[i] = i & it + for i in range(q): + a = int(input()) + arr.append(str(mapper[a])) + print("\n".join(arr)) + +if __name__ == "__main__": + main()