QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#550542 | #9250. Max GCD | ucup-team1004# | WA | 1488ms | 509212kb | C++14 | 1.7kb | 2024-09-07 13:23:04 | 2024-09-07 13:23:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
const int N=1.5e5+10,M=1e6+10;
int n,m,a[N];
int cnt,pri[M],vis[M],mn[M];
void init(int n=M-1){
for(int i=2;i<=n;i++){
if(!vis[i])pri[++cnt]=i,mn[i]=i;
for(int j=1;j<=cnt&&i*pri[j]<=n;j++){
vis[i*pri[j]]=1;
mn[i*pri[j]]=pri[j];
if(i%pri[j]==0)break;
}
}
}
vector<int>pos[M];
vector<pair<int,int>>o[N],q[N];
int c[N],ans[N];
void add(int x,int y){
for(;x<=n;x+=x&-x)c[x]=max(c[x],y);
}
int get(int x,int y=0){
for(;x;x^=x&-x)y=max(y,c[x]);
return y;
}
int main(){
scanf("%d%d",&n,&m),init();
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
int x=a[i];
vector<int>t;
for(;x>1;x/=mn[x])t.push_back(mn[x]);
function<void(int,int)>dfs=[&](int l,int cur){
if(l==t.size())return pos[cur].push_back(i);
int r=l+1;
for(;r<t.size()&&t[l]==t[r];r++);
for(int i=l;i<=r;i++)dfs(r,cur),cur*=t[l];
};
dfs(0,1);
}
for(int i=1,l,r;i<=m;i++){
scanf("%d%d",&l,&r);
if(r-l<=1){
continue;
}
q[l].push_back({r,i});
}
for(int i=1;i<M;i++){
if(pos[i].empty())continue;
for(int j=1,x=0;j+1<pos[i].size();j++){
for(;x<pos[i].size()&&pos[i][x]-pos[i][j]<pos[i][j]-pos[i][j-1];x++);
if(x<pos[i].size())o[pos[i][j-1]].push_back({pos[i][x],i});
}
}
for(int i=n;i>=1;i--){
for(auto [x,w]:o[i])add(x,w);
for(auto [x,id]:q[i])ans[id]=get(x);
}
for(int i=1;i<=m;i++)printf("%d\n",ans[i]);
return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 13ms
memory: 43512kb
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: 1488ms
memory: 509212kb
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 5108th words differ - expected: '997920', found: '982800'