Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Problem link :
- //CREDITS : sanath kumar
- #include<bits/stdc++.h>
- using namespace std;
- #define ll long long int
- #define ld long double
- #define mod 1000000007
- #define inf 1e9
- #define endl "\n"
- #define pb push_back
- #define vi vector<ll>
- #define vs vector<string>
- #define pii pair<ll,ll>
- #define ump unordered_map
- #define mp make_pair
- #define pq_max priority_queue<ll>
- #define pq_min priority_queue<ll,vector<ll>,greater<ll>>
- #define all(v) v.begin(),v.end()
- #define ff first
- #define ss second
- #define mid(l,r) (l+(r-l))/2
- #define bitc(x) __builtin_popcount(x)
- #define read(a,n) for(int i=0;i<n;i++) cin>>a[i];
- #define loop(i,a,b) for(int i=(a);i<=(b);i++)
- #define looprev(i,a,b) for(int i=(a);i>=(b);i--)
- #define iter(c,it) for(__typeof(c.begin()) it=c.begin();it!=c.end();it++)
- #define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
- #define log(args...) {string _s=#args;replace(_s.begin(),_s.end(),',',' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
- #define logarr(arr,a,b) for(int z=(a);z<=(b);z++) cout<<(arr[z])<<" ";cout<<endl;
- template<typename T> void shiftr(T *arr,int n){for(int i=n;i>=1;i--) arr[i]=arr[i-1];arr[0]=0;}
- template<typename T> T gcd(T a,T b) {if(b==0) return a; return gcd(b,a%b);}
- template<typename T> T lcm(T a,T b) {return a*(b/gcd(a,b));}
- template<class T> T add(T a,T b) {return ((a%mod)+(b%mod))%mod;}
- template<class T> T sub(T a,T b) {return ((a%mod)-(b%mod)+mod)%mod;}
- template<class T> T mul(T a,T b) {return ((a%mod)*(b%mod)*(1LL))%mod;}
- template<class T> void debug(set<T> S){cout<<"[ ";for(auto i:S) cout<<i<<" ";cout<<"] "<<endl;}
- template<class T> void debug(vector<ll> v){cout<<"[ ";for(auto i:v) cout<<i<<" ";cout<<"] "<<endl;}
- template<class T> void debug(multiset<T> S){cout<<"[ ";for(auto i:S) cout<<i<<" ";cout<<"] "<<endl;}
- template<class T> void debug(unordered_set<T> S){cout<<"[ ";for(auto i:S) cout<<i<<" ";cout<<"] "<<endl;}
- template<class T,class X> void debug(T *arr,X s,X e){cout<<"[ ";loop(i,s,e) cout<<arr[i]<<" ";cout<<"] "<<endl;}
- template<class T,class V> void debug(pair<T,V> p){cout<<"{";cout<<p.ff<<" "<<p.ss<<"}"<<endl;}
- template<class T,class V> void debug(vector<pair<T,V>> v){cout<<"[ "<<endl;for(auto i:v) debug(i);cout<<"]"<<endl;}
- void err(istream_iterator<string> it){}
- template<typename T,typename... Args>
- void err(istream_iterator<string> it,T a,Args... args){
- cout<<*it<<" = "<<a<<endl;
- err(++it,args...);
- }
- ll *getfactorial(){
- int m=1e6;
- ll *fact=new ll[m+1];
- fact[0]=1;
- loop(i,1,m){
- fact[i]=(fact[i-1]*i)%mod;
- }
- // time complexity O(n)
- return fact;
- }
- vi *getfactors(){
- int n=2e5;
- vi *factors=new vi[n+5];
- loop(i,1,n){
- for(int j=i;j<=n;j+=i){
- factors[j].pb(i);
- }
- }
- // time complexity O(nlogn)
- return factors;
- }
- ll power(ll a,ll b,ll m=mod){
- if(b==0) return 1;
- ll smallans=power(a,b/2,m);
- ll ans=(smallans*smallans)%m;
- if(b%2==1){
- ans=(ans*a)%m;
- }
- return ans;
- // time complexity O(logb)
- }
- bool *isprime(){
- int m=1e6;
- bool *p=new bool[m];
- loop(i,0,m) p[i]=true;
- p[0]=false;
- p[1]=false;
- loop(i,2,sqrt(m)){
- for(int j=2*i;j<=m;j+=i){
- p[j]=false;
- }
- }
- // time complexity O(nlogn)
- return p;
- }
- ll nCr(ll n,ll r,int m=mod){
- if(n<r) return 0;
- ll *fac=getfactorial();
- ll ans=fac[n];
- ans=(ans*power(fac[n-r],m-2))%m;
- ans=(ans*power(fac[r],m-2))%m;
- return ans;
- }
- //==================START==================
- ll arr[200005],b[200005];
- int n;
- struct seg{
- ll tree[600005];
- void build(int s,int e,int tn){
- if(s==e){
- tree[tn]=b[s];
- return ;
- }
- int m=(s+e)/2;
- build(s,m,2*tn);
- build(m+1,e,2*tn+1);
- tree[tn]=gcd(tree[2*tn],tree[2*tn+1]);
- }
- ll query(int s,int e,int l,int r,int tn){
- if(s>=l and e<=r) return tree[tn];
- if(s>r or e<l) return 0;
- int m=(s+e)/2;
- ll a=query(s,m,l,r,2*tn);
- ll b=query(m+1,e,l,r,2*tn+1);
- return gcd(a,b);
- }
- };
- ll get(int i,struct seg &S){
- ll ans=0;
- ll l=i,r=n-1;
- while(l<=r){
- ll m=(l+r)/2;
- ll x=S.query(1,n-1,i,m,1);
- if(x>1){
- ans=max(ans,m-i+2);
- l=m+1;
- }
- else{
- r=m-1;
- }
- }
- return ans;
- }
- int main(){
- boost
- int t;
- cin>>t;
- while(t--){
- cin>>n;
- read(arr,n);
- shiftr(arr,n);
- loop(i,1,n-1) b[i]=abs(arr[i+1]-arr[i]);
- struct seg S;
- S.build(1,n-1,1);
- ll ans=0;
- loop(i,1,n-1){
- ans=max(ans,get(i,S));
- }
- cout<<ans<<endl;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment