QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#516532 | #6405. Barkley | louhao088 | WA | 12ms | 5880kb | C++23 | 1.5kb | 2024-08-12 18:02:11 | 2024-08-12 18:02:11 |
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[l][i]%G==0&&f[l][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,G);
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();
if(n==100)cout<<l<<" "<<r<<" "<<k<<endl;
printf("%lld\n",solve(l,r,k,0));
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5816kb
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: 12ms
memory: 5880kb
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:
56 57 1 26 90 97 1 1 81 89 1 1 39 45 1 1 56 64 1 1 49 54 1 1 28 34 1 1 63 70 1 1 49 50 1 31 20 23 1 3 97 99 1 1 21 25 1 1 57 63 1 1 95 100 1 3 37 38 1 26 6 11 1 3 39 46 1 1 56 65 1 1 57 67 2 1 23 30 1 1 90 95 1 1 7 8 1 29 9 11 1 1 33 37 1 1 74 78 1 1 39 46 1 1 39 47 1 1 9 11 1 1 93 95 1 4 29 37 1 1 ...
result:
wrong answer 1st numbers differ - expected: '26', found: '56'