QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#616813#9250. Max GCDucup-team4153#WA 1671ms606692kbC++201.6kb2024-10-06 12:07:502024-10-06 12:07:50

Judging History

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

  • [2024-10-06 12:07:50]
  • 评测
  • 测评结果:WA
  • 用时:1671ms
  • 内存:606692kb
  • [2024-10-06 12:07:50]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
const int N = 1e6 + 7;
const int M = 2e5 + 7;
int n, q;
int ans[N];
vector<int> p[N];
vector<pair<int, int>> add[M], ask[N];
int sum[M];

int low_bit(int x) {
    return x & (-x);
}

void update(int pos, int v) {
    for (int i = pos; i <= n; i += low_bit(i))sum[i] = max(sum[i], v);
}

int query(int pos) {
    int ans = 0;
    for (int i = pos; i > 0; i -= low_bit(i))ans = max(ans, sum[i]);
    return ans;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> n >> q;
    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        for (int j = 1; j * j <= x; j++) {
            if (x % j == 0) {
                p[j].push_back(i);
                if (j * j != x)p[x / j].push_back(i);
            }
        }
    }
    for (int i = 1; i <= q; i++) {
        int l, r;
        cin >> l >> r;
        ask[l].push_back({r, i});
    }
    for (int i = 2; i <= 1e6; i++) {
        if (p[i].size() <= 2)continue;
        int siz = p[i].size();
        int l = siz - 2;
        for (int j = siz - 1; j >= 2; j--) {
            while (l > 0 && (p[i][l] - p[i][l - 1]) > (p[i][j] - p[i][l]))l--;
            if (l) {
                add[p[i][l - 1]].push_back({p[i][j], i});
            }
        }
    }
    for (int i = n; i >= 1; i--) {
        for (auto [pos, v]: add[i])update(pos, v);
        for (auto [pos, id]: ask[i])ans[id] = query(pos);
    }
    for (int i = 1; i <= q; i++)cout << max(1, ans[i]) << "\n";
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 4ms
memory: 3728kb

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: 1671ms
memory: 606692kb

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 1518th words differ - expected: '0', found: '1'