QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#559819 | #9250. Max GCD | yhddd | WA | 1108ms | 936532kb | C++20 | 1.9kb | 2024-09-12 09:33:36 | 2024-09-12 09:33:36 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
using namespace std;
const int maxn=150010;
const int maxm=1000010;
const int inf=1e18;
inline int read(){
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
return x*f;
}
bool Mbe;
int n,q,B;
vector<int> a[maxm];
vector<pii> upd[maxn];
int id[maxn],pl[maxn],pr[maxn];
struct ask{
int l,r,id;
}que[maxn];
int ans[maxn],mx[maxn],mx1[maxn];
void work(){
n=read();q=read();B=500;
for(int i=1;i<=n;i++){
int x=read();
for(int j=1;j*j<=x;j++)if(x%j==0){
a[j].pb(i);
if(j*j!=x)a[x/j].pb(i);
}
}
for(int i=1;i<=maxn-10;i++)if(a[i].size()>2){
// cout<<i<<" "<<a[i].size()<<endl;
for(int j=(int)a[i].size()-2,k=a[i].size();j;j--){
while(k>j&&a[i][k-1]-a[i][j]>=a[i][j]-a[i][j-1])k--;
// cout<<i<<" "<<j<<" "<<k<<endl;
if(k<a[i].size())upd[a[i][j-1]].pb({a[i][k],i});
}
}
for(int l=1,r,num=0;l<=n;l=r+1){
r=min(n,l+B-1);++num;
pl[num]=l,pr[num]=r;
for(int j=l;j<=r;j++)id[j]=num;
}
for(int i=1;i<=q;i++)que[i]={read(),read(),i};
sort(que+1,que+q+1,[&](ask u,ask v){return u.l>v.l;});
for(int i=1,p=n;i<=q;i++){
while(p>=que[i].l){
for(auto[r,v]:upd[p])mx[r]=max(mx[r],v),mx1[id[r]]=max(mx1[id[r]],v);
p--;
}
for(int j=id[que[i].l];j<=id[que[i].r]-1;j++)ans[que[i].id]=max(ans[que[i].id],mx1[j]);
for(int j=pl[id[que[i].r]];j<=que[i].r;j++)ans[que[i].id]=max(ans[que[i].id],mx[j]);
}
for(int i=1;i<=q;i++)printf("%lld\n",ans[i]);
}
// \
444
bool Med;
int T;
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
// ios::sync_with_stdio(0);
// cin.tie(0);cout.tie(0);
// cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
T=1;
while(T--)work();
}
詳細信息
Test #1:
score: 100
Accepted
time: 3ms
memory: 10048kb
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: 1108ms
memory: 936532kb
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:
147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840 147840...
result:
wrong answer 1st words differ - expected: '997920', found: '147840'