QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#709922#6405. Barkleytassei903#WA 0ms3788kbC++233.6kb2024-11-04 17:27:172024-11-04 17:27:18

Judging History

This is the latest submission verdict.

  • [2024-11-04 17:27:18]
  • Judged
  • Verdict: WA
  • Time: 0ms
  • Memory: 3788kb
  • [2024-11-04 17:27:17]
  • Submitted

answer


#include <bits/stdc++.h>
#include <bits/extc++.h> 
using namespace std;
#define sz(x) (int)(x).size()
#define rep(i, l, r) for (int i = l; i < (r); i++)
#define rrep(i, l, r) for(int i = (int)(r)-1; i >= (int)(l); i--)
#define all(x) begin(x), end(x)

using ll = long long;
using vi = vector<int>;

using pii = pair<int, int>;


template <class S, S (*op)(S, S), S (*e)()> struct segtree {
  private:
    int n;
    int size;
    vector<S> data;

    void update(int i) {
        data[i] = op(data[2 * i], data[2 * i + 1]);
    }

  public:
    segtree(int n) : segtree(vector<S>(n, e())) {}
    segtree(const vector<S> &v) : n((int)v.size()), size(1) {
        while (size < n) size *= 2;
        data = vector<S>(2 * size, e());
        rep(i, 0, n) {
            data[size + i] = v[i];
        }
        rrep(i, 1, size) update(i);
    }

    void set(int p, S x) {
        assert(0 <= p && p < n);
        p += size;
        data[p] = x;
        while (p > 1) {
            p >>= 1;
            update(p);
        }
    }

    S get(int p) {
        assert(0 <= p && p < n);
        return data[p + size];
    }

    S prod(int l, int r) {
        assert(0 <= l && l <= r && r <= n);
        S sml = e(), smr = e();
        l += size;
        r += size;
        while (l < r) {
            if (l & 1) sml = op(sml, data[l++]);
            if (r & 1) smr = op(data[--r], smr);
            l >>= 1;
            r >>= 1;
        }
        return op(sml, smr);
    }

    S all_prod() {
        return data[1];
    }

    template <class F> int max_right(int l, F f) {
        assert(0 <= l && l <= n);
        assert(f(e()));
        if (l == n) return n;
        l += size;
        S sm = e();
        do {
            while (l % 2 == 0) l >>= 1;
            if (!f(op(sm, data[l]))) {
                while (l < size) {
                    l = 2 * l;
                    if (f(op(sm, data[l]))) {
                        sm = op(sm, data[l]);
                        l++;
                    }
                }
                return l - size;
            }
            sm = op(sm, data[l]);
            l++;
        } while ((l & -l) != l);
        return n;
    }

};

using ull = unsigned long long;

ull gcd(ull a, ull b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}

ull e() {
    return 0;
}

int main() {
    int n, q;cin >> n >> q;
    vector<ull> a(n);rep(i, 0, n) cin >> a[i];

    segtree<ull, gcd, e> st(a);
    vector<vector<pair<int, ull>>> g(n);
    rep(i, 0, n) {
        ull now = a[i];
        int l = i;
        while (true) {
            int r = st.max_right(l, [&](ull x)->bool{if (now == 0)return x == 0;else return x % now == 0;});
            g[i].emplace_back(r, st.prod(i, r));
            cout << i << " " << r << " " << st.prod(i, r) << endl;

            if (r == n)break;
            now = st.prod(i, r + 1);
        }
    }

    rep(_, 0, q) {
        int l, r, k;cin >> l >> r >> k;
        l--;
        auto dfs = [&](auto self, int x, int d, ull now) -> ull {
            // cout << x << " " << d << " " << now << endl;
            if (d == k && x >= r)return now;
            if (x >= r) return 0;
            if (d > k) return 0;
            ull ans = 0;
            for (auto[y, gc] : g[x]) {
                ans = max(ans, self(self, y, d, gcd(now, gc)));
                if (y >= r) break;
            }
            ans = max(ans, self(self, x+1, d+1, now));
            return ans;
        };

        cout << dfs(dfs, l, 0, 0) << endl;
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3788kb

input:

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

output:

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

result:

wrong answer 1st numbers differ - expected: '3', found: '0'