QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#552724#9250. Max GCDucup-team180#TL 0ms27040kbC++203.9kb2024-09-08 01:24:102024-09-08 01:24:11

Judging History

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

  • [2024-09-08 01:24:11]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:27040kb
  • [2024-09-08 01:24:10]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define ov3(a,b,c,name,...)name
#define rep0(n) for(ll aaaaa = 0; aaaaa < n;++aaaaa)
#define rep1(i,n) for(ll i = 0;i < (n); i++)
#define rep2(i,a,b) for(ll i = (a); i <(b); i ++)
#define rep(...) ov3(__VA_ARGS__, rep2,rep1,rep0)(__VA_ARGS__)
#define per(i, a, b) for(ll i = (a) - 1; i >= b; i--)
#define fore(e,v) for(auto &&e:v)
#define all(a) begin(a),end(a)
#define si(a) (int)(size(a))
bool chmin(auto &a, auto b){return a>b?a = b,1:0;}
bool chmax(auto &a, auto b){return a<b?a = b,1:0;}

#define pb push_back
#define eb emplace_back
#define i128 __int128_t

const ll inf = LLONG_MAX / 3;

template <typename S, S (*op)(S, S), S (*e)()> struct segtree {
    segtree(int n) : segtree(vector<S>(n, e())) {}
    segtree(const vector<S> &v) : n(si(v)) {
        s = bit_ceil(unsigned(n));
        log = countr_zero(unsigned(s));
        d = vector<S>(2 * s, e());
        rep(i, n) d[s + i] = v[i];
        per(i, s, 1) update(i);
    }
    void set(int p, S x) {
        d[p += s] = x;
        rep(i, 1, log + 1) update(p >> i);
    }
    S prod(int l, int r) const {
        S sml = e(), smr = e();
        l += s, r += s;
        while(l < r) {
            if(l & 1) sml = op(sml, d[l++]);
            if(r & 1) smr = op(d[--r], smr);
            l >>= 1, r >>= 1;
        }
        return op(sml, smr);
    }
    S all_prod() const { return d[1]; }

  private:
    int n, s, log;
    vector<S> d;
    void update(int k) { d[k] = op(d[k * 2], d[k * 2 + 1]); }
};

ll f(ll x, ll y) { return max(x, y); }
ll e() { return -inf; }

int main(){
    cin.tie(0) -> sync_with_stdio(0);
    ll n,q;
    cin>>n>>q;
    const ll m = 1e6 + 1;
    vl a(n);
    vector<vl> divs(n);
    rep(i,n){
        cin>>a[i];
        for(ll x = 1;x * x <= a[i];x ++)if(a[i] % x == 0){
            ll y = a[i] / x;
            divs[i].pb(x);
            if(x != y)divs[i].pb(y);
        }
    }
    vector<unordered_map<ll,ll> > js(n);
    {
        vector<vl> is(m);
        rep(j,n){
            fore(g,divs[j]){
                while(si(is[g])){
                    ll i = is[g].back(); is[g].pop_back();
                    js[i][g] = j;
                    // cout<<"i,j,g = "<<i<<" "<<j<<" "<<g<<endl;
                }
            }
            fore(g,divs[j]){
                is[g].pb(j);
            }
        }
    }
    vector<unordered_map<ll,ll> > ks(n);
    {
        vector<vl> is(m);
        vector<vector<pll> > qs(n);
        rep(i,n){
            fore(g,divs[i]){
                if(!js[i].count(g))continue;
                ll j = js[i][g];
                // cout<<"i,j,g = "<<i<<" "<<j<<" "<<g<<endl;
                if(2 * j - i < n){
                    qs[2 * j - i].eb(i,g);
                }
            }
        }
        rep(k,n){
            for(auto &&[i,g] : qs[k]){
                is[g].pb(i);
            }
            fore(g,divs[k]){
                while(si(is[g])){
                    ll i = is[g].back(); is[g].pop_back();
                    ks[i][g] = k;
                }
            }
        }
    }

    vl l(q),r(q);
    rep(i,q){
        cin>>l[i]>>r[i];
        l[i]--;
    }
    vector<vl> qs(n);
    rep(i,q){
        qs[l[i]].pb(i);
    }
    segtree<ll,f,e> seg(n);
    vl ans(q);
    for(ll i = n - 1;i >= 0;i--){
        for(auto &&[g,k] : ks[i]){
            ll cur = seg.prod(k, k + 1);
            if(cur < g){
                seg.set(k,g);
            }
        }
        fore(j,qs[i]){
            ans[j] = seg.prod(l[j], r[j]);
        }
    }
    rep(i,q){
        cout<<ans[i]<<"\n";
    }
    // rep(i,n){
    //     for(auto &&[g,k] : ks[i]){
    //         ll j = js[i][g];
    //         cout<<i<<" "<<j<<" "<<k<<" "<<g<<endl;
    //     }
    // }
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 27040kb

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: