题目 Source http://vjudge.net/problem/142058 Description Given N integers A1, A2, …. AN, Dexter wants to know how many ways he can choose three numbers such that they are three consecutive terms of an arithmetic progression. Meaning that, how many trip…
题意:求一个序列中,有多少三元组$(i,j,k)i<j<k $ 满足\(A_i + A_k = 2*A_i\) 构成等差数列. https://www.cnblogs.com/xiuwenli/p/9719425.html 在该题的基础上加了i<j<k的限制.不能单纯地FFT枚举结果. 考虑分块搭配FFT结果问题. 将原序列分成若干块,设每个块的大小为\(B\).则构成等差数列的三元组有三种构成情况. 1)三个数都在一个块内.这种情况对每个块独立处理.二重循环枚举\(A_i .A_…
[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,,和右边块的出现…
题意: 求一个序列中顺序的长度为3的等差数列. SOL: 对于这种计数问题都是用个数的卷积来进行统计.然而对于这个题有顺序的限制,不好直接统计,于是竟然可以分块?惊为天人... 考虑分块以后的序列: 一个块内直接枚举统计三个或两个在块内的. 只有一个在当前块我们假设它是中间那个,对左右其它块做卷积. 但是还是感觉复杂度有点玄学啊... 我比较傻逼...一开始块内统计根本没有想清楚...最后做卷积硬生生把复杂度变成了 $\sqrt{N}*N*log(N)$... 改了一个晚上终于没忍住看标程...…
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…
Arithmetic Progressions Given N integers A1, A2, …. AN, Dexter wants to know how many ways he can choose three numbers such that they are three consecutive terms of an arithmetic progression. Meaning that, how many triplets (i, j, k) are there such t…
3509: [CodeChef] COUNTARI Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 883  Solved: 250[Submit][Status][Discuss] Description 给定一个长度为N的数组A[],求有多少对i, j, k(1<=i<j<k<=N)满足A[k]-A[j]=A[j]-A[i]. Input 第一行一个整数N(N<=10^5).接下来一行N个数A[i](A[i]<=300…
3509: [CodeChef] COUNTARI Time Limit: 40 Sec  Memory Limit: 128 MBSubmit: 339  Solved: 85[Submit][Status] Description 给定一个长度为N的数组A[],求有多少对i, j, k(1<=i<j<k<=N)满足A[k]-A[j]=A[j]-A[i]. Input 第一行一个整数N(N<=10^5). 接下来一行N个数A[i](A[i]<=30000). Outp…
[Educational Codeforces Round 16]D. Two Arithmetic Progressions 试题描述 You are given two arithmetic progressions: a1k + b1 and a2l + b2. Find the number of integers x such that L ≤ x ≤ R andx = a1k' + b1 = a2l' + b2, for some integers k', l' ≥ 0. 输入 Th…
Dirichlet's Theorem on Arithmetic Progressions Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16733   Accepted: 8427 Description If a and d are relatively prime positive integers, the arithmetic sequence beginning with a and increasing…