QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#634028#9250. Max GCD11d10xyWA 1027ms301340kbC++141.3kb2024-10-12 16:35:232024-10-12 16:35:24

Judging History

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

  • [2024-10-12 16:35:24]
  • 评测
  • 测评结果:WA
  • 用时:1027ms
  • 内存:301340kb
  • [2024-10-12 16:35:23]
  • 提交

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],bmx[400];
inline void ins(int p,int v){
   mx[p]=max(mx[p],v),bmx[p/400]=max(bmx[p/400],v);
}
inline int ask(int p){
   int res=0;
   for(int i=p;i/400==p/400;i++)res=max(res,mx[i]);
   for(int i=p/400+1;i<=n/400;i++)res=max(res,bmx[i]);
   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);
   if(n>100)return 0;
   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: 821ms
memory: 148696kb

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: 1027ms
memory: 301340kb

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:


result:

wrong answer Unexpected EOF in the participants output