QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#105668 | #6405. Barkley | zhouhuanyi | TL | 72ms | 21228kb | C++11 | 1.4kb | 2023-05-14 18:16:20 | 2023-05-14 18:16:24 |
Judging History
answer
#include<iostream>
#include<cstdio>
#define N 100000
#define inf 1e9
using namespace std;
long long read()
{
char c=0;
long long sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
long long gcd(long long x,long long y)
{
if (!y) return x;
return gcd(y,x%y);
}
int n,q,lg[N+1];
long long a[N+1],ST[N+1][21],ans;
long long query(int l,int r)
{
if (l>r) return 0;
int lw=lg[r-l+1];
return gcd(ST[l][lw],ST[r-(1<<lw)+1][lw]);
}
bool check(int l,int r,int d)
{
int lw=lg[r-l+1];
return ST[l][lw]%d==0&&ST[r-(1<<lw)+1][lw]%d==0;
}
void solve(int l,int r,int k,long long d)
{
if (!k)
{
ans=max(ans,gcd(d,query(l,r)));
return;
}
int x=l,y;
solve(l+1,r,k-1,d),d=gcd(d,a[l]);
while (x+k<=r)
{
y=x;
for (int i=lg[n];i>=0;--i)
if (y+(1<<i)<=r-k&&check(l,y+(1<<i),d))
y+=(1<<i);
solve(y+2,r,k-1,d),x=y+1,d=gcd(d,a[y+1]);
}
return;
}
int main()
{
int l,r,k;
for (int i=2;i<=N;++i) lg[i]=lg[i>>1]+1;
n=read(),q=read();
for (int i=1;i<=n;++i) a[i]=read(),ST[i][0]=a[i];
for (int i=1;i<=lg[n];++i)
for (int j=1;j+(1<<i)-1<=n;++j)
ST[j][i]=gcd(ST[j][i-1],ST[j+(1<<(i-1))][i-1]);
while (q--) ans=0,l=read(),r=read(),k=read(),solve(l,r,k,0),printf("%lld\n",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3868kb
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: 0
Accepted
time: 5ms
memory: 3888kb
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:
ok 10000 numbers
Test #3:
score: 0
Accepted
time: 27ms
memory: 4100kb
input:
1000 66666 25 21 18 19 9 34 16 7 36 2 8 10 25 15 34 9 1 34 6 19 20 20 1 16 10 6 10 1 30 34 6 15 15 11 9 4 34 36 27 17 2 2 19 10 4 22 15 16 22 36 27 26 20 23 29 16 27 14 3 31 32 16 5 5 31 13 27 5 17 23 20 19 13 22 30 14 25 13 7 16 10 6 1 6 3 5 36 1 33 22 31 26 28 3 14 14 2 31 35 7 19 30 36 5 3 14 14 ...
output:
1 2 1 1 1 1 1 1 1 1 1 3 1 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 17 1 1 1 20 1 1 1 7 1 1 1 1 1 1 1 1 3 1 1 1 1 1 1 7 1 2 15 1 3 1 2 1 1 3 4 1 1 1 1 1 31 1 1 1 2 1 1 1 1 27 3 1 1 1 1 4 10 1 1 1 1 17 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 8 1 1 17 1 2 1 1 1 30 1 25 1 35 1...
result:
ok 66666 numbers
Test #4:
score: 0
Accepted
time: 31ms
memory: 5580kb
input:
10000 66666 35 30 29 34 3 25 23 29 30 32 34 1 25 1 23 11 10 24 33 25 14 1 16 25 33 5 19 2 16 1 19 14 34 6 26 25 36 35 1 32 35 27 18 3 7 16 10 25 6 21 36 31 24 17 20 12 30 21 25 31 27 22 5 19 6 16 7 26 15 21 32 11 34 4 7 25 34 3 14 13 10 1 28 8 12 24 34 27 17 8 17 32 23 30 23 8 19 22 2 11 23 10 4 30 ...
output:
1 16 2 2 1 23 1 1 1 2 1 3 5 1 1 2 1 1 1 1 30 1 1 1 3 18 1 1 1 1 2 1 1 1 1 1 1 1 1 2 2 1 6 36 1 1 2 19 2 1 1 1 1 1 2 1 1 1 21 1 1 1 1 3 1 1 1 1 1 1 1 1 1 1 1 1 29 1 1 30 2 2 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 4 2 1 1 1 2 29 1 1 14 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 3 1 9 5 1 2 2 1 32 1 1 1 3 2 1 1 ...
result:
ok 66666 numbers
Test #5:
score: 0
Accepted
time: 72ms
memory: 21228kb
input:
100000 66666 7 27 21 15 35 19 32 8 1 30 6 3 33 29 25 5 1 24 34 9 13 27 9 32 20 26 5 10 1 30 29 15 11 31 12 27 10 32 14 30 27 6 16 17 16 36 12 35 18 4 14 9 12 33 1 10 27 31 16 27 16 15 6 16 28 16 26 6 25 23 23 31 22 16 30 33 15 2 27 11 18 23 3 2 23 2 13 17 21 15 4 2 19 22 35 35 13 28 9 30 20 29 17 5 ...
output:
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 7 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 29 1 1 1 1 1 1 1 1 1 1 1 35 3 1 1 20 1 1 1 1 1 1 1 1 1 2 1 1 2 1 1 19 1 1 1 1 1 1 1 1 1 1 1 1 1 1 25 1 1 1 1 1 1 2 13 1 9 25 1 1 1 1 1 1 1 1 2 1 1 1 25 1 18 4 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 23 1 1 1 1 1 33 2...
result:
ok 66666 numbers
Test #6:
score: -100
Time Limit Exceeded
input:
100000 66666 450283905890997363 450283905890997363 450283905890997363 450283905890997363 450283905890997363 450283905890997363 450283905890997363 450283905890997363 450283905890997363 450283905890997363 450283905890997363 450283905890997363 450283905890997363 450283905890997363 450283905890997363 45...