QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#410063#8338. Quad Kingdoms ChessbigJWA 37ms4360kbC++203.5kb2024-05-13 09:27:592024-05-13 09:27:59

Judging History

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

  • [2024-05-13 09:27:59]
  • 评测
  • 测评结果:WA
  • 用时:37ms
  • 内存:4360kb
  • [2024-05-13 09:27:59]
  • 提交

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 {
    int n;
    std::vector<Info> tr;
    std::vector<int> seq;
    template<class T>
    SegmentTree(std::vector<T> init_) {
        init(init_);
    }
    template<class T>
    void init(std::vector<T> init_) {
        n = init_.size();
        tr.assign(4 << std::__lg(n), Info());
        auto build = [&](auto&& self, int p, int l, int r) {
            if (r - l == 1) {
                tr[p] = init_[l];
                return;
            }
            int m = std::midpoint(l, r);
            self(self, 2 * p, l, m);
            self(self, 2 * p + 1, m, r);
            pull(p, m, r);
        };
        build(build, 1, 0, n);
    }

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

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

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

Info operator+(const Info& a, const Info& b) {
    return Info{ std::max(a.max, b.max), (a.hash + 1LL * b.hash * p[a.siz] % P) % P, a.siz + b.siz };
}

Info merge(const Info& a, const Info& b, SegmentTree<Info>& seg, int p, int l, int r) {
    if (a.max == 0) {
        return b;
    } else if (b.max == 0) {
        return a;
    }
    if (a.max > b.max) {
        return a;
    }
    if (r - l == 1) {
        return a + b;
    }
    int m = std::midpoint(l, r);
    Info c = a;
    if (seg.tr[2 * p].max == b.max) {
        c = merge(c, seg.tr[2 * p], seg, 2 * p, l, m);
    }
    if (seg.tr[2 * p + 1].max == b.max) {
        c = merge(c, seg.tr[2 * p + 1], seg, 2 * p + 1, m, r);
    }
    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;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 4360kb

input:

5
1 2 3 4 5
5
5 4 3 2 1
8
1 1 5
1 4 2
1 2 4
1 5 1
1 5 5
2 1 4
2 3 5
2 5 5

output:

NO
NO
NO
YES
NO
NO
NO
YES

result:

ok 8 tokens

Test #2:

score: 0
Accepted
time: 31ms
memory: 4176kb

input:

1
2
6
2 1 1 1 1 1
200000
2 6 2
1 1 1
1 1 1
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
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 200000 tokens

Test #4:

score: -100
Wrong Answer
time: 37ms
memory: 4092kb

input:

6
1 3 1 2 1 2
6
2 1 3 3 3 1
200000
2 4 2
1 2 1
1 6 2
2 3 2
1 1 1
1 6 2
1 6 2
1 3 2
2 6 1
2 4 3
1 1 2
2 5 2
2 6 2
2 3 1
1 4 3
1 3 1
2 5 2
2 4 2
2 1 3
1 1 1
2 2 2
2 4 2
1 5 3
1 6 3
2 6 3
1 5 3
2 5 3
2 4 1
2 4 2
1 1 2
1 6 1
2 6 1
1 2 3
1 1 3
1 1 1
2 6 3
2 4 1
1 4 2
2 2 1
1 3 1
1 1 3
1 1 3
1 4 3
1 3 3
2...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
YES
YES
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
N...

result:

wrong answer 15th words differ - expected: 'NO', found: 'YES'