QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#696993#9250. Max GCDllleiWA 974ms279584kbC++202.7kb2024-11-01 09:29:442024-11-01 09:29:45

Judging History

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

  • [2024-11-01 09:29:45]
  • 评测
  • 测评结果:WA
  • 用时:974ms
  • 内存:279584kb
  • [2024-11-01 09:29:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using LL = long long;



int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    constexpr int N = 1e6 + 1;
    vector<vector<array<int, 2>>> stk(N);
    vector<int> lp(N, 0);
    vector<int> pre(N, -1);
    vector<int> d(n);


    for (int i = 0; i < n; ++i) {
        cin >> d[i];
    }

    int S = 333;
    int cnt = (n + S - 1) / S;
    vector<int> L(cnt), R(cnt);
    vector<int> blk(cnt), c(n);
    for (int i = 0; i < cnt; ++i) {
        L[i] = i * S;
        R[i] = min((i + 1) * S - 1, n - 1);
    }

    vector<array<int, 3>> b(q);
    for (int i = 0; i < q; ++i) {
        int l, r;
        cin >> l >> r;
        --l, --r;
        b[i] = {l, r, i};
    }
    vector<int> ans(q);

    sort(b.begin(), b.end(), [&](const auto &a, const auto &b) {
        return a[1] < b[1];
    });

    int p = 0;

    #define belong(x) ((x) / S)

    auto add = [&](int x, int y) {
        c[x] = max(c[x], y);
        blk[belong(x)] = max(blk[belong(x)], y);
    };

    auto query = [&](int l, int r) {
        int ll = belong(l), rr = belong(r);

        if (ll == rr) {
            int ans = 0;
            for (int i = l; i <= r; ++i) {
                ans = max(ans, c[i]);
            }
            return ans;
        }

        int ans = 0;
        for (int i = l; i <= R[ll]; ++i) {
            ans = max(ans, c[i]);
        }
        for (int i = L[rr]; i <= r; ++i) {
            ans = max(ans, c[i]);
        }

        for (int i = ll + 1; i <= rr - 1; ++i) {
            ans = max(ans, blk[i]);
        }
        return ans;
    };

    auto handle = [&](int x, int y) {
        while (lp[x] < int(stk[x].size()) && y >= stk[x][lp[x]][0]) {
            lp[x]++;
        }
        if (lp[x] >= 1) {
            add(stk[x][lp[x] - 1][1], x);
        }
        
        if (pre[x] != -1) {
            int now = 2 * y - pre[x]; 
            if (stk[x].size() && now <= stk[x].back()[0]) {
                stk[x].pop_back();
            }
            stk[x].push_back({now, pre[x]});
            lp[x] = min(lp[x], int(stk[x].size()));
        }
        pre[x] = y;
    };

    for (int i = 0; i < q; ++i) {
        auto [l, r, id] = b[i];

        while (p <= r) {
            int x = d[p];
            for (int j = 1; j * j <= x; ++j) {
                if (x % j == 0) {
                    handle(j, p);
                    if (j * j != x) {
                        handle(x / j, p);
                    }
                }
            }
            p++;
        }
        ans[id] = query(l, r);
    }
    for (int i = 0; i < q; ++i) {
        cout << ans[i] << '\n';
    }
    return 0;
}

詳細信息

Test #1:

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

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: 974ms
memory: 279584kb

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 69144th words differ - expected: '960960', found: '831600'