QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#246510 | #6405. Barkley | ztxcsl | WA | 1ms | 5676kb | C++14 | 1.5kb | 2023-11-10 21:26:49 | 2023-11-10 21:26:50 |
Judging History
answer
#include <iostream>
using namespace std;
typedef long long ll;
const int MAXN=100000;
ll gcd(ll a,ll b){
if(b==0)return a;
else return gcd(b,a%b);
}
int n,q;
ll a[MAXN+5];
struct ST{
ll f[MAXN+5][21];
int lg[MAXN+5];
void build(ll a[],int n){
lg[0]=-1;
for(int i=1;i<=n;i++){
lg[i]=lg[i/2]+1;
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]);
}
}
}
ll calc(int l,int r){
int k=lg[r-l+1];
return gcd(f[l][k],f[r-(1<<k)+1][k]);
}
}st;
ll calc(int l,int r,int k,ll t){
if(r-l+1<=k)return t;
if(k==0){
return gcd(st.calc(l,r),t);
}
ll cur=gcd(a[l],t),ans=calc(l+1,r,k-1,t);
for(int i=l;i<=r;i++){
int L=i,R=r;
while(L<R){
int mid=(L+R+1)/2;
if(gcd(cur,st.calc(i,mid))==cur){
L=mid;
}else{
R=mid-1;
}
}
ans=max(ans,gcd(calc(L+2,r,k-1,cur),cur));
cur=gcd(cur,a[L+1]);
i=L+1;
}
return ans;
}
int main(){
ios::sync_with_stdio(false);
cin>>n>>q;
for(int i=1;i<=n;i++){
cin>>a[i];
}
st.build(a,n);
while(q--){
int l,r,k;cin>>l>>r>>k;
cout<<calc(l,r,k,0)<<endl;
}
return 0;
}/*4 4
3 2 6 4
1 3 1*/
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5676kb
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: 3640kb
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 3 1 1 1 1 26 1 1 1 1 1 1 29 1 1 1 1 1 1 4 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 2 4 1 1 1 21 1 1 3 1 1 19 1 1 1 21 1 1 1 1 1 2 1 1 1 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 4 2 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 2 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 10th numbers differ - expected: '1', found: '3'