QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#104106 | #6405. Barkley | He_Ren | WA | 6ms | 3992kb | C++14 | 1.2kb | 2023-05-08 17:22:56 | 2023-05-08 17:22:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e5 + 5;
const int LB = 18 + 2;
const ll linf = 0x3f3f3f3f3f3f3f3f;
ll gcd(ll a,ll b){ return b? gcd(b,a%b): a;}
int lb[MAXN];
int n;
ll a[MAXN];
ll f[MAXN][LB];
ll getf(int l,int r)
{
int k = lb[r-l+1];
return gcd(f[l][k], f[r-(1<<k)+1][k]);
}
ll query(int l,int r,int k)
{
if(r-l+1 == k) return 0;
if(k == 0) return getf(l, r);
int lim = r - k, pos = l-1;
ll res = -linf, cur = 0;
while(1)
{
if(cur)
{
for(int i=lb[lim-pos]; i>=0 && pos<lim; --i)
if(i<=lb[lim-pos] && f[pos+1][i] % cur == 0)
pos += 1<<i;
}
res = max(res, gcd(cur, query(pos+2, r, k-1)));
if(pos == lim) break;
++pos;
cur = gcd(cur, a[pos]);
}
return res;
}
int main(void)
{
lb[0] = -1;
for(int i=1; i<MAXN; ++i)
lb[i] = lb[i>>1] + 1;
int Q;
scanf("%d%d",&n,&Q);
for(int i=1; i<=n; ++i)
scanf("%lld",&a[i]);
for(int i=n; i>=1; --i)
{
f[i][0] = a[i];
for(int j=1; i+(1<<j)-1<=n; ++j)
f[i][j] = gcd(f[i][j-1], f[i+(1<<(j-1))][j-1]);
}
while(Q--)
{
int l,r,k;
scanf("%d%d%d",&l,&r,&k);
printf("%lld\n",query(l,r,k));
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3992kb
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: 6ms
memory: 3944kb
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 7823rd numbers differ - expected: '2', found: '1'