当前位置:网站首页>Integers have friends interval GCD + double pointer
Integers have friends interval GCD + double pointer
2022-04-23 06:21:00 【Bzdhxs_ nt】
Ideas
For two adjacent numbers a b
Interval module p p p congruence a % p = k 1 ∗ x + c , b % p = k 2 ∗ x + c a\%p = k1*x+c , b\%p = k2*x+c a%p=k1∗x+c,b%p=k2∗x+c Introduction ( a − b ) % p = k ∗ x (a-b) \% p = k*x (a−b)%p=k∗x
Consider the differential array , If there is an interval in the difference array [ l , r ] , g c d > 1 [l,r] ,gcd >1 [l,r],gcd>1 . In the original array interval [ l − 1 , r ] [l-1,r] [l−1,r] Modulo identical number x x x congruence
Maintenance interval g c d gcd gcd Sure Segment tree and can be maintained dynamically
There is no need to modify S T ST ST Tables can also maintain intervals g c d gcd gcd
How to enumerate the answers ?
Violent enumeration is not desirable , Because of the interval g c d gcd gcd Monotonicity , It can be divided into two parts It's fine too
Enumerate right endpoints r r r, Then move the left endpoint l l l
Code
#define int long long
#define endl "\n"
#define _orz ios::sync_with_stdio(false),cin.tie(0)
#define mem(str,num) memset(str,num,sizeof(str))
#define forr(i,a,b) for(int i = a; i <= b;i++)
#define forn(i,n) for(int i = 0; i < n; i++)
#define dbg() cout <<"0k!"<< endl;
typedef long long ll;
int pri[16] = {
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53};
const int inf = 0x3f3f3f3f;
const int INF = ~0ULL;
const int N = 1e6+10;
int a[200005],b[200005];
// struct node{
// int l,r;
// int dat;
// #define ls i<<1
// #define rs i<<1|1
// }t[200005<<2];
// void build(int i,int l,int r){
// t[i].l = l,t[i].r = r;
// if(l==r){
// t[i].dat = b[l];
// return;
// }
// int mid = (l+r) >> 1;
// build(ls,l,mid);
// build(rs,mid+1,r);
// t[i].dat = __gcd(t[ls].dat,t[rs].dat);
// }
// int ask(int i,int l,int r){
// if(l <= t[i].l && r >= t[i].r){
// return t[i].dat;
// }
// int res = 0;
// int mid = (t[i].l+t[i].r)>>1;
// if(l <= mid) res = __gcd(res,ask(ls,l,r));
// if(r >mid ) res = __gcd(res,ask(rs,l,r));
// return abs(res);
// }
int f[200005][21];
int n;
void ST(){
// No initialization
forr(i,1,n) f[i][0] = b[i];
forr(i,1,20)for(int j = 1;j+(1<<i)-1 <= n;j++){
f[j][i] = __gcd(f[j][i-1],f[j+(1<<(i-1))][i-1]);
}
}
void solve(){
cin>>n;
forr(i,1,n) cin>> a[i],b[i] = abs(a[i]-a[i-1]);
ST();
if(n==1){
cout << 1 << endl;
return;
}
//build(1,1,n);
int l = 2; // Minutiae Because the differential array b[1] Same as the original array So we have to go from l=2 Start enumeration , Because sometimes b[1] It may lead to answers within the range of answers provided +1, Examples 2
int res = 1;
for(int r = 2;r <= n;r++){
if(b[r]==1) continue;
while(l < r){
int len =__lg(r-l+1);
if(__gcd(f[r-(1<<len)+1][len],f[l][len]) == 1) l++;
else break;
}
res = max(res,r-l+2);
}
cout << res << endl;
}
signed main()
{
_orz;
int t;cin>>t;
while(t--) solve();
return 0;
}
版权声明
本文为[Bzdhxs_ nt]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210617219217.html
边栏推荐
- Fundamentals of SQL: first knowledge of database and SQL - installation and basic introduction - Alibaba cloud Tianchi
- JDBC operation transaction
- In depth source code analysis servlet first program
- EditorConfig
- PyTorch笔记——观察DataLoader&用torch构建LeNet处理CIFAR-10完整代码
- RPC must know and know
- Framework analysis 1 Introduction to system architecture
- Pytorch learning record (V): back propagation + gradient based optimizer (SGD, adagrad, rmsporp, Adam)
- 线代第四章-向量组的线性相关
- JDBC connection database
猜你喜欢
Font shape `OMX/cmex/m/n‘ in size <10.53937> not available (Font) size <10.95> substituted.
How to use comparative learning to do unsupervised - [cvpr22] training & [eccv20] image translation
Graphic numpy array matrix
Anaconda installed pyqt5 and pyqt5 tools without designer Exe problem solving
Contrôle automatique (version Han min)
LDCT图像重建论文——Eformer: Edge Enhancement based Transformer for Medical Image Denoising
Automatic control (Han min version)
Framework analysis 1 Introduction to system architecture
Linear algebra Chapter 1 - determinant
Pytoch -- data loading and processing
随机推荐
Unsupervised denoising - [tmi2022] ISCL: dependent self cooperative learning for unpaired image denoising
Pytorch learning record (III): structure of neural network + using sequential and module to define the model
Delete and truncate
线性代数第一章-行列式
如何利用对比学习做无监督——[CVPR22]Deraining&[ECCV20]Image Translation
Chapter 4 of line generation - linear correlation of vector systems
Event listener
Calculation (enter the calculation formula to get the result)
POI and easyexcel exercises
Solve the error: importerror: iprogress not found Please update jupyter and ipywidgets
Common sense of thread pool
7.Domino piling
RPC must know and know
Techniques et principes de détection
Class loading and classloader understanding
Common programming records - parser = argparse ArgumentParser()
Linear algebra Chapter 1 - determinant
编程记录——图片旋转函数scipy.ndimage.rotate()的简单使用和效果观察
5.The Simple Problem
MySQL best practices for creating tables