import sys
import os
# import time
from bisect import bisect_left, bisect_right
# import functools
from math import ceil, floor, gcd, factorial, sqrt, log2, log
import random
# import re
from collections import Counter, defaultdict, deque
# from copy import deepcopy
from functools import cmp_to_key, lru_cache, reduce
from heapq import heapify, heappop, heappush, heappushpop, nlargest, nsmallest
from itertools import accumulate, combinations, permutations
from operator import add, iand, ior, itemgetter, mul, xor
from string import ascii_lowercase, ascii_uppercase
from typing import *
input = lambda: sys.stdin.readline().rstrip("\r\n")
# --------------------
# 手写栈模板
# 克服py栈太浅的问题
from types import GeneratorType
def bootstrap(f, stack=[]):
def wrappedfunc(*args, **kwargs):
if stack:
return f(*args, **kwargs)
else:
to = f(*args, **kwargs)
while True:
if type(to) is GeneratorType:
stack.append(to)
to = next(to)
else:
stack.pop()
if not stack:
break
to = stack[-1].send(to)
return to
return wrappedfunc
# --------------------
def I():
return input()
def II():
return int(input())
def MII():
return map(int, input().split())
def LI():
return list(input().split())
def LII():
return list(map(int, input().split()))
def GMI():
return map(lambda x: int(x) - 1, input().split())
def LGMI():
return list(map(lambda x: int(x) - 1, input().split()))
def isPrimeMR(n):
if n <= 1:
return 0
if n == 2 or n == 7 or n == 61:
return 1
d = n - 1
d = d // (d & -d)
L = [2, 7, 61] if n < 1 << 32 else [2, 3, 5, 7, 11, 13, 17] if n < 1 << 48 else [2, 3, 5, 7, 11, 13, 17, 19, 23, 29,
31, 37]
for a in L:
t = d
y = pow(a, t, n)
if y == 1: continue
while y != n - 1:
y = y * y % n
if y == 1 or t == n - 1: return 0
t <<= 1
return 1
def findFactorRho(n):
m = 1 << n.bit_length() // 8
for c in range(1, 99):
f = lambda x: (x * x + c) % n
y, r, q, g = 2, 1, 1, 1
while g == 1:
x = y
for i in range(r):
y = f(y)
k = 0
while k < r and g == 1:
ys = y
for i in range(min(m, r - k)):
y = f(y)
q = q * abs(x - y) % n
g = gcd(q, n)
k += m
r <<= 1
if g == n:
g = 1
while g == 1:
ys = f(ys)
g = gcd(abs(x - ys), n)
if g < n:
if isPrimeMR(g):
return g
elif isPrimeMR(n // g):
return n // g
return findFactorRho(g)
def primeFactor(n):
i = 2
ret = {}
rhoFlg = 0
while i * i <= n:
k = 0
while n % i == 0:
n //= i
k += 1
if k: ret[i] = k
i += i % 2 + (3 if i % 3 == 1 else 1)
if i == 101 and n >= 2 ** 20:
while n > 1:
if isPrimeMR(n):
ret[n], n = 1, 1
else:
rhoFlg = 1
j = findFactorRho(n)
k = 0
while n % j == 0:
n //= j
k += 1
ret[j] = k
if n > 1: ret[n] = 1
if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
return ret
def divisors(N):
pf = primeFactor(N)
ret = [1]
for p in pf:
ret_prev = ret
ret = []
for i in range(pf[p] + 1):
for r in ret_prev:
ret.append(r * (p ** i))
return sorted(ret)
def iii():
num = 0
neg = False
while True:
c = sys.stdin.read(1)
if c == '-':
neg = True
continue
elif c < '0' or c > '9':
continue
while True:
num = 10 * num + ord(c) - ord('0')
c = sys.stdin.read(1)
if c < '0' or c > '9':
break
return -num if neg else num
# sys.setrecursionlimit(int(1e5 + 10))根据需要调整递归深度
dx, dy = [0, 1, 0, -1, 1, -1, 1, -1], [1, 0, -1, 0, -1, -1, 1, 1]
inf = float('inf')
# RANDOM = random.randint(int(1e9 + 7), int(2e9 + 7)) # 防止卡哈希
mod = int(1e9 + 7)
# mod = 998244353
def solve():
n = II()
g1 = []
f1 = f2 = 0
d1 = defaultdict(list)
d2 = defaultdict(list)
for _ in range(n):
s, x, y = LI()
if s == "lzr010506":
f1 = 1
d1[s] = [int(x), int(y)]
m = II()
for _ in range(m):
s, x, y = LI()
if s == "lzr010506":
f2 = 1
d2[s] = [int(x), int(y)]
res = inf
if f1:
t = []
for s in d1.keys():
if s == "lzr010506":
t.append((d1[s] + [s]))
continue
if not d2[s]:
t.append((d1[s] + [s]))
# print(t)
t.sort(key=lambda x: (-x[0], x[1]))
for i in range(len(t)):
if t[i][2] == "lzr010506":
res = min(res, i + 1)
if f2:
t = []
for s in d2.keys():
if s == "lzr010506":
t.append((d2[s] + [s]))
continue
if not d1[s]:
t.append((d2[s] + [s]))
t.sort(key=lambda x: (-x[0], x[1]))
for i in range(len(t)):
if t[i][2] == "lzr010506":
res = min(res, i + 1)
print(res)
return
if __name__ == '__main__':
# 1多组数据,0单组数据
t = 0
if t:
t = II()
for _ in range(t):
solve()
else:
solve()
以上内容就是模板了,我得去学习一下怎么使用,然后明天解释一下这个模板,然后就正式投入使用了。