传送门

文章目录

  • 题意:
  • 思路:

题意:

给你一个序列aaa,求一个最长的子序列[l,r][l,r][l,r]满足aimodm=ai+1modm=...=armodma_i\bmod m=a_{i+1}\bmod m=...=a_r\bmod mai​modm=ai+1​modm=...=ar​modm,其中m≥2m\ge2m≥2。
n≤2e5,ai≤1e18n\le2e5,a_i\le1e18n≤2e5,ai​≤1e18

思路:

之前牛客做过一个类似的题,但是哪个题是要你找一个最小模数使得每个数模上他之后各不相同,这个题大同小异。
首先如果他们取模相等的话,那么每个相邻的两个之差的因数都可以作为mmm,问题转换成了求ci=ai+1−aic_i=a_{i+1}-a_ici​=ai+1​−ai​数组中最长的gcdgcdgcd不为111的序列。
这个显然可以用尺取来解决,数越少gcdgcdgcd可能越大,满足单调性。用STSTST表预处理一下即可。

// Problem: D. Integers Have Friends
// Contest: Codeforces - Codeforces Round #736 (Div. 2)
// URL: https://codeforces.com/contest/1549/problem/D
// Memory Limit: 256 MB
// Time Limit: 2000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tune=native")
//#pragma GCC optimize(2)
#include<cstdio>
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<cmath>
#include<cctype>
#include<vector>
#include<set>
#include<queue>
#include<algorithm>
#include<sstream>
#include<ctime>
#include<cstdlib>
#include<random>
#include<cassert>
#define X first
#define Y second
#define L (u<<1)
#define R (u<<1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].l+tr[u].r)>>1)
#define Len(u) (tr[u].r-tr[u].l+1)
#define random(a,b) ((a)+rand()%((b)-(a)+1))
#define db puts("---")
using namespace std;//void rd_cre() { freopen("d://dp//data.txt","w",stdout); srand(time(NULL)); }
//void rd_ac() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//AC.txt","w",stdout); }
//void rd_wa() { freopen("d://dp//data.txt","r",stdin); freopen("d://dp//WA.txt","w",stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> PII;const int N=400010,mod=1e9+7,INF=0x3f3f3f3f;
const double eps=1e-6;int n;
LL a[N],c[N];
LL f[N][25];
int len[N];
void init(int n)
{for(int i=1;i<=n;i++) len[i]=log2(i);for(int i=1;i<=n;i++) f[i][0]=c[i];int t=len[n]+1;for(int j=1;j<t;j++)for(int i=1;i<=n-(1<<j)+1;i++)f[i][j]=__gcd(f[i][j-1],f[i+(1ll<<(j-1))][j-1]);
}LL query(int l,int r) {int t=len[r-l+1];return __gcd(f[l][t],f[r-(1<<t)+1][t]);
}int main()
{//  ios::sync_with_stdio(false);
//  cin.tie(0);     int _; scanf("%d",&_);while(_--) {scanf("%d",&n);for(int i=1;i<=n;i++) scanf("%lld",&a[i]);for(int i=1;i<=n-1;i++) c[i]=abs(a[i+1]-a[i]);init(n-1);int ans=1;for(int i=1,j=1;i<=n-1;i++) {while(j<=i&&query(j,i)==1) j++;ans=max(ans,i-j+2);}printf("%d\n",ans);}return 0;
}
/**/

