QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#310225 | #6405. Barkley | PlentyOfPenalty# | WA | 1ms | 15908kb | C++20 | 1.4kb | 2024-01-21 09:07:42 | 2024-01-21 09:07:43 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5;
int n,Q,lg[N+10];
int a[N+10],ql,qr,qk,sz[N+10],ar[N+10][70];
ll g[20][N+10],gp[N+10][70],ls,tmp;
ll _gcd(ll l,ll r){
if(l>r)return 0;
int k=lg[r-l+1];
return gcd(g[k][l],g[k][r-(1<<k)+1]);
}
ll Que(int l,int r,int k,ll tg){
//cout<<"QUE "<<l<<" "<<r<<" "<<k<<" "<<tg<<"\n";
if(r-l<k)return -1;
if(k==1){
ll ret=gcd(tg,_gcd(l+1,r)),t;
for(int i=2;i<=sz[l];++i){
t=gcd(gp[l][i-1],_gcd(ar[l][i]+1,r));
//cout<<"P="<<ar[l][i]<<",t="<<t<<"\n";
ret=max(ret,gcd(tg,t));
}
return ret;
}
ll ret=Que(l+1,r,k-1,tg);
for(int i=2;i<=sz[l];++i){
ret=max(ret,Que(ar[l][i]+1,r,k-1,gcd(tg,gp[l][i-1])));
}
return ret;
}
int main(){
cin.sync_with_stdio(0),cin.tie(0);
cin>>n>>Q;
for(int i=2;i<=n;++i)lg[i]=lg[i>>1]+1;
for(int i=1;i<=n;++i)cin>>a[i],g[0][i]=a[i];
for(int i=1;i<=lg[n];++i)for(int j=1;j+(1<<i)-1<=n;++j)g[i][j]=gcd(g[i-1][j],g[i-1][j+(1<<i-1)]);
ar[n][sz[n]=1]=n,gp[n][1]=a[n];
for(int i=n-1;i>=1;--i){
ar[i][sz[i]=1]=i,gp[i][1]=a[i],ls=a[i];
for(int j=1;j<=sz[i+1];++j){
if(ls!=(tmp=gcd(a[i],gp[i+1][j]))){
ar[i][++sz[i]]=ar[i+1][j],gp[i][sz[i]]=tmp,ls=tmp;
}
}
//cout<<"AR "<<i<<":\n";
//for(int j=1;j<=sz[i];++j)cout<<"("<<ar[i][j]<<","<<gp[i][j]<<")\n";
}
while(Q--){
cin>>ql>>qr>>qk;
cout<<Que(ql,qr,qk,0)<<"\n";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9716kb
input:
4 4 3 2 6 4 1 3 1 2 4 1 1 4 2 1 4 3
output:
3 2 3 6
result:
ok 4 number(s): "3 2 3 6"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 15908kb
input:
100 10000 7 25 33 17 13 33 24 29 11 1 3 19 2 20 33 23 14 24 15 12 3 1 5 13 6 35 15 21 10 34 31 19 7 33 17 26 26 1 19 21 31 5 29 20 18 32 19 18 19 31 11 26 6 19 2 26 23 1 4 2 31 21 29 30 1 14 20 23 14 32 4 34 13 29 5 26 24 29 28 5 26 26 21 19 2 33 2 31 30 3 23 24 26 32 36 21 21 11 5 9 56 57 1 90 97 1...
output:
26 1 1 1 1 1 1 1 31 1 1 1 1 1 26 1 1 1 1 1 1 29 1 1 1 1 1 1 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 21 1 1 1 1 1 19 1 1 1 21 1 1 1 1 1 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 3 1 2 1 26 1 1 1 1 1 1 1 7 1 1 1 33 1 1 1 1 1 1 2 1 26 1 1 1 2 1 1 1 1 1 1 26 1 1 1 1 31 1 1 2 1 4 29 1 2 1 1...
result:
wrong answer 945th numbers differ - expected: '2', found: '1'