Description ?? is practicing his program skill, and now he is given a string, he has to calculate the total number of its distinct substrings. But ?? thinks that is too easy, he wants to make this problem more interesting. ?? likes a character X very…
暑假颓废了好久啊...重新开始写博客 题目大意:给定10w个数,10w个询问.每次询问一个区间[l,r],求出gcd(a[l],a[l+1],...,a[r])以及有多少个区间[l',r']满足gcd(a[l'],a[l'+1],...,a[r'])==gcd(a[l],a[l+1],...,a[r]). 第一问就是简单的ST表了,f[i,j]表示i~i+2^j-1的gcd是多少,预处理出来就可以O(1)查询了. 第二问需要分析一下.首先,对于任意一个左端点,显然随着右端点的右移,这个区间的gc…
Bubble Sort Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 224    Accepted Submission(s): 147 Problem Description P is a permutation of the integers from 1 to N(index starting from 1). Here is…
描述  有N个人,N个活动, 每个人只会对2个或者3个活动感兴趣,  每个活动也只有两个人或者两个活动对它兴趣,每个人参加一个  感兴趣的活动需要一天 ,且当天该活动被参加时,其他的人不能参加  如果每个人都参加完自己有兴趣的活动,应当怎样安排使得所用总天数时间最短 2<= N <=1000, 1<=m<=1000;   输入 一个数T 表示T 组数据每组一个N表示人数,编号1 -- N , 一个数 m ,接下来m 行每个两个数x,y, 表示第 x 个人对第y个活动感兴趣 输出 每…
题目大意:一个n(n<=1000)行,20列的棋盘上有一些棋子,两个人下棋,每回合可以把任意一个棋子向右移动到这一行的离这个棋子最近的空格上(注意这里不一定是移动最后一个棋子),不能移动到棋盘外,不能移动了就算输,两个人都用最优策略,问先手是否有必胜策略. 这题显然就是SG函数了吧.行与行之间互不影响,所以可以看成n个子游戏,求出它们各自的SG函数然后异或一下就可以了.我们发现只有20列,2^21=2097152,所以我们可以先把行的所有情况的SG函数预处理出来,然后每次询问O(1)就行了. 代…
本题题意是,给你一个长度为n的序列,使用最少的操作把序列转换为从小到大的顺序,并输出操作数*min(x,y) 实质上是算出该序列中有多少逆序对,有归并排序和树状数组两种算法,由于数据之间的差值有点大,所以使用树状数组时需要先离散化 离散化后排序有两种方式,一种是先按value排,再按id排,另一种是按value排后,把重复的统一化 这里采用第一种方式 Swaps and Inversions Time Limit: 2000/1000 MS (Java/Others)    Memory Lim…
题目链接:hdu_1403_Longest Common Substring 题意: 给你两个字符串,然你找最长的公共子串 题解: 后缀数组的经典应用,要找两个字符串的公共子串,那么就相当于找两个串的后缀的最长公共前缀,我们将两个字符串拼接在一起,中间插一个特殊字符 然后我们考虑height数组,height数组存的是排i和i-1的最长前缀,如果sa[i]和sa[i-1]在特殊字符的两边,那么这个height[i]记录的就是这两个串的最长 子串,然后扫一遍height数组更新一下答案就行了 #i…
Maximum repetition substring Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9458   Accepted: 2915 Description The repetition number of a string is defined as the maximum number R such that the string can be partitioned into R same conse…
Substring Problem Description ?? is practicing his program skill, and now he is given a string, he has to calculate the total number of its distinct substrings. But ?? thinks that is too easy, he wants to make this problem more interesting. ?? likes…
http://acm.hdu.edu.cn/showproblem.php?pid=5769 题意:在S串中找出X串出现的不同子串的数目? 其中1 <= |S| < $10^5$ 官方题解: 处理出后缀数组中的sa[]数组和height[]数组.在不考虑包含字符X的情况下,不同子串的个数为 如果要求字符X,只需要记录距离sa[i]最近的字符X的位置(用nxt[sa[i]]表示)即可,个数 理解:后缀数组height[i]就是sa[i]与sa[i-1]的LCP,在后缀数组中求解全部的不同子串(之…
题意:求母串中有多少不同的包含x字符的子串 分析:(首先奉上FZU官方题解) 上面那个题就是SPOJ694 ,其实这两个题一样,原理每次从小到大扫后缀sa数组,加上新的当前后缀的若干前缀,再减去重复的 吐槽:因为打多校的时候忘记了后缀数组(其实是就算记着也不会做这题),所以傻逼了,所以眼看无数人1y这题,让我一度产生了暴力的想法 还是太弱,太傻逼 #include <iostream> #include <cmath> #include <cstdio> #includ…
重复次数最多的字串,我们可以枚举循环节的长度. 然后正反两次LCP,然后发现如果长度%L有剩余的情况时,答案是在一个区间内的. 所以需要找到区间内最小的rk值. 两个后缀数组,四个ST表,$\Theta(n\log n)$ 就可以解决了 空间卡死了,瞎晶胞卡过去了. #include <map> #include <cmath> #include <queue> #include <cstdio> #include <cstring> #incl…
POJ - 3693 Maximum repetition substring 题意 输入一个串,求重复次数最多的连续重复字串,如果有次数相同的,则输出字典序最小的 Sample input ccabababc daabbccaa # Sample Output Case 1: ababab Case 2: aa #include <iostream> #include <cstdio> #include <cstring> #include <algorithm…
题目链接 Problem Description We define the distance of two strings A and B with same length n is disA,B=∑i=0n−1|Ai−Bn−1−i| The difference between the two characters is defined as the difference in ASCII. You should find the maximum length of two non-over…
Is Derek lying? Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 612    Accepted Submission(s): 353 Problem Description Derek and Alfia are good friends.Derek is Chinese,and Alfia is Austrian.Thi…
题面传送门 一道非常不错的 FWT+插值的题 %%%%%%%%%%%% 还是那句话,反正非六校的看不到题对吧((( 方便起见在下文中设 \(n=2^d\). 首先很明显的一点是这题涉及两个维度:异或和与选出的元素的个数.因此考虑像子集卷积那样建立一个二元生成函数表示这个东西,具体来说我们定义一个幂级数 \(F\)​​ 形如 \(\sum\limits_{n\ge 0}\sum\limits_{m\ge 0}f_{n,m}x^ny^m\)​​,并定义两个幂级数 \(F,G\)​​ 的乘法得到的幂级…
由于 NFLSOJ 题面上啥也没有就把题意贴这儿了( 没事儿,反正是上赛季的题,你们非六校学生看了就看了,况且看了你们也没地方交就是了 题意: 给你一张 \(n\) 个点 \(m\) 条边的图 \(G=(V,E)\). 要求有多少张子图 \(G'=(V',E')\)​ 满足 \(G'\) 是连通二分图. \(n\le 20,m\le\dfrac{n(n-1)}{2}\) 答案对 \(998244353\) 取模. 输入样例 #1: 3 3 1 2 1 3 2 3 输出样例 #1: 9 众所周知,…
这题起初没读懂题意,悲剧啊,然后看了题解写完就AC了 题意是给一个N,然后给N+1个整数 接着给N个操作符(只有三种操作  即  或 ,与 ,和异或 |   &  ^ )这样依次把操作符插入整数之间就可以得到一个表达式 接着给出 N 给浮点数(在0~1之间表示概率 )表示的是 操作符和他右边的整数丢失的概率. 例如下面这组数据 1 1 2 & 0.5 整数与操作符间可以组成一个表达式即 1&2 但是由于某些原因表达式的操作符和他操作的右边的 那个数有一定的概率会丢失这组数据就是 &…
题目连接:Click here 题意:在一个[L,R]内找到最大的gcd(f[i],f[j])其中L<=i<j<=R,f[x]表示i分解质因数后因子的种类数.eg:f[10]=2(10=2*5),f[12]=2(12=2*2*3). 分析:很容易想到先将f[x]求出来,这里x最大1e6,要在常数时间内求出f[x].并且稍加分析就知道1<=f[x]<=7,可以用一个dp[i][j]表示从f[1]到f[i]有多少个j.这样就可以在常数时间内预处理出来,后面在O(1)的时间内就可以…
题目链接 Problem Description The Eternal Fleet was built many centuries ago before the time of Valkorion by an unknown race on the planet of Iokath. The fate of the Fleet's builders is unknown but their legacy would live on. Its first known action was in…
题目链接 Problem Description The Death Star, known officially as the DS-1 Orbital Battle Station, also known as the Death Star I, the First Death Star, Project Stardust internally, and simply the Ultimate Weapon in early development stages, was a moon-si…
题目链接 Problem Description Galen Marek, codenamed Starkiller, was a male Human apprentice of the Sith Lord Darth Vader. A powerful Force-user who lived during the era of the Galactic Empire, Marek originated from the Wookiee home planet of Kashyyyk as…
题目链接 Problem Description HazelFan wants to build a rooted tree. The tree has n nodes labeled 0 to n−1, and the father of the node labeled i is the node labeled ⌊i−1k⌋. HazelFan wonders the size of every subtree, and you just need to tell him the XOR…
题目链接 Problem Description Bob has a dictionary with N words in it. Now there is a list of words in which the middle part of the word has continuous letters disappeared. The middle part does not include the first and last character. We only know the pr…
题目链接 Problem Description Alice and Bob are playing a game called 'Gameia ? Gameia !'. The game goes like this : There is a tree with all node unpainted initial. Because Bob is the VIP player, so Bob has K chances to make a small change on the tree an…
题目链接 Problem Description The school set up three elective courses, assuming that these courses are A, B, C. N classes of students enrolled in these courses. Now the school wants to count the number of students who enrolled in at least one course in e…
题目链接 Problem Description Have you ever seen the wave? It's a wonderful view of nature. Little Q is attracted to such wonderful thing, he even likes everything that looks like wave. Formally, he defines a sequence a1,a2,...,an as ''wavel'' if and only…
题目链接 Problem Description Give you an array A[1..n]of length n. Let f(l,r,k) be the k-th largest element of A[l..r]. Specially , f(l,r,k)=0 if r−l+1<k. Give you k , you need to calculate ∑nl=1∑nr=lf(l,r,k) There are T test cases. 1≤T≤10 k≤min(n,80) A[…
题目链接 Problem Description RXD has a tree T, with the size of n. Each edge has a cost. Define f(S) as the the cost of the minimal Steiner Tree of the set S on tree T. he wants to divide 2,3,4,5,6,-n into k parts S1,S2,S3,-Sk, where ⋃Si={2,3,-,n} and fo…
题目链接 Problem Description Function Fx,ysatisfies: For given integers N and M,calculate Fm,1 modulo 1e9+7. Input There is one integer T in the first line. The next T lines,each line includes two integers N and M . 1<=T<=10000,1<=N,M<2^63. Output…