BZOJ-3509 母函数+分块+暴力+FFT】的更多相关文章

题目描述 给定一个长度为N的数组A[],求有多少对i, j, k(1<=i<j<k<=N)满足A[k]-A[j]=A[j]-A[i]. 输入格式 第一行一个整数N(N<=10^5).接下来一行N个数A[i](A[i]<=30000). 输出格式 一行一个整数. 样例输入 10 3 5 3 6 3 4 10 4 5 2 样例输出 9 这题网上题解很多我的第一个想法是枚举 j 然后左边的数 和 右边的数 FFT处理一下 这样的复杂度是 n^2*log(n) 复杂度明显不行…
[BZOJ 3509] [CodeChef] COUNTARI (FFT+分块) 题面 给出一个长度为n的数组,问有多少三元组\((i,j,k)\)满足\(i<j<k,a_j-a_i=a_k-a_j\) \(n \leq 10^5, a_i \leq 30000\) 分析 记\(m=\max(a_i)\) 先做一点变形\(a_i+a_k=2a_j\).那么枚举j,把j左边的和右边的所有数字找出来,找出有哪些数字对的和为\(2a_j\). 维护当前块左边每个数的出现次数cntl,,和右边块的出现…
3509: [CodeChef] COUNTARI 题意:统计满足\(i<j<k, 2*a[j] = a[i] + a[k]\)的个数 \(2*a[j]\)不太好处理,暴力fft不如直接暴力 考虑分块 每个块用生成函数统计j在块中ik在两边的块中的 有两个在块中或者三个都在暴力统计,实时维护两边权值出现次数 #include <iostream> #include <cstdio> #include <cstring> #include <algori…
E. Holes Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/13/problem/E Description Little Petya likes to play a lot. Most of all he likes to play a game «Holes». This is a game for one person with following rules: There are…
Description An array of positive integers a1, a2, ..., an is given. Let us consider its arbitrary subarray al, al + 1..., ar, where 1 ≤ l ≤ r ≤ n. For every positive integer s denote by Ks the number of occurrences of s into the subarray. We call the…
[BZOJ 3456]城市规划(cdq分治+FFT) 题面 求有标号n个点无向连通图数目. 分析 设\(f(i)\)表示\(i\)个点组成的无向连通图数量,\(g(i)\)表示\(i\)个点的图的数量. 显然\(g(i)=2^{C_i^2}\)种,但是我们要把不联通的去掉. 枚举1号点所在联通块大小\(j\).从剩下\(i-1\)个点里选\(j-1\)个点和1号点构成联通块,有\(C_{i-1}^{j-1}\)种选法.1号点所在联通块的连边方案有\(f(i)\)种,剩下\(i-j\)个点随便连边…
Easy version:Codeforces 题面传送门 & 洛谷题面传送门 Hard version:Codeforces 题面传送门 & 洛谷题面传送门 发现自己交互题烂得跟 sh*t 一样--于是不管三七二十一先来两道再说( 首先考虑最 trivial 的情况,也就是 \(k=1\) 和 \(k=n\) 两种情况,对于 \(k=1\) 你就 \(\mathcal O(n^2)\) 地检查一遍所有的 pair,具体来说我们枚举所有 \(i,j(i<j)\),然后依次询问 \(i…
分块大法好. 块内暴力,块外FFT. 弃疗了,抄SX队长$silvernebula$的代码 #include <map> #include <cmath> #include <queue> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; #define F(i,j,k) fo…
思路: 跟今年WC的题几乎一样 (但是这道题有重 不能用bitset水过去) 正解:分块FFT http://blog.csdn.net/geotcbrl/article/details/50636401    from GEOTCBRL 可以看看hgr的题解..写得很详细 //By SiriusRen #include <cmath> #include <cstdio> #include <cstring> #include <algorithm> usi…
2038: [2009国家集训队]小Z的袜子(hose) Time Limit: 20 Sec  Memory Limit: 259 MBSubmit: 5763  Solved: 2660[Submit][Status][Discuss] Description 作为一个生活散漫的人,小Z每天早上都要耗费很久从一堆五颜六色的袜子中找出一双来穿.终于有一天,小Z再也无法忍受这恼人的找袜子过程,于是他决定听天由命……具体来说,小Z把这N只袜子从1到N编号,然后从编号L到R(L 尽管小Z并不在意两只…