Codeforces Round #736 (Div. 2) D. Integers Have Friends ST表gcd + 尺取相关推荐

  1. Codeforces Round #736 (Div. 1Div2)

    Codeforces Round #736 (Div2) Codeforces Round #736 (Div. 1) 题号 题目 难度 A Gregor and Cryptography 签到 B ...

  2. Codeforces Round #736 (Div. 2)(B-C)

    Codeforces Round #736 (Div. 2) 花了十分钟帮朋友写了B,C就睡觉了,自己没打 B 先看上,再看左后看右 #include <iostream> #includ ...

  3. Codeforces Round #736 (Div. 2)E. The Three Little Pigs-长除法求多项式系数

    https://codeforces.com/contest/1549/problem/E 题目大意自己悟吧,不解释了. 这题在赛时我想的是fft,但是题解说不用fft就能求出多项式的系数,fft在这 ...

  4. Codeforces Round #736 (Div. 2) C. Web of Lies

    传送门 题意: n个人,m个朋友关系,在一个关系中,编号较小的那个人权力较小.q次操作:让两个人成为朋友:让两个人断绝关系:杀死所有有朋友的并且他的所有朋友的权力都比他大的人,重复该操作直到没有可以杀 ...

  5. Codeforces Round #736 (Div. 2)_C. Web of Lies

    C. Web of Lies 题目传送门: 题目传送门 题目截图: 题目大意: 给你一张图,连边代表两个点是朋友.一个点如果它所有的朋友都比它大,那他就出局了.接下来做q个操作: 1 u v代表uv之 ...

  6. Codeforces Round #401 (Div. 2) C Alyona and Spreadsheet —— 打表

    题目链接:http://codeforces.com/contest/777/problem/C C. Alyona and Spreadsheet time limit per test 1 sec ...

  7. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸

    D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  8. Codeforces Round #552 (Div. 3) E stl模拟 F dp G gcd

    contest链接 https://codeforces.com/contest/1154 E 题解思路 直接哈希模拟删除T了,可以用setsetset和lowerlowerlower_boundbo ...

  9. Codeforces Round #104 (Div. 2) E DP(01背包模型) +组和+除法取模求逆元

    题意: 规定只包含4或7的数为幸运数字,给定n个数的序列,求他的子序列,使得该子序列的长度为k并且满足该子序列中不存在相同的两个幸运数字.问一共寻在多少种可能.(只要该数的下标不同则认为是不同的序列) ...

最新文章

  1. Mob之社会化分享集成ShareSDK
  2. 毕业设计(二十四)---退出 博客 清除session
  3. docker 三种挂载文件路径方式
  4. 解决Windows系统崩溃Linux系统却没有任何问题的错误
  5. python格式化字符串漏洞_Python字符串格式化的方法(两种)
  6. int与bigdecimal的相互转换
  7. Android项目同步,如何通过gradle任务同步Android项目?
  8. P1426 小鱼会有危险吗
  9. Android框架之AsyncHttpClient
  10. 转换整形数字为16进制字符串
  11. IEC 60335标准介绍
  12. matlab legend下划线,MATLAB 画图 legend
  13. python新浪微博爬虫_利用新浪API实现数据的抓取\微博数据爬取\微博爬虫
  14. 关于STVP写保护等级2的问题
  15. 工作流程管理系统,表结构与运行机制
  16. Python字符串中提取国家名称
  17. [Error] 'else' without a previous 'if'
  18. 小程序开发工具中黑马优购小程序tabs组件_别不信,二十一天巧妙精通微信小程序的开发,附赠教程...
  19. 集成学习【一】:集成学习(Ensemble Learning)结合神经网络
  20. 地理国情普查外业调绘轨迹线的整理方法

热门文章

  1. COMA(二):Counterfactual Multi-Agent Policy Gradients 论文讲解
  2. 看似杂乱无序的随机运动.....
  3. 2021年将迎接你的是什么?
  4. 100斤的铁和100斤女生哪个重?
  5. 每日一笑 | 终于知道为什么胖了之后气质会垮了
  6. 项目管理 计算机仿真,分析计算机仿真技术在工程项目施工管理中的运用.pdf
  7. jquery如何实现ajax技术,使用JavaScript和jQuery简单实现Ajax技术(示例代码)
  8. python读写文件实例_python读写文件的简单示例
  9. 计算机组成与系统 报告,计算机组成与系统结构实验报告2
  10. 计算机安全模型研究与应用,软件哨兵安全动态检测模型的研究与实现-计算机应用研究.PDF...