QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#619768#9250. Max GCDucup-team5071#TL 38ms11716kbC++202.0kb2024-10-07 15:19:312024-10-07 15:19:38

Judging History

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

  • [2024-10-07 15:19:38]
  • 评测
  • 测评结果:TL
  • 用时:38ms
  • 内存:11716kb
  • [2024-10-07 15:19:31]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
const int maxn=1.5e5+10;
struct tree{
    int c[maxn];
    int n;
    void set_n(int _n){
        n=_n;
        for(int i=1;i<=n;i++)c[i]=1;
    }
    int lowbit(int x){
        return x&(-x);
    }
    void update(int x,int k){
        while(x<=n){
            c[x]=max(c[x],k);
            x+=lowbit(x);
        }
    }
    int getsum(int x){
        int res=1;
        while(x>0){
            res=max(res,c[x]);
            x-=lowbit(x);
        }
        return res;
    }
}tri;
// vector<int>pr;
// void init()
// {
//     int N=1e6;
//     vector<int> vis(N+1);
//     for(int i=2;i<=N;i++)if(!vis[i]){
//         pr.push_back(i);
//         for(int j=i*2;j<=N;j++)vis[j]=1;
//     }
// }
const int N=1e6;
vector<int> ve[N+1];
map<int,int> ma[maxn];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,q;cin>>n>>q;
    vector<int> a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i],ve[a[i]].push_back(i);
    for(int i=2;i<=N;i++){
        vector<int>all;
        for(int j=i;j<=N;j+=i){
            for(auto it:ve[j])all.push_back(it);
        }
        sort(all.begin(),all.end());
        for(int j=0;j+2<all.size();j++){
            int x=all[j],y=all[j+1];
            auto it=lower_bound(all.begin(),all.end(),y+y-x);
            if(it!=all.end()){
                ma[x][*it]=i;
                // cout<<"x="<<x<<" y="<<*it<<" w="<<i<<endl;
            }
        }
    }
    vector<tuple<int,int,int>> query(q);
    for(int i=0;i<q;i++){
        int l,r;cin>>l>>r;
        query[i]=make_tuple(l,r,i);
    }
    sort(query.begin(),query.end());
    reverse(query.begin(),query.end());
    int now=n;
    tri.set_n(n);
    vector<int> ans(q);
    for(auto [l,r,id]:query){
        while(now>=l){
            for(auto [rr,w]:ma[now])tri.update(rr,w);
            now--;
        }
        ans[id]=tri.getsum(r);
    }
    for(int i=0;i<q;i++)cout<<ans[i]<<"\n";
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 38ms
memory: 11716kb

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...

output:


result: