摘要: from math import sqrt from collections import Counter # ①试除法求约数 x = int(input()) ans = [] for i in range(1,int(sqrt(x)) + 1): if x % i == 0: ans.appen 阅读全文
posted @ 2024-04-02 22:07 gebeng 阅读(1) 评论(0) 推荐(0) 编辑
摘要: # 求 1 ~ n 所有的质数【线性筛,也叫欧拉筛,时间复杂度为O(n),埃氏筛为O(nlogn)】 n = int(input()) prime = [] vis = [0] * (n + 1) # 合数 = 最小质因子 × k (最大且不等于它自身的因数) # 每个合数必有一个【最小素因子】或【 阅读全文
posted @ 2024-04-02 21:18 gebeng 阅读(5) 评论(0) 推荐(0) 编辑
摘要: epsilon = pow(10,-10) g = [] for _ in range(int(input())): g.append([*map(float,input().split())]) n,m = len(g),len(g[0]) row = 0 for col in range(n): 阅读全文
posted @ 2024-04-02 20:01 gebeng 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 灵茶之二分02 题目链接 https://codeforces.com/problemset/problem/1538/C 题目大意 输入 T(≤104) 表示 T 组数据。所有数据的 n 之和 ≤2e5。 每组数据输入 n(1≤n≤2e5) L R(1≤L≤R≤1e9) 和长为 n 的数组 a(1 阅读全文
posted @ 2024-04-01 22:27 gebeng 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 一个动态维护前缀和的工具 class BIT: def __init__(self, n): self.tree = [0] * (n + 1) self.n = n def lowbit(self, x): return x & -x def update(self, x, k): while x 阅读全文
posted @ 2024-03-31 20:00 gebeng 阅读(2) 评论(0) 推荐(0) 编辑
摘要: 曼哈顿距离 两个单元格 \((x_i, y_i)\)和\((x_j, y_j)\) 之间的曼哈顿距离为 \(|x_i - x_j| + |y_i - y_j|\) 进一步总结,求最大的 \((x_i + y_i)_{max}\) - \((x_i + y_i)_{min}\) 与 最大的 \((x_ 阅读全文
posted @ 2024-03-31 16:30 gebeng 阅读(24) 评论(0) 推荐(0) 编辑
摘要: s = input() n = len(s) z = [0] * n left,right = 0,0 # z[i]表示s和s[i:]的LCP长度,规定z[0] = 0! for i in range(1,n): # 如果在z-box里,那么更新它的z[i]的值! if i <= right: z[ 阅读全文
posted @ 2024-03-31 10:27 gebeng 阅读(3) 评论(0) 推荐(0) 编辑
摘要: PMT:部分匹配表(Partial Match Table) 表示含义:t[0,i] 的前后缀最大匹配长度 s = input() t = input() n,m = len(s),len(t) pmt = [0] * m c = 0 for i in range(1,m): x = t[i] wh 阅读全文
posted @ 2024-03-30 17:00 gebeng 阅读(3) 评论(0) 推荐(0) 编辑
摘要: 灵茶之KMP01 题目链接 https://codeforces.com/problemset/problem/1137/B 题目大意 输入两个长度均 ≤\(5* 10^5\) 的字符串 s 和字符串 t,只包含 '0' 和 '1'。 重排 s 中的字符,使得 s 中有尽量多的子串等于 t。 输出重 阅读全文
posted @ 2024-03-30 16:35 gebeng 阅读(1) 评论(0) 推荐(0) 编辑
摘要: 暴力美学,珂朵莉树! from sortedcontainers import SortedList class node: __slots__ = ['l', 'r', 'val'] def __init__(self, l, r, val): self.l = l self.r = r self 阅读全文
posted @ 2024-03-30 10:33 gebeng 阅读(3) 评论(0) 推荐(0) 编辑