QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#516526 | #6405. Barkley | louhao088 | WA | 1ms | 5856kb | C++23 | 1.4kb | 2024-08-12 17:56:38 | 2024-08-12 17:56:40 |
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){
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;
if(k==0)return get(l,r);
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){
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();
printf("%lld\n",solve(l,r,k,0));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5844kb
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: 5856kb
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 3 26 19 26 19 21 29 31 12 21 3 23 36 26 33 19 26 23 5 3 29 11 7 29 19 19 11 26 10 26 19 32 24 14 21 19 14 33 15 21 10 26 1 10 31 23 32 26 33 10 21 15 26 30 1 23 19 14 21 31 36 17 19 23 19 29 10 2 2 17 2 11 2 14 21 1 5 21 18 20 19 26 26 33 19 32 10 4 25 23 17 30 23 14 7 26 29 7 29 33 2 13 21 35 18...
result:
wrong answer 2nd numbers differ - expected: '1', found: '3'