QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#409920#8338. Quad Kingdoms ChessbigJCompile Error//C++204.3kb2024-05-12 21:46:412024-05-12 21:46:41

Judging History

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

  • [2024-05-12 21:46:41]
  • 评测
  • [2024-05-12 21:46:41]
  • 提交

answer

#include <bits/stdc++.h>

constexpr bool isprime(int n) {
    if (n <= 1) {
        return false;
    }
    for (int i = 2; i * i <= n; i++) {
        if (n % i == 0) {
            return false;
        }
    }
    return true;
}

constexpr int findPrime(int n) {
    while (!isprime(n)) {
        n++;
    }
    return n;
}

std::mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
const int P = findPrime(rnd() % 900000000 + 100000000);
const int B = rnd() % P;

constexpr int N = 100000;
int p[N + 1];

template <class Info>
struct SegmentTree {
#define m (l + r) / 2
    int n;
    std::vector<Info> tr;
    constexpr SegmentTree() : n(0) {}
    constexpr SegmentTree(int n_, Info v_ = Info()) {
        init(n_, v_);
    }
    template<class T>
    constexpr SegmentTree(std::vector<T> init_) {
        init(init_);
    }
    constexpr void init(int n_, Info v_ = Info()) {
        init(std::vector(n_, v_));
    }
    template<class T>
    constexpr void init(std::vector<T> init_) {
        n = init_.size();
        tr.assign(4 << std::__lg(n), Info());
        const auto build = [&](auto&& self, int p, int l, int r) {
            if (r - l == 1) {
                tr[p] = init_[l];
                return;
            }
            self(self, 2 * p, l, m);
            self(self, 2 * p + 1, m, r);
            pull(p, m, r);
        };
        build(build, 1, 0, n);
    }

    constexpr void pull(int p, int bl, int br) {
        tr[p] = merge(tr[2 * p], tr[2 * p + 1], *this, bl, br);
    }

    constexpr void modify(int p, int l, int r, int x, const Info& v) {
        if (r - l == 1) {
            tr[p] = v;
            return;
        }
        if (x < m) {
            modify(2 * p, l, m, x, v);
        } else {
            modify(2 * p + 1, m, r, x, v);
        }
        pull(p, m, r);
    }
    constexpr void modify(int x, const Info& v) {
        modify(1, 0, n, x, v);
    }

    constexpr Info rangeQuery(int p, int l, int r, int x, int y) {
        if (l >= y || r <= x) {
            return Info();
        }
        if (l >= x && r <= y) {
            return tr[p];
        }
        return merge(rangeQuery(2 * p, l, m, x, y), rangeQuery(2 * p + 1, m, r, x, y), *this, m, r);
    }

    constexpr Info rangeQuery(int l, int r) {
        return rangeQuery(1, 0, n, l, r);
    }

    constexpr int find(int p, int l, int r, int x, int y, int v) {
        if (l >= y || r <= x || tr[p].max < v) {
            return -1;
        }
        if (r - l == 1) {
            return l;
        }
        int res = find(2 * p, l, m, x, y, v);
        if (res == -1) {
            res = find(2 * p + 1, m, r, x, y, v);
        }
        return res;
    }
    constexpr int find(int x, int y, int v) {
        return find(1, 0, n, x, y, v);
    }

#undef m
};

struct Info {
    int max;
    int hash;
    int siz;
    Info(int v = 0) : max(v), hash(1LL * v * B % P), siz(1) {}
};

constexpr Info merge(const Info& a, const Info& b, SegmentTree<Info>& seg, int bl, int br) {
    if (a.max == 0) {
        return b;
    } else if (b.max == 0) {
        return a;
    }
    if (a.max > b.max) {
        return a;
    }
    int pos = seg.find(bl, br, a.max);
    if (pos == -1) {
        pos = bl;
    }
    Info d = seg.rangeQuery(pos, br);
    Info c{};
    c.max = std::max(a.max, b.max);
    c.siz = a.siz + d.siz;
    c.hash = (a.hash + 1LL * d.hash * p[a.siz] % P) % P;
    return c;
}

int main() {
    p[0] = 1;
    for (int i = 1; i <= N; i++) {
        p[i] = (1LL * p[i - 1] * B) % P;
    }

    int n1;
    scanf("%d", &n1);
    std::vector<int> a(n1);
    for (int i = n1 - 1; i >= 0; i--) {
        scanf("%d", &a[i]);
    }

    int n2;
    scanf("%d", &n2);
    std::vector<int> b(n2);
    for (int i = n2 - 1; i >= 0; i--) {
        scanf("%d", &b[i]);
    }

    SegmentTree<Info> sega(a);
    SegmentTree<Info> segb(b);

    int m;
    for (scanf("%d", &m); m; m--) {
        int o, x, y;
        scanf("%d%d%d", &o, &x, &y);
        if (o == 1) {
            sega.modify(n1 - x, y);
        } else {
            segb.modify(n2 - x, y);
        }
        puts(sega.tr[1].hash == segb.tr[1].hash ? "YES" : "NO");
    }

    return 0;
}

Details

answer.code: In function ‘constexpr Info merge(const Info&, const Info&, SegmentTree<Info>&, int, int)’:
answer.code:135:10: error: variable ‘d’ of non-literal type ‘Info’ in ‘constexpr’ function only available with ‘-std=c++2b’ or ‘-std=gnu++2b’
  135 |     Info d = seg.rangeQuery(pos, br);
      |          ^
answer.code:115:8: note: ‘Info’ is not literal because:
  115 | struct Info {
      |        ^~~~
answer.code:115:8: note:   ‘Info’ is not an aggregate, does not have a trivial default constructor, and has no ‘constexpr’ constructor that is not a copy or move constructor
answer.code:136:10: error: variable ‘c’ of non-literal type ‘Info’ in ‘constexpr’ function only available with ‘-std=c++2b’ or ‘-std=gnu++2b’
  136 |     Info c{};
      |          ^
answer.code: In function ‘int main()’:
answer.code:150:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  150 |     scanf("%d", &n1);
      |     ~~~~~^~~~~~~~~~~
answer.code:153:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  153 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
answer.code:157:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  157 |     scanf("%d", &n2);
      |     ~~~~~^~~~~~~~~~~
answer.code:160:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  160 |         scanf("%d", &b[i]);
      |         ~~~~~^~~~~~~~~~~~~
answer.code:167:15: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  167 |     for (scanf("%d", &m); m; m--) {
      |          ~~~~~^~~~~~~~~~
answer.code:169:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
  169 |         scanf("%d%d%d", &o, &x, &y);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~