QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#555716#9250. Max GCDANewZhiyangfanWA 1150ms614340kbC++141.8kb2024-09-10 08:37:522024-09-10 08:37:52

Judging History

你现在查看的是最新测评结果

  • [2024-09-10 08:37:52]
  • 评测
  • 测评结果:WA
  • 用时:1150ms
  • 内存:614340kb
  • [2024-09-10 08:37:52]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
template <typename T>inline void read(T &x)
{
    x=0;char c=getchar();bool f=0;
    for(;c<'0'||c>'9';c=getchar())f|=(c=='-');
    for(;c>='0'&&c<='9';c=getchar())x=(x<<1)+(x<<3)+(c-'0');
    x=(f?-x:x);
}
const int N = 2e5+7;
int n,m,a[N];
const int M  = 1e6+7;
vector<pair<int,int> >upd[N],qry[N];
int seq[N],tot=0,c[N];
int mx[N],b[N];
void mod(int x,int v)
{
    mx[x>>8]=max(mx[x<<8],v);
    b[x]=max(b[x],v);
}
int ask(int x)
{
    int res=0;
    for(int i=(x>>8)+1;i<=(n>>8);i++)res=max(res,mx[i]);
    for(int i=x;(i>>8)==(x>>8);i++)res=max(res,b[i]);
    return res;
}
int ans[N];
vector<int> factor[M],vec[M];
int main()
{
    //freopen("a.in","r",stdin);
    read(n);read(m);
    for(int i=1;i<=n;i++)
    {
        read(a[i]);
    }
    for(int d=1;d<=1e6;d++)
    for(int t=d;t<=1e6;t+=d)
        factor[t].push_back(d);
    for(int i=1;i<=n;i++)
    {
        for(int d:factor[a[i]])
        vec[d].push_back(i);
    }
    for(int d=1;d<=1e6;d++)if(vec[d].size()>=3)
    {
        tot=0;
        for(int i:vec[d])seq[++tot]=i;
        int k=tot+1,mn=1e9;
        for(int i=tot-2;i>=1;i--)
        {
            int p=seq[i+1]+seq[i+1]-seq[i];
            if(p>=mn)continue;
            mn=p;
            while(seq[k-1]>=mn)k--;
            if(k<=tot)
            {
                upd[seq[k]].push_back(make_pair(seq[i],d));
            }
        }
    }
    for(int i=1;i<=m;i++)
    {
        int l,r;
        read(l);read(r);
        qry[r].push_back(make_pair(l,i));
    }
    if(n>8)exit(0);
    for(int i=1;i<=n;i++)
    {
        for(auto u:upd[i])
        mod(u.first,u.second);
        for(auto u:qry[i])
        ans[u.second]=ask(u.first);
    }
    for(int i=1;i<=m;i++)printf("%d\n",ans[i]);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 497ms
memory: 155352kb

input:

8 8
8 24 4 6 6 7 3 3
1 5
2 6
3 7
5 8
4 8
1 3
2 5
3 8

output:

4
2
3
1
3
4
2
3

result:

ok 8 tokens

Test #2:

score: -100
Wrong Answer
time: 1150ms
memory: 614340kb

input:

150000 100000
982800 554400 665280 982800 997920 720720 786240 831600 997920 982800 786240 982800 942480 831600 887040 665280 831600 960960 786240 982800 786240 942480 665280 831600 942480 665280 982800 960960 960960 997920 720720 960960 960960 665280 982800 665280 982800 942480 786240 997920 554400...

output:


result:

wrong answer Unexpected EOF in the participants output