QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#625565 | #9426. Relearn through Review | Emotion_Z | Compile Error | / | / | C++20 | 3.6kb | 2024-10-09 19:53:16 | 2024-10-09 19:53:18 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int __int128
#define deg( x ) cerr<<""#x"="<<x<<endl
#define endl '\n'
const int N=3e5+10;
istream &operator>>( istream &in , __int128 &n ){
string s; in>>s;
n=0;
for(char i:s) n=n*10+i-'0';
return in;
}
ostream &operator<<( ostream &out , __int128 n ){
if( n==0 ){
out<<0;
return out;
}
string s;
while( n ){
s+='0'+n%10;
n/=10;
}
reverse( s.begin( ) , s.end( ) );
out<<s;
return out;
}
int idn=0;
int fan[ N ];
int A[ N ];
int up[ N ];
int ne[ N ];
void solve(){
int n,k;
cin>>n>>k;
A[ n+1 ]=0;
for( int i=1; i<=n; i++ ){
cin>>A[ i ];
}
for( int i=1; i<=n; i++ ){
up[ i ]=gcd( up[ i-1 ] , A[ i ] );
}
for( int i=n; i>=1; i-- ){
ne[ i ]=gcd( ne[ i+1 ] , A[ i ] );
}
int ans=0;
int cnt=0;
int cnt2=0;
for( int i=1; i<=n; i++ ){
cnt=gcd( cnt , A[ i ] );
cnt2=gcd( cnt2 , A[ i ]+k );
}
ans=max( max( cnt , cnt2 ) , ans );
cnt=0;
for( int i=1; i<=n; i++ ){
ans=max( ans , gcd( cnt , ne[ i ] ) );
cnt=gcd( cnt , A[ i ]+k );
}
cnt=0;
for( int i=n; i>=1; i-- ){
ans=max( ans , gcd( up[ i ] , cnt ) );
cnt=gcd( cnt , A[ i ]+k );
}
/*
// vector<int> V;
// V.emplace_back( 0 );
//
// int e=1;
// while( e<=n ){
// int te=A[ e ];
// while( A[ e ]==te ){
// e++;
// if( e==n+1 ) break;
// }
// V.emplace_back( te );
// }
//
// n=V.size()-1;
// for( int l=1; l<=min( n , 1ll+50 ); l++ ){
// cnt=0;
// for( int o=1; o<l; o++ ) cnt=gcd( cnt , V[ o ] );
// for( int r=max( l+1 , n-50 ); r<=n; r++ ){
// int te=cnt;
// for( int o=l; o<=r; o++ ){
// te=gcd( te , V[ o ]+k );
// }
// for( int o=r+1; o<=n; o++ ) te=gcd( te , V[ o ] );
//
// ans=max( ans , te );
// }
// }
*/
int te=gcd( A[ 1 ] , A[ n ] );
vector<int> V;
int oo=te;
for( int i=1; i<=n; i++ ){
oo=gcd( oo , A[ i ] );
V.emplace_back( oo );
}
oo=te;
for( int i=n; i>=1; i-- ){
oo=gcd( oo , A[ i ] );
V.emplace_back( oo );
}
sort( V.begin() , V.end() );
V.erase( unique( V.begin() , V.end() ) , V.end() );
idn=0;
for( auto x:V ){
fan[ ++idn ]=x;
}
for( int i=idn; i>=1; i-- ){
int now=fan[ i ];
bool ok=false;
int l=1;
for( ; l<=n; l++ ){
if( A[ l ]%now != 0 ){
if( ( A[ l ]+k )%now == 0 ) break;
else{
ok=true;
break;
}
}
}
if( ok ) continue;
int r=l+1;
for( ; r<=n; r++ ){
if( ( A[ r ]+k )%now!=0 ){
if( A[ r ]%now==0 ) break;
else{
ok=true;
break;
}
}
}
if( ok ) continue;
for( int e=r; e<=n; e++ ){
if( A[ e ]%now!=0 ){
ok=true;
break;
}
}
if( ok ) continue;
ans=max( ans , now );
}
cout<<ans<<endl;
}
signed main() {
ios::sync_with_stdio( 0 );
cin.tie( 0 ); cout.tie( 0 );
int T=1;
cin>>T;
while( T-- ){
solve();
}
return 0;
}
详细
In file included from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:58, from answer.code:1: /usr/include/c++/13/numeric: In instantiation of ‘constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn) [with _Mn = __int128; _Nn = __int128; common_type_t<_Tp1, _Tp2> = __int128]’: answer.code:54:20: required from here /usr/include/c++/13/numeric:166:21: error: static assertion failed: std::gcd arguments must be integers 166 | static_assert(is_integral_v<_Mn> && is_integral_v<_Nn>, | ^~~~~~~~~~~~~~~~~~ /usr/include/c++/13/numeric:166:21: note: ‘std::is_integral_v<__int128>’ evaluates to false In file included from /usr/include/c++/13/bits/stl_pair.h:60, from /usr/include/c++/13/bits/stl_algobase.h:64, from /usr/include/c++/13/algorithm:60, from /usr/include/x86_64-linux-gnu/c++/13/bits/stdc++.h:51: /usr/include/c++/13/type_traits: In instantiation of ‘struct std::make_unsigned<__int128>’: /usr/include/c++/13/type_traits:1983:11: required by substitution of ‘template<class _Tp> using std::make_unsigned_t = typename std::make_unsigned::type [with _Tp = __int128]’ /usr/include/c++/13/numeric:173:24: required from ‘constexpr std::common_type_t<_Tp1, _Tp2> std::gcd(_Mn, _Nn) [with _Mn = __int128; _Nn = __int128; common_type_t<_Tp1, _Tp2> = __int128]’ answer.code:54:20: required from here /usr/include/c++/13/type_traits:1836:62: error: invalid use of incomplete type ‘class std::__make_unsigned_selector<__int128, false, false>’ 1836 | { typedef typename __make_unsigned_selector<_Tp>::__type type; }; | ^~~~ /usr/include/c++/13/type_traits:1744:11: note: declaration of ‘class std::__make_unsigned_selector<__int128, false, false>’ 1744 | class __make_unsigned_selector; | ^~~~~~~~~~~~~~~~~~~~~~~~