QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#106855#6405. Barkleywhatever#WA 3ms9580kbC++171.5kb2023-05-19 15:58:152023-05-19 15:58:17

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-19 15:58:17]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:9580kb
  • [2023-05-19 15:58:15]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
using pii = pair<int, int>;
using i64 = long long;
#define rep(i, a, b) for (int i = a, I = b; i <= I; ++i)
#define per(i, a, b) for (int i = a, I = b; i >= I; --i)
template<typename T> void up(T &x, T y) { if (x < y) x = y; }
template<typename T> void down(T &x, T y) { if (x > y) x = y; }

const int N = 100005, K = 17;
int n, q, lg[N];
i64 a[N], st[N][K];
vector<int> rp[N];

i64 query(int l, int r) {
    if (l > r) return 0;
    int k = lg[r - l + 1];
    return __gcd(st[l][k], st[r - (1 << k) + 1][k]);
}

i64 solve(int l, int r, int k) {
    if (k == 0) return query(l, r);
    i64 res = 0;
    for (auto i : rp[l]) {
        if (i > r - k + 1) break;
        up(res, __gcd(query(l, i - 1), solve(i + 1, r, k - 1)));
    }
    return res;
}

int main() {
    ios::sync_with_stdio(0), cin.tie(0);

    cin >> n >> q;
    rep(i, 1, n) cin >> a[i];

    rep(i, 2, n) lg[i] = lg[i >> 1] + 1;
    per(i, n, 1) {
        st[i][0] = a[i];
        for (int k = 1; i + (1 << k) - 1 <= n; ++k) st[i][k] = __gcd(st[i][k - 1], st[i + (1 << (k - 1))][k - 1]);
    }

    per(i, n, 1) {
        rp[i].push_back(i);
        i64 last = a[i];
        for (auto j : rp[i + 1]) {
            i64 cur = query(i, j);
            if (cur != last) rp[i].push_back(j);
        }
    }

    while (q--) {
        int l, r, k;
        cin >> l >> r >> k;
        cout << solve(l, r, k) << "\n";
    }

    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 3ms
memory: 6508kb

input:

4 4
3 2 6 4
1 3 1
2 4 1
1 4 2
1 4 3

output:

3
2
3
6

result:

ok 4 number(s): "3 2 3 6"

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 9580kb

input:

100 10000
7 25 33 17 13 33 24 29 11 1 3 19 2 20 33 23 14 24 15 12 3 1 5 13 6 35 15 21 10 34 31 19 7 33 17 26 26 1 19 21 31 5 29 20 18 32 19 18 19 31 11 26 6 19 2 26 23 1 4 2 31 21 29 30 1 14 20 23 14 32 4 34 13 29 5 26 24 29 28 5 26 26 21 19 2 33 2 31 30 3 23 24 26 32 36 21 21 11 5 9
56 57 1
90 97 1...

output:

26
1
1
1
1
1
1
1
31
1
1
1
1
1
26
1
1
1
1
1
1
29
1
1
1
1
1
1
4
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
2
2
1
1
1
21
1
1
1
1
1
19
1
1
1
21
1
1
1
1
1
1
1
1
1
1
1
1
1
3
1
1
1
1
1
1
1
1
1
1
4
1
1
1
1
1
3
1
2
1
26
1
1
1
1
1
1
1
7
1
1
1
33
1
1
1
1
1
1
2
1
26
1
1
1
2
1
1
1
1
1
1
26
1
1
1
1
31
1
1
2
1
4
29
1
2
1
1...

result:

wrong answer 7823rd numbers differ - expected: '2', found: '1'