permutation prefix sums

CF1542E2 Abnormal Permutation Pairs (hard version) 题解

Abnormal Permutation Pairs (hard version) 两个限制:字典序小、逆序对大,一个显然的想法就是确保一对关系,统计另一对关系。 确保哪一对呢?我们想了想,决定确保字典序小,因为字典序是可以贪心的。 具体而言,我们考虑两个排列自第 \(i\) 位开始出现了不同。这样 ......
题解 Permutation Abnormal version 1542E

Codeforces Round 884 (Div. 1 + Div. 2) B. Permutations & Primes

给一个正整数 \(n\) ,你需要构造一个 \(n\) 的排列 \(p_1, p_2, \cdots, p_n\) 。对于排列 \(p\) 的每个子段 \([l, r]\) ,\(mex_{i = l}^{r} a_i\) 的结果为质数的次数尽可能多。 此处的 \(mex\) 最小排除值最低为 \( ......
Permutations Codeforces Div Primes Round

【dp】【竞赛图的性质】ARC163D Sum of SCC 题解

ARC163D 发现这个竞赛图一定能被分为两个集合 \(A\),\(B\)。满足 \(\forall u\in A,v\in B\),均有 \(u\to v\in E\)。答案就是划分这两个集合的方案数。 证明: 首先,竞赛图缩完点后一定是一条链,对强连通分量进行标号,满足编号小的强连通分量指向编号 ......
题解 性质 163D ARC 163

【前缀和优化 dp】CF1542E1 Abnormal Permutation Pairs (easy version) 题解

CF1542E1 首先时间复杂度肯定是 \(\mathcal{O}(n^3)\) 的。 容易想到先枚举最长公共前缀,然后枚举 \(p_{len+1}\) 和 \(q_{len+1}\),再枚举逆序对数进行统计。 令 \(f_{i,j}\) 表示有 \(j\) 个逆序对的 \(i\) 阶排列的个数。 ......
题解 前缀 Permutation Abnormal version

【前缀和优化 dp】CF1542E2 Abnormal Permutation Pairs (hard version) 题解

CF1542E2 首先时间复杂度肯定是 \(\mathcal{O}(n^3)\) 的。 容易想到先枚举最长公共前缀,然后枚举 \(p_{len+1}\) 和 \(q_{len+1}\),再枚举逆序对数进行统计。 令 \(f_{i,j}\) 表示有 \(j\) 个逆序对的 \(i\) 阶排列的个数。 ......
题解 前缀 Permutation Abnormal version

Codeforces Round 893 (Div. 2) C. Yet Another Permutation Problem

有一个 \(gcd\) 游戏,按以下步骤进行: 选择一个 \(n\) 的排列 \(p_1, p_2, \cdots, p_n\) 。 对于每个 \(i\) ,\(d_i = gcd(p_i, p_{i \% n + 1})\) 排列 \(p\) 的 \(score\) 为数组 \([d_1, d_2 ......
Permutation Codeforces Another Problem Round

linux 中 md5sum -c 命令

001\ [root@pc1 test01]# ls [root@pc1 test01]# seq 3 > a.txt ## 测试文件 [root@pc1 test01]# ls a.txt [root@pc1 test01]# cat a.txt 1 2 3 [root@pc1 test01]# ......
命令 md5sum linux 5sum md5

[ARC167D] Good Permutation 题解

题意 对于一个长度为 \(N\) 的排列 \(Q\),定义其为好的,当且仅当 对于任意整数 \(i \in \left[1, N\right]\),在进行若干次操作 \(i \leftarrow Q_i\) 后可以得到 \(i = 1\)。 给定一个排列 \(P\),定义一次操作为交换两个数。定义 ......
题解 Permutation 167D Good ARC

ARC167D Good Permutation 题解

题意 给定一个长度为 \(N\) 的排列 \((P_1,P_2,\cdots,P_N)\)。称一个排列 \(P\) 为“好排列”当且仅当对于所有 \(1\leq x\leq N\),都能通过不停地使 \(x\leftarrow P_x\) 将 \(x\) 变成 \(1\)。 通过最小次数操作将 \( ......
题解 Permutation 167D Good ARC

Count of Sub-Multisets With Bounded Sum

Count of Sub-Multisets With Bounded Sum You are given a 0-indexed array nums of non-negative integers, and two integers l and r. Return the count of s ......
Sub-Multisets Multisets Bounded Count With

CF1628D2 Game on Sum

题目链接(Easy) 题目链接(Hard) Part1 神奇的博弈类型 \(Dp\) 。 我们发现与当前状态有关的量,有且只有 现在是第几轮,还有 Bob 用了几次加的操作 ,这都会影响之后的决策,而和之前的决策无关,换句话说,当前决策有后效性,没有前效性。那我们考虑倒着 \(Dp\). Part2 ......
1628D 1628 Game Sum CF

[LeetCode] 1354. Construct Target Array With Multiple Sums 多次求和构造目标数组

You are given an array target of n integers. From a starting array arr consisting of n 1's, you may perform the following procedure : let x be the sum ......
数组 Construct LeetCode Multiple 目标

Codeforces Round 684 (Div. 2) B. Sum of Medians

定义 \(median\) 是一个非降序数组中第 \(\lceil \frac{n}{2} \rceil\) 的数。数组从 \(1\) 开始标号。 给两个数 \(n\) 和 \(k\) ,并给出一个长为 \(nk\) 的数组 \(a\) 。 需要分出为 \(k\) 个大小为 \(n\) 的数组,每个 ......
Codeforces Medians Round 684 Div

解决SUM函数返回为NULL

解决SUM函数返回为NULL SUM函数的作用:计算某一字段中所有行的数值和, 使用SUM函数进行对符合条件的结果行数进行求和。 问题产生: sum 求和时会对 null 进行过滤,不计算,但如果没有返回结果,则sum 函数的返回值为 null,不是 0: 解决方式: 1. IFNULL 使用IFN ......
函数 NULL SUM

CF1886A Sum of Three 题解

Question 给定一个正整数 N ,我们需要找三个不同的整数x,y,z,使得 N = x+y+z,其中下x,y,z不能被三整除 solution 我们把N%3会有一些余数,我们针对余数来讨论,其中我们只关注xyz的余数 如果余数为0 那么也就可能是1+1+1,或者2+2+2,但是考虑到xyz不同 ......
题解 1886A Three 1886 Sum

[AGC030F] Permutation and Minimum 题解

Permutation and Minimum 看到 300 的数据范围,再加上计数题,很容易就往计数 DP 方向去想。 为方便,我们将 \(n\) 乘二。 因为是两个位置取 \(\min\),于是我们便想到从小往大把每个数填入序列。于是DP数组第一维的意义便出来了:当前已经填入了前 \(i\) 小 ......
题解 Permutation Minimum 030F AGC

Prefixes and Suffixes (CF D) (字符串翻转找性质)

思路: 利用操作 使得题目更好分析, t 的后缀,反转t , 来看t 的前缀, 实际操作的时候, 把s 和 t 的前缀在反转一下进行交换就可以了, 发现性质 1 C(si, ti) 他们的相对位置不会变化, 一直是匹配的 然后利用 翻转的性质, 一定会产生任意我想要的排列 (从后开始构造, 先把目标 ......
字符串 字符 Prefixes Suffixes 性质

CF882E1+CF1882E2 Two Permutations 题解-构造题

CF882E1+CF1882E2 Two Permutations 题解-构造题 哇,人类智慧,太智慧了。。。 此题作为20231010联考的 T3。 感觉赛时根本没有去往这方面想。 CF1882E1 CF1882E2 E1 是简单版,就是没有要求操作数最小化。 E1-Easy Version 方法 ......
题解 Permutations CF 1882 882

Python word'str'(字符串前缀string prefix)的种类

Python 字符串前缀(String prefix) r 'string' r' ',用法是不会对后方字符串中的转义符进行转义,如: str = r'\n' print(str) # 会直接输出\n,并不会输出换行 f 'string' f ' ',用法是对字符进行格式化就和str.format( ......
前缀 字符串 字符 种类 Python

CodeForces 1882E1 Two Permutations (Easy Version)

洛谷传送门 CF 传送门 考虑若是对一个排列进行操作,怎么做。 我们维护一个排列上的值域连续段 \([l, r]\),满足 \(a_{l + 1} = a_l + 1, a_{l + 2} = a_{l + 1} + 1\),以此类推。初始 \(l = r = 1\)。 那么我们每次可以选择往外扩充 ......
Permutations CodeForces Version 1882E1 1882E

CodeForces 1882E2 Two Permutations (Hard Version)

洛谷传送门 CF 传送门 如何评价,模拟赛搬了一道,前一天晚上代码写了一半的题。 考虑如何让操作次数最小。发现直接做太困难了。根本原因是,一次操作对序列的影响太大了。考虑做一些转化,减少一次操作对序列的影响。 仍然先考虑一个排列怎么做。 不知道为什么可以想到在排列前面添加特殊字符 \(0\) 变成 ......
Permutations CodeForces Version 1882E2 1882E

Educational Codeforces Round 109 (Rated for Div. 2) B. Permutation Sort

给一个长为 \(n\) 的排列 \(a\),你可以执行以下操作:选择一个子数组并且按任意顺序重排,但这个子数组不能是数组本身。 询问最少经过多少次操作可以使得排列 \(a\) 变为升序。 定义操作次数为 \(ans\) 。 若数组已经有序,\(ans = 0\) 。 若 \(a_1 = 1\) 或者 ......

Codeforces Round 891 (Div. 3) F. Sum and Product(数论+map)

Codeforces Round 891 (Div. 3) F. Sum and Product 思路:对于x,y:ai+aj=x —> aj=x-ai 因此 ai*(x-ai) = y ——> ai = (x 土 sqr( x^2 - 4y ) ) /2 对应的 ai 就是要的两个值 若两个值不同 ......
数论 Codeforces Product Round 891

D. Sum of XOR Functions

D. Sum of XOR Functions You are given an array $a$ of length $n$ consisting of non-negative integers. You have to calculate the value of $\sum_{l=1}^{ ......
Functions Sum XOR of

[LeetCode] 2578. Split With Minimum Sum

Given a positive integer num, split it into two non-negative integers num1 and num2 such that: The concatenation of num1 and num2 is a permutation of  ......
LeetCode Minimum Split 2578 With

pytorch permute

pytorch permute permute(dims)将tensor的维度换位。参数:参数是一系列的整数,代表原来张量的维度。比如三维就有0,1,2这些dimension。例: import torch import numpy as np a=np.array([[[1,2,3],[4,5,6 ......
pytorch permute

CF1857F Sum and Product

根据题意我们有:\(b=a_i+a_j\),\(c=a_i\times a_j\)。 可以发现 \(a_i\) 和 \(a_j\) 是一元二次方程 \(x^2-bx+c=0\) 的根。 那么就可以根据求根公式 \(x=\dfrac{-b\pm \sqrt{b^2-4ac}}{2a}\) 来求出 \( ......
Product 1857F 1857 Sum and

D. Prefix Purchase

D. Prefix Purchase You have an array $a$ of size $n$, initially filled with zeros ($a_1 = a_2 = \ldots = a_n = 0$). You also have an array of integers ......
Purchase Prefix

D. Prefix Permutation Sums

D. Prefix Permutation Sums 吐槽:读题不仔细,还以为原数组的取值是任意的,最后看题解的时候才发现取值在[1,n],当时因为看不懂直接跳过了 题意:给你一个缺了一个的前缀和数组,让你判断是否存在原数组,取值[1,n],每个数只存在一次 可以分类讨论 1 缺少最后一个前缀和 2 ......
Permutation Prefix Sums

【思维】【DP】ABC298Ex Sum of Min of Length 题解

ABC298Ex 简单题。 因为有 \(\min\) 不好做,容易想到讨论 \(d(i, L)\) 和 \(d(i, R)\) 的大小。 令 \(p = \text{LCA}(L, R)\),\(dep_L > dep_R, dist = dep_L + dep_R - 2\times dep_p\ ......
题解 思维 Length of ABC