QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#633819 | #9250. Max GCD | 11d10xy | TL | 820ms | 149372kb | C++14 | 1.2kb | 2024-10-12 16:15:42 | 2024-10-12 16:15:42 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
constexpr int V=1000000;
int n,m,a[150010],ans[100010];
vector<int>divisor[1000010],pos[1000010];
struct Q_{int l,i;};
vector<Q_>q[150010];
vector<pair<int,int>>pr[150010];
namespace ds{
int mx[150010];
inline void ins(int p,int v){
for(p=n-p+1;p<=n;p+=p&-p)mx[p]=max(mx[p],v);
}
inline int ask(int p){
int res=0;
for(p=n-p+1;p;p-=p&-p)res=max(res,mx[p]);
return res;
}
}
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1,l,r;i<=m;i++){
scanf("%d%d",&l,&r);
q[r].push_back({l,i});
}
for(int i=1;i<=V;i++)for(int j=i;j<=V;j+=i)divisor[j].push_back(i);
for(int i=1;i<=n;i++)for(int d:divisor[a[i]])pos[d].push_back(i);
for(int i=1;i<=V;i++){
for(int j=1;j<pos[i].size();j++){
auto it=lower_bound(begin(pos[i]),end(pos[i]),pos[i][j]+pos[i][j]-pos[i][j-1]);
if(it!=end(pos[i]))pr[*it].emplace_back(pos[i][j-1],i);
}
}
for(int i=1;i<=n;i++){
for(auto X:pr[i])ds::ins(X.first,X.second);
for(Q_ x:q[i])ans[x.i]=ds::ask(x.l);
}
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: 820ms
memory: 149372kb
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
Time Limit Exceeded
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...