Given n strings s1,s2,⋯,sn. Now define f(s,t) as the maximum i that satisfy s1⋯i=t∣t∣−i+1⋯∣t∣, and if such i doesn’t exist, f(s,t)=0.
The Problem is to calculate:
\sum_{i=1}^{n}\sum_{j=1}^{n}f(s_i, s_j)^2 \pmod{998244353}∑
i=1
n
∑
j=1
n
f(s
i
,s
j
)
2
(mod998244353)
输入描述:
The first line contains one integer n~(1 \leq n \leq 10^5)n (1≤n≤10
5
), denoting the number of given strings.
The following {n}n lines each contains a string s_i~(i = 1, 2, \cdots, n)s
i
(i=1,2,⋯,n).
It’s guaranteed that 1\leq |s_i|, \sum|s_i| \leq 10^61≤∣s
i
∣,∑∣s
i
∣≤10
6
and all strings only contain lowercase letters.
输出描述:
Only one line containing one integer, denoting the answer.
示例1
输入
复制
3
ab
ba
aba
输出
复制
29
说明
So the answer is 4\times 1^2 + 4\times 2^2 + 1\times 3^2 = 294×1
2
+4×2
2
+1×3
2
=29.
分析
计算 n 个字符串的所有后缀的哈希值,用 \text{unordered_map} 存不同后缀的个数,cntx 表示哈希值为 x 的后缀的个数。
然后对每个字符串的前缀求哈希值,若某个前缀的哈希值为 x,那么就有 cntx 个后缀与之匹配,而实际上这样的计数方法会产生重复。就拿单个字符串 aba 来说,会有两个后缀 a 和 aba 在位置 0 和 2 处匹配,而我们要的最长匹配显然是 aba。也就是说,某个位置 i 的匹配数多了与 i 为结尾的前缀与的后缀的最长匹配长度,这就是 Next 数组的定义,只需要将位置 i 的匹配后缀数量减去 Next 数组的值就是真正的贡献了。
Given n points in 2D plane. Considering all circles that the origin point (0,0) is on their boundries, find the one with the maximum given points on its boundry. Print the maximum number of points.
输入描述
The first line contains one integer n(1⩽n⩽2000), denoting the number of given points.
Following n lines each contains two integers x,y(∣x∣,∣y∣⩽10000), denoting a given point (x,y).
It’s guaranteed that the points are pairwise different and no given point is the origin point.
输出描述
Only one line containing one integer, denoting the answer.
示例1
输入
1 2 3 4 5
4 1 1 0 2 2 0 2 2
输出
1
3
说明
Considering circle (x−1)2+(y−1)2=2, we can see that the origin point is on its boundry and that there are 3 given points (0,2),(2,0),(2,2) on its boundry.
/****************************************************************** Copyright: 11D_Beyonder All Rights Reserved Author: 11D_Beyonder Problem ID: 2020牛客暑期多校训练营(第二场) Problem D Date: 8/11/2020 Description: Easy Calculation *******************************************************************/ #include<iostream> #include<cmath> #include<cstdio> usingnamespace std; intmain() { int HH,MM,SS; scanf("%d:%d:%d",&HH,&MM,&SS); int a=HH*3600+MM*60+SS; scanf("%d:%d:%d",&HH,&MM,&SS); int b=HH*3600+MM*60+SS; cout<<abs(a-b)<<endl; return0; }
Given n integers A1,A2,⋯,An. For all i∈{1,2,⋯,n}, you should determine the maximum value you can get if you repeatedly choose exactly i integers a1,a2,⋯ai and calculate their XOR sum $a_1 \oplus a_2 \oplus \cdots $.
Please notice that you can choose one integer multiple times for one i in this problem.
输入描述
The first line contains one integer n(1⩽n⩽2×105), denoting the number of given integers.
The second line contains n integers A1,A2,⋯,An(0⩽Ai<218).
输出描述
One line containing n integers, where i-th integer denotes the maximum value you can get if you repeatedly choose i integers and calculate their XOR sum.
Given a matrix of size n×m and an integer k, where ai,j=lcm(i,j), the least common multiple of i and j. You should determine the sum of the maximums among all k×k submatrices.
输入描述
Only one line containing three integers n,m,k $(1\leqslant n,m \leq 5000, 1 \leqslant k \leqslant $$\min(n, m))$.
输出描述
Only one line containing one integer, denoting the answer.
示例1
输入
1
3 4 2
输出
1
38
说明
The given matrix is: $\begin{pmatrix}1&2&3&4\\2&2&6&4\\3&6&3&12\end{pmatrix}$.
The maximums among all 2×2 submatrices are 2,6,6,6,6,12 respectively, and their sum is 38.
分析
要求所有边长为 k 的正方形区域内的最值,可以看作将滑动窗口由一维的数轴扩展到了二维矩阵上。
首先对于每一行利用单调队列求出位于 (i,j) 时,(i,j)∼(i,j+k−1) 区域内的最大值,用 ansi,j 表示。然后,遍历每一列,利用单调队列求出位于 (i,j) 时, (i,j)∼(i+k−1,j) 区域内 ans 的最大值,用 ansi,j 表示(直接赋值于 ansi,j);由于 ansi,j 已经是 (i,j)∼(i,j+k−1) 的最大值,所以第二次纵向求区间最大值后,ansi,j 已经表示由 (i,j) 为左上角,(i+k−1,j+k−1) 为右下角的正方形区域内的最大值。
至此,求出了所有边长为 k 的正方形区域内的最值。
Given a sequence a of size n and a sequence b of size m, determine the number of subintervals called s of size m in a satisfying ∀i∈{1,2,⋯,m}, si⩾bi.
输入描述
The first line contains two integers n,m(1⩽n⩽150000,1⩽m⩽min(n,40000)). The second line contains n integers a1,a2,⋯,an(1⩽ai⩽109), denoting the sequence a.
The third line contains m integers b1,b2,⋯,bn(1⩽bi⩽109), denoting the sequence b.
输出描述
Only one line containing one integer, denoting the answer.
Given three concentric circles whose radiuses are r1,r2,r3 respectively, and A,B,C are the moving points on the given three circles respectively. Determine the expected area of △ABC.
输入描述
The first line contains one integer T(1⩽T⩽1000), denoting the number of test cases.
For each test case, one line containing three integers r1,r2,r3(1⩽r1,r2,r3⩽100), denoting the radiuses of three given concentric circles.
输出描述
Print T lines each containing one real number with one decimal places after the decimal point, denoting the answer to corresponding test case.
It’s guaranteed that the second decimal place after the decimal point is neither 4 nor 5.
示例1
输入
2
1 1 1
2 3 5
输出
0.5
5.5
说明
For the first text case, the accurate answer is 2π3=0.47746482927568600730665129011754⋯.