From 3f5ea197e0e9a133a94aa6fc38351570dbe73b95 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Fri, 30 Dec 2022 22:31:48 +0800 Subject: [PATCH] =?UTF-8?q?#6850.=20=E6=9C=80=E5=A4=A7=E5=BC=82=E6=88=96?= =?UTF-8?q?=E5=92=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1661199 --- LibreOJ/6850/6850.cpp | 87 ++++++++++++++++++++++++++++++++++++++++ LibreOJ/6850/data/1.in | 3 ++ LibreOJ/6850/data/1.out | 3 ++ LibreOJ/6850/data/10.in | 3 ++ LibreOJ/6850/data/10.out | 3 ++ LibreOJ/6850/data/2.in | 3 ++ LibreOJ/6850/data/2.out | 3 ++ LibreOJ/6850/data/3.in | 3 ++ LibreOJ/6850/data/3.out | 3 ++ LibreOJ/6850/data/4.in | 3 ++ LibreOJ/6850/data/4.out | 3 ++ LibreOJ/6850/data/5.in | 3 ++ LibreOJ/6850/data/5.out | 3 ++ LibreOJ/6850/data/6.in | 3 ++ LibreOJ/6850/data/6.out | 3 ++ LibreOJ/6850/data/7.in | 3 ++ LibreOJ/6850/data/7.out | 3 ++ LibreOJ/6850/data/8.in | 3 ++ LibreOJ/6850/data/8.out | 3 ++ LibreOJ/6850/data/9.in | 3 ++ LibreOJ/6850/data/9.out | 3 ++ 21 files changed, 147 insertions(+) create mode 100644 LibreOJ/6850/6850.cpp create mode 100644 LibreOJ/6850/data/1.in create mode 100644 LibreOJ/6850/data/1.out create mode 100644 LibreOJ/6850/data/10.in create mode 100644 LibreOJ/6850/data/10.out create mode 100644 LibreOJ/6850/data/2.in create mode 100644 LibreOJ/6850/data/2.out create mode 100644 LibreOJ/6850/data/3.in create mode 100644 LibreOJ/6850/data/3.out create mode 100644 LibreOJ/6850/data/4.in create mode 100644 LibreOJ/6850/data/4.out create mode 100644 LibreOJ/6850/data/5.in create mode 100644 LibreOJ/6850/data/5.out create mode 100644 LibreOJ/6850/data/6.in create mode 100644 LibreOJ/6850/data/6.out create mode 100644 LibreOJ/6850/data/7.in create mode 100644 LibreOJ/6850/data/7.out create mode 100644 LibreOJ/6850/data/8.in create mode 100644 LibreOJ/6850/data/8.out create mode 100644 LibreOJ/6850/data/9.in create mode 100644 LibreOJ/6850/data/9.out diff --git a/LibreOJ/6850/6850.cpp b/LibreOJ/6850/6850.cpp new file mode 100644 index 00000000..eb7f7bc5 --- /dev/null +++ b/LibreOJ/6850/6850.cpp @@ -0,0 +1,87 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 6e5 + 5; + +int n, m, sum; +int cnt, tot, root[N], lst[N], tr[N << 5][2], siz[N << 5]; + +void insert(int val) { + root[++tot] = ++cnt; + + int l = root[tot - 1], r = root[tot]; + + for (int i = 30; i >= 0; i--) { + bool x = val >> i & 1; + + tr[r][x ^ 1] = tr[l][x ^ 1]; + tr[r][x] = ++cnt; + + l = tr[l][x]; + r = tr[r][x]; + + siz[r] = siz[l] + 1; + } + + lst[tot] = cnt; +} + +int query(int l, int r, int val) { + int res = 0; + + l = root[l], r = root[r]; + + for (int i = 30; i >= 0; i--) { + bool x = val >> i & 1; + + if (siz[tr[r][x ^ 1]] > siz[tr[l][x ^ 1]]) { + res |= 1 << i; + x = x ^ 1; + } + + l = tr[l][x]; + r = tr[r][x]; + } + + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + insert(0); + + for (int i = 1, x; i <= n; i++) { + cin >> x; + + insert(sum ^= x); + } + + while (m--) { + char op; + + cin >> op; + + if (op == 'A') { + int x; + + cin >> x; + + insert(sum ^= x); + } else { // op == 'Q' + int l, r, x; + + cin >> l >> r >> x; + + cout << query(l - 1, r, x ^ sum) << endl; + } + } + + return 0; +} diff --git a/LibreOJ/6850/data/1.in b/LibreOJ/6850/data/1.in new file mode 100644 index 00000000..04103106 --- /dev/null +++ b/LibreOJ/6850/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cfbd01e193a52526c41879aa65246013d9598206e9d3ca7a8fdd9e239bb86936 +size 3626671 diff --git a/LibreOJ/6850/data/1.out b/LibreOJ/6850/data/1.out new file mode 100644 index 00000000..4262b20a --- /dev/null +++ b/LibreOJ/6850/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:588a08d3a29d3c7e5d4d9edcab88c1852774c20c57175ab335dfad1e7b345475 +size 676115 diff --git a/LibreOJ/6850/data/10.in b/LibreOJ/6850/data/10.in new file mode 100644 index 00000000..f610fdd7 --- /dev/null +++ b/LibreOJ/6850/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c81905ea8353b758e591772abc78f9fea47189bc320a68f04c29a99ec21b174f +size 870564 diff --git a/LibreOJ/6850/data/10.out b/LibreOJ/6850/data/10.out new file mode 100644 index 00000000..c9f8e6a1 --- /dev/null +++ b/LibreOJ/6850/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dc588a1b6b716a5628e9cb30e82eed005fcae3adb15298ebd95b3e65182cd2f6 +size 269995 diff --git a/LibreOJ/6850/data/2.in b/LibreOJ/6850/data/2.in new file mode 100644 index 00000000..a64a5153 --- /dev/null +++ b/LibreOJ/6850/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3c5843c27cf6a1ddcc282132e3ba96f5e90bd706c1b8af566c115735e58352ad +size 94 diff --git a/LibreOJ/6850/data/2.out b/LibreOJ/6850/data/2.out new file mode 100644 index 00000000..89064363 --- /dev/null +++ b/LibreOJ/6850/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f18e3f6f367853db5d7c371c3b444be94ee5b1442b35fff93b0b94520f93fd83 +size 31 diff --git a/LibreOJ/6850/data/3.in b/LibreOJ/6850/data/3.in new file mode 100644 index 00000000..9ee5c68c --- /dev/null +++ b/LibreOJ/6850/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2691d8963abd17b66eef964c93aa930196f09ad1178b533ec388a9caf6221aaf +size 7345043 diff --git a/LibreOJ/6850/data/3.out b/LibreOJ/6850/data/3.out new file mode 100644 index 00000000..757fbb82 --- /dev/null +++ b/LibreOJ/6850/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:52ca92ae86fd78a7d91343fda419563c0677d0a40a722258d449fd62d02e825b +size 1353327 diff --git a/LibreOJ/6850/data/4.in b/LibreOJ/6850/data/4.in new file mode 100644 index 00000000..7aa9aa11 --- /dev/null +++ b/LibreOJ/6850/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:afcf290899864e1772ecf46545d7b68790730b87b1f033c9feb9f1ec5c896f1f +size 1180189 diff --git a/LibreOJ/6850/data/4.out b/LibreOJ/6850/data/4.out new file mode 100644 index 00000000..d67e06d2 --- /dev/null +++ b/LibreOJ/6850/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:83528f9f8b3d12d69f585cf5249624a84619b859cdbf39b06f8af3e5b6b80eb2 +size 225528 diff --git a/LibreOJ/6850/data/5.in b/LibreOJ/6850/data/5.in new file mode 100644 index 00000000..359ae313 --- /dev/null +++ b/LibreOJ/6850/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7dc0e091324c850561612ba40ce8f6601815237dad71f7838ce6edfde8b0aed0 +size 1466143 diff --git a/LibreOJ/6850/data/5.out b/LibreOJ/6850/data/5.out new file mode 100644 index 00000000..4fcc8d48 --- /dev/null +++ b/LibreOJ/6850/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:884386a3e5d3242a2fe913f95bf9f4a421584661e2b70c950b85cf14bcab4633 +size 449984 diff --git a/LibreOJ/6850/data/6.in b/LibreOJ/6850/data/6.in new file mode 100644 index 00000000..4fc31d75 --- /dev/null +++ b/LibreOJ/6850/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:438ce1385bfecdc592813e1559869500474fc065bb754321ca232a79eabdbf35 +size 9308531 diff --git a/LibreOJ/6850/data/6.out b/LibreOJ/6850/data/6.out new file mode 100644 index 00000000..8812ccca --- /dev/null +++ b/LibreOJ/6850/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:270edd617ea8831d495436ddfcaeecfd0cef8412d379e72bc2b707e485699ea3 +size 2699995 diff --git a/LibreOJ/6850/data/7.in b/LibreOJ/6850/data/7.in new file mode 100644 index 00000000..2818d319 --- /dev/null +++ b/LibreOJ/6850/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2edfe7a7882f278bdf49393e1c7ed815e2401afd60787ef1654aef591d4d6905 +size 2359198 diff --git a/LibreOJ/6850/data/7.out b/LibreOJ/6850/data/7.out new file mode 100644 index 00000000..f8d5ccdc --- /dev/null +++ b/LibreOJ/6850/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:72d6c3d4f55326a1ea44b4eff13911ef6cc4f9277e2f413395de9a6cb266a77a +size 719994 diff --git a/LibreOJ/6850/data/8.in b/LibreOJ/6850/data/8.in new file mode 100644 index 00000000..d4886e13 --- /dev/null +++ b/LibreOJ/6850/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:25eba6bddb3a68ec0c5afbc1e405c0a2ceb2e1786d6824f0e56df03ee160c723 +size 1896658 diff --git a/LibreOJ/6850/data/8.out b/LibreOJ/6850/data/8.out new file mode 100644 index 00000000..ba159539 --- /dev/null +++ b/LibreOJ/6850/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3defeb22d19e60da9367f0793b81f0b4d82644aeeecf0f1b41fb5ddb6f10e666 +size 360745 diff --git a/LibreOJ/6850/data/9.in b/LibreOJ/6850/data/9.in new file mode 100644 index 00000000..e4b17811 --- /dev/null +++ b/LibreOJ/6850/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b22bee8263c094a0a989422d0e21ea51e5d2ebc5321601bb340c5a3507ef4dbe +size 85 diff --git a/LibreOJ/6850/data/9.out b/LibreOJ/6850/data/9.out new file mode 100644 index 00000000..b85cae2b --- /dev/null +++ b/LibreOJ/6850/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:98f291387d1ca9b67c9c39151702d020e309f7d813e42811ad01d5c6599a64f8 +size 20