QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#516540 | #6405. Barkley | louhao088 | WA | 3ms | 5860kb | C++23 | 1.5kb | 2024-08-12 18:06:38 | 2024-08-12 18:06:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pi pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define ls (rt<<1)
#define rs (rt<<1|1)
#define lowbit(i) (i&(-i))
#define mid ((l+r)>>1)
#define int long long
inline int read(){
char ch=getchar();int x=0;bool f=0;
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=1;
for(;isdigit(ch);ch=getchar())x=(x<<1)+(x<<3)+(ch^48);
if(f==1)x=-x;return x;
}
const int maxn=1e5+5,M=(1<<30)-1;
int n,m,a[maxn],f[maxn][21],l,r,k,q,lg[maxn];
int gcd(int x,int y){
if(!x||!y)return x+y;
if(y>x)swap(x,y);
return gcd(y,x%y);
}
int get(int l,int r){
if(l>r)return 0;
int p=lg[r-l+1];
return gcd(f[l][p],f[r-(1<<p)+1][p]);
}
int solve(int l,int r,int k,int G){
int res=0;
//cout<<l<<" "<<r<<" "<<G<<" "<<get(l,r)<<endl;
if(k==0)return gcd(get(l,r),G);
res=max(res,solve(l+1,r,k-1,G));
if(!G)G=a[l];
int u=l;
while(true){
for(int i=20;i>=0;i--)
if(f[u][i]%G==0&&f[u][i]){
u=u+(1<<i);
}
if(u>r)break;
res=max(res,solve(u+1,r,k-1,G));
G=gcd(G,a[u]);
}res=max(res,get(l,r));
return res;
}
signed main(){
n=read();q=read();lg[1]=0;
for(int i=2;i<=n;i++)lg[i]=lg[i/2]+1;
for(int i=1;i<=n;i++)a[i]=read(),f[i][0]=a[i];
for(int i=1;i<=20;i++)
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]);
for(int i=1;i<=q;i++){
l=read(),r=read(),k=read();
//for(int i=l;i<=r;i++)cout<<a[i]<<" ";cout<<endl;
printf("%lld\n",solve(l,r,k,0));
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5860kb
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: 3ms
memory: 5848kb
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 6063rd numbers differ - expected: '3', found: '5'