题目大意:给一个字符串,求所有相邻两回文子串的外侧下标之积的和 题目分析:另L[i]为所有以 i 为右端点的回文字串的左端点之和,同理,另R[i]表示所有以 i 为左端点的回文子串的右端点之和.显然,答案为sigma(L[i]*R[i+1]) 其中,1<=i<length(字符串).求出L和R是关键.先用manacher算法处理出p数组,然后再求出L和R.求L和R的思想(非常巧妙)跟树状数组求区间和的思想差不多.不过,这道题如果用树状数组或线段树的话会超时. 参考代码: # include&l
Codeforces Round #539 (Div. 1) A. Sasha and a Bit of Relax description 给一个序列\(a_i\),求有多少长度为偶数的区间\([l,r]\)满足\([l,mid]\)的异或和等于\([mid+1,r]\)的异或和. solution 等价于询问有多少长度为偶数的区间异或和为\(0\). 只需要两个位置的异或前缀和与下标奇偶性相同即可组成一个合法区间. #include<cstdio> #include<algorith
Description Leha somehow found an array consisting of n integers. Looking at it, he came up with a task. Two players play the game on the array. Players move one by one. The first player can choose for his move a subsegment of non-zero length with an
目的:线性查找一个串的最长回文子串 时间复杂度:O(n) len[i]表示以i为中心的回文串的半径,mx即为当前计算回文串最右边字符的最大值,p是中心点mid,mx-i和2*p-1关于p对称 https://blog.csdn.net/csdn_kou/article/details/82917937 hdu3068,板子题,求最长回文长度. #include<bits/stdc++.h> using namespace std; ; ]; ],T[maxn*],s[maxn*]; int i
一.质数排列(LeetCode-1175) 1.1 题目描述 1.2 解题思路 先统计出1-n中有多少个质数,得到质数个数\(x\),剩下的数\(y = n - x\): 使用排列组合公式得出结果 \(A_x^x A_y^y\) 1.3 解题代码 private static final long INF = 1000000007; public int numPrimeArrangements(int n) { int count = countPrime(n); //剩余位数 int oth
A Who is better? 题意 excrt+斐波那契博弈 分析 Java的BigInteger对象默认为null,不能直接比较. 代码 import java.math.BigInteger; import java.util.Scanner; public class Main { static int n; static BigInteger[] a=new BigInteger[25]; static BigInteger[] b=new BigInteger[25]; stati
题意:给n个数字串,求它们的所有不包含前导0的不同子串的值之和 思路:把数字串拼接在一起,构造SAM,然后以每个状态的长度len作为特征值从小到大排序,从前往后处理每个状态,相当于按拓扑序在图上合并计算答案. #include <bits/stdc++.h> using namespace std; #define X first #define Y second #define pb(x) push_back(x) #define mp(x, y) make_pair(x, y) #defi