QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#682621#9250. Max GCDlouhao088RE 1524ms617004kbC++981.5kb2024-10-27 16:29:312024-10-27 16:29:31

Judging History

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

  • [2024-10-27 16:29:31]
  • 评测
  • 测评结果:RE
  • 用时:1524ms
  • 内存:617004kb
  • [2024-10-27 16:29:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;

typedef pair<int,int> pr;

const int MAXN=1.5e5,MAXQ=1e5,MAXA=1e6,S=387;

int n,q,ans[MAXQ+5];
vector<int> fac[MAXA+5],loc[MAXA+5];
vector<pr> ope[MAXN+5],qry[MAXN+5];

inline void Init()
{
    for(int i=1;i<=MAXA;i++)
        for(int j=i;j<=MAXA;j+=i)
            fac[j].push_back(i);
}

int maxn[MAXN+5],Maxn[S+5],Bloc[MAXN+5];
inline void Modify(int x,int v) {maxn[x]=max(maxn[x],v),Maxn[Bloc[x]]=max(Maxn[Bloc[x]],v);}
inline int GetMax(int L,int R)
{
	int res=0;
	for(int i=Bloc[L];i<Bloc[R];i++) res=max(res,Maxn[i]);
	for(int i=(Bloc[R]-1)*S+1;i<=R;i++) res=max(res,maxn[i]);
	return res;
}

int main()
{
    Init();
    scanf("%d %d",&n,&q);
    for(int i=1,A;i<=n;i++)
	{
		scanf("%d",&A);
		for(int j=0;j<fac[A].size();j++) loc[fac[A][j]].push_back(i);
	}
	for(int i=1;i<=MAXA;i++)
		for(int j=(int)loc[i].size()-2,k=loc[i].size();j>=0;j--)
		{
			int x=2*loc[i][j+1]-loc[i][j];
			while(k && loc[i][k-1]>=x) --k;
			if(loc[i][k]>=x) ope[loc[i][j]].push_back(make_pair(loc[i][k],i));
		}
	for(int i=1,L,R;i<=q;i++) scanf("%d %d",&L,&R),qry[L].push_back(make_pair(R,i));
	for(int i=1,L=1,R;L<=n;i++,L=R+1)
	{
		R=min(L+S-1,n);
		for(int j=L;j<=R;j++) Bloc[j]=i;
	}
	for(int i=n;i;i--)
	{
		for(int j=0;j<ope[i].size();j++) Modify(ope[i][j].first,ope[i][j].second);
		for(int j=0;j<qry[i].size();j++) ans[qry[i][j].second]=GetMax(i,qry[i][j].first);
	}
	for(int i=1;i<=q;i++) printf("%d\n",ans[i]);
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 677ms
memory: 149480kb

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: 0
Accepted
time: 1524ms
memory: 617004kb

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:

997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920...

result:

ok 100000 tokens

Test #3:

score: -100
Runtime Error

input:

150000 100000
716844 340255 836453 422971 389959 56166 837543 724949 336855 860372 579302 812222 849774 845846 999555 136871 624002 100905 529143 187215 582397 95964 363772 534762 258007 132867 753342 300681 770692 654005 397230 267857 21953 347450 248776 397101 768172 868404 612257 885884 270063 45...

output:


result: