QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#626096#9426. Relearn through ReviewSonktxWA 168ms3896kbC++143.0kb2024-10-09 23:09:212024-10-09 23:09:25

Judging History

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

  • [2024-10-09 23:09:25]
  • 评测
  • 测评结果:WA
  • 用时:168ms
  • 内存:3896kb
  • [2024-10-09 23:09:21]
  • 提交

answer

#ifdef DS
    #include "debug.h"
#else 
    #include<bits/stdc++.h>
    #define deb(...) 
#endif
using namespace std;
#define FOR(i,a,b) for (int i=a;i<=b;i++)
#define FOD(i,a,b) for (int i=a;i>=b;i--)
#define ALL(x) x.begin(),x.end()
#define NALL(x) x.begin()+1,x.end()
#define TIME "Time elapsed : "<<(double)clock()/1000<<" s"
#define int long long
#define vi vector<int>
#define pii pair<int,int>
const int MOD=1e9+7,INF=4e18;
#define maxn 
struct Node{
    int val;
    Node()
    {
        // init val for the empty Node
        val = 0;
    }
};
Node makeNode(int _val)
{
    Node ans;
    // assign the value to Node
    ans.val = _val;
    return ans;
}
Node Merge(Node l,Node r)
{
    Node ans;
    // combine two Node
    ans.val = __gcd(l.val, r.val);
    return ans;
}
struct Segment_Tree{
    vector<Node> st;
    Segment_Tree (int _sz)
    {
        st.resize(_sz << 2);
    }
    void update(int id,int l,int r,int pos,int val)
    {
        if (l > pos || r < pos) return;
        if (l == r) 
            return st[id] = makeNode(val), void(); // base Node
        int m = l+r >> 1;
        update(id << 1,l,m,pos,val);
        update(id << 1 | 1,m+1,r,pos,val);
        st[id] = Merge(st[id << 1], st[id << 1 | 1]);
    }
    Node get(int id,int l,int r,int u,int v)
    {
        if (u > v) return Node();
        if (r < u || l > v) return Node();
        if (l >= u && r <= v) return st[id];
        int m = l+r >> 1;
        return Merge(get(id << 1,l,m,u,v), get(id << 1 | 1,m+1,r,u,v));
    }
};
void solve()
{
    int n,k; cin>>n>>k;
    vi a(n+1);
    FOR(i,1,n) cin>>a[i];
    int ans = 1;
    Segment_Tree ST(n);
    FOR(i,1,n)
        ST.update(1,1,n,i,a[i]+k);
    vector<set<pii>> g(n+1);
    int cur_gcd = 0;
    FOR(i,1,n)
    {
        g[i] = g[i-1];
        cur_gcd = __gcd(cur_gcd, a[i]);
        auto it = g[i].lower_bound({cur_gcd, -1});
        if (it != g[i].end() && (*it).first == cur_gcd)
            g[i].erase(it);
        g[i].insert({cur_gcd, i});
    }

    vi pf_gcd(n+1), sf_gcd(n+2);
    pf_gcd[0] = 0;
    FOR(i,1,n)
        pf_gcd[i] = __gcd(pf_gcd[i-1], a[i]);
    sf_gcd[n+1] = 0;
    FOD(i,n,1)
        sf_gcd[i] = __gcd(sf_gcd[i+1], a[i]);
    
    ans = max(ans, pf_gcd[n]);
    ans = max(ans, ST.get(1,1,n,1,n).val);

    FOR(i,1,n)
        ans = max(ans, __gcd(ST.get(1,1,n,1,i).val, sf_gcd[i+1]));
    
    FOR(r,1,n)
    {
        if (sf_gcd[r] == 1 || r == 1) continue;
        for (pii val : g[r-1]) 
            if (__gcd(val.first, sf_gcd[r]) == 1) continue;
            else 
            {
                ans = max(ans, __gcd(val.first, __gcd(sf_gcd[r], ST.get(1,1,n,val.second+1,r-1).val)));
            }
    }

    cout<<ans<<"\n";
}

signed main()
{
    #ifndef ONLINE_JUDGE
    freopen("thu.inp","r",stdin);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int tc; cin>>tc;
    while (tc--)
    {
        solve();	
    }
}

详细

Test #1:

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

input:

2
6 2
5 3 13 8 10 555
3 0
3 6 9

output:

5
3

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 168ms
memory: 3896kb

input:

100000
1 608611451460421713
33155506392034032
1 743116173559300609
6138108577573005
7 364454564010802125
657035115675878115 657035115675878115 657035115675878115 657035115675878115 657035115675878115 292580551665075990 657035115675878115
4 316648374341335221
365788422120542814 182894211060271407 731...

output:

641766957852455745
749254282136873614
657035115675878115
3
1
560553564512176618
183698346865682381
1
616597869896951268
6
188820994675344528
997057718507559252
949074379610491450
37337367838628559
632093288650732211
377121713907330928
356502546608886970
789177332497135009
2
2
134561004312215460
1
1
...

result:

wrong answer 4th lines differ - expected: '182894211060271407', found: '3'