QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#599950#9250. Max GCDgaofengWA 1477ms669320kbC++204.1kb2024-09-29 13:34:442024-09-29 13:34:45

Judging History

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

  • [2024-09-29 13:34:45]
  • 评测
  • 测评结果:WA
  • 用时:1477ms
  • 内存:669320kb
  • [2024-09-29 13:34:44]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int>PII;
const int N=1e6+10;
const int mod=998244353;
const int INF  = 0x3f3f3f3f;
const ll INFll  = 0x3f3f3f3f3f3f3f3f;
#define endl "\n" 
#define x first
#define y second

vector<vector<int>>adj(N);

int a[N];

struct Node{
    int l, r, w;
}query[N];
int ans[N];

struct gfseg { // 区间最值
    int a[N], _n;
    struct Node {
        int l, r;
        int max;
    }tr[N];

    void pushup(int u) {
        tr[u].max = max(tr[u << 1].max, tr[u << 1 | 1].max);
    }

    void build(int u, int l, int r) {
 
        if(l == r) {
            tr[u] = {l, r, a[l]};
            return;
        }
        int mid = l + r >> 1;
        tr[u] = {l, r, -INF};
        build(u << 1, l, mid);
        build(u << 1 | 1, mid + 1, r);
        pushup(u);
    }

    void init(vector<int> _a) {
        _n = _a.size();
        for(int i = 1; i <= _n; i ++) {
            a[i] = _a[i - 1];
        } 
        build(1, 1, _n);
    }

    void modify(int u, int x, int y) {
        if(tr[u].l == tr[u].r && tr[u].l == x) {
            tr[u].max = max(tr[u].max, y);
            return;
        }
        int mid = tr[u].l + tr[u].r >> 1;
        if(x <= mid) modify(u << 1, x, y);
        if(x >  mid) modify(u << 1 | 1, x, y);
        pushup(u);
    }


    int querymax(int u, int l, int r) {
        if(l <= tr[u].l && tr[u].r <= r) {
            return tr[u].max;
        }

        int res = -INF;
        int mid = tr[u].l + tr[u].r >> 1;
        if(l <= mid) res = max(querymax(u << 1, l,  r), res);
        if(r >  mid) res = max(querymax(u << 1 | 1, l,  r), res);
        return res;
    }

    void debug() {
        for(int i = 1; i <= _n; i ++)
        cout << querymax(1, i, i) << " "; cout <<  endl;
    }
}tr;


vector<Node> no2[N];
void solve()
{
    
    int n, q; cin >> n >> q;
    for(int i = 1; i <= n; i ++) {
        cin >> a[i];
        // a[i] = rand();
        int x = a[i];
        for(int j = 1; j * j <= x; j ++) {
            if(x % j == 0) {
                adj[j].push_back(i);
                if(j * j != x) 
                    adj[x/j].push_back(i);
            }
        }
    }

    for(int i = 1; i <= N; i ++) {
        int l = 0, r = 0;
        for(int l = 0; l < adj[i].size(); l ++) {
            while(r <= l + 1 && r < adj[i].size()) r ++;

            while(r < adj[i].size()) {
                if(r < adj[i].size() && adj[i][l + 1] - adj[i][l] <= adj[i][r] - adj[i][l + 1]) {
                    no2[adj[i][l]].push_back({adj[i][l], adj[i][r], i});
                    break;
                }
                else r ++;
            }
        }
    }

    // for(int i = 1; i < N; i ++) {
    //     for(int j = 0; j + 2 < adj[i].size(); j ++) {
    //         if(adj[i][j + 1] - adj[i][j] <= adj[i][j + 2] - adj[i][j + 1]) 
    //             no2[adj[i][j]].push_back({adj[i][j], adj[i][j + 2], i});
    //     }
    // }

    vector<int>T; for(int i = 1; i <= n + 10; i ++) T.push_back(0); tr.init(T);

    for(int i = 0; i < q; i ++) {
        cin >> query[i].l >> query[i].r; query[i].w = i;
    }

    sort(query , query + q, [&](Node a, Node b){
        return a.l > b.l;
    });

    vector<int>mx (n + 10, 0);
    int j = 0;
    for(int L = n; L >= 0; L --) {
        for(auto [x, y, w] : no2[L]){
            // cout << x << " " << y << " " << w << endl;
            // cout << no[i].l << " " << no[i].r << " " << no[i].w << endl;
            if(mx[y] < w) {
                tr.modify(1, y, w);
                mx[y] = w;
            }
        }

        while(j < q && query[j].l >= L) {
            ans[query[j].w] = tr.querymax(1,1,query[j].r);
            j ++;
        }
    }
    // tr.debug();
    // cout << i << " " << j << endl;

    for(int i = 0; i < q; i ++) cout << ans[i] << endl;
}


signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cout << setprecision(11) << fixed;
    int t;t=1;
    //cin>>t;
    for(int i=1;i<=t;i++){
        //printf("Case %d: ",i);
        solve();
    }
}

詳細信息

Test #1:

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

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: 1477ms
memory: 669320kb

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:

997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920
997920...

result:

wrong answer 5108th words differ - expected: '997920', found: '982800'