QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#606043 | #9250. Max GCD | Coffins | WA | 2832ms | 819316kb | C++14 | 2.0kb | 2024-10-02 21:48:16 | 2024-10-02 21:48:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=15e4+5,V=1e6+5;
using pii=pair<int,int>;
int n,q,a[N],pr[V];
vector<pii> qr[N],mf[N],vc[N];
int d[N<<2],ans[N];
void build(int l,int r,int k)
{
if(l==r)return d[k]=0,void();
int mid=(l+r)>>1;
build(l,mid,k<<1),build(mid+1,r,k<<1|1);
d[k]=max(d[k<<1],d[k<<1|1]);
}void modify(int p,int v,int l,int r,int k)
{
if(l==r)return d[k]=max(v,d[k]),void();
int mid=(l+r)>>1;
if(p<=mid)modify(p,v,l,mid,k<<1);
else modify(p,v,mid+1,r,k<<1|1);
d[k]=max(d[k<<1],d[k<<1|1]);
}int query(int a,int b,int l,int r,int k)
{
if(a<=l&&r<=b)return d[k];
int mid=(l+r)>>1,ans=1;
if(a<=mid)ans=max(ans,query(a,b,l,mid,k<<1));
if(mid+1<=b)ans=max(ans,query(a,b,mid+1,r,k<<1|1));
return ans;
}int main()
{
ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin>>n>>q;for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=q;i++)
{
int l,r;cin>>l>>r;
qr[r].push_back({l,i});
}for(int i=1;i<=n;i++)
{
for(int j=1;j*j<=a[i];j++)
{
if(a[i]%j)continue;int p=pr[j];
if(p&&2*i-p<=n)vc[2*i-p].push_back({p,j});
pr[j]=i;if(j*j==a[i])break;
p=pr[a[i]/j];if(p&&2*i-p<=n)
vc[2*i-p].push_back({p,a[i]/j});
pr[a[i]/j]=i;
}
}for(int i=1;i<V;i++)pr[i]=0;
for(int i=n;i>=1;i--)
{
for(int j=1;j*j<=a[i];j++)
if(a[i]%j==0)
pr[j]=pr[a[i]/j]=i;
for(auto el:vc[i])
{
int l=el.first;
int vl=el.second;if(pr[vl])
mf[pr[vl]].push_back({l,vl});
}
}for(int r=1;r<=n;r++)
{
for(auto el:mf[r])
{
int l=el.first;
int vl=el.second;
modify(l,vl,1,n,1);
}for(auto el:qr[r])
{
int l=el.first;
int id=el.second;
ans[id]=query(l,r,1,n,1);
}
}for(int i=1;i<=q;i++)cout<<ans[i]<<'\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 18628kb
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: 2832ms
memory: 819316kb
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:
wrong answer 1518th words differ - expected: '0', found: '1'