QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#633774#9250. Max GCD11d10xyRE 0ms0kbC++141.2kb2024-10-12 16:11:042024-10-12 16:11:10

Judging History

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

  • [2024-10-12 16:11:10]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-10-12 16:11:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
constexpr int V=1000010;
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: 0
Runtime Error

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:


result: