diff --git a/S2OJ/1800/1800.cpp b/S2OJ/1800/1800.cpp new file mode 100644 index 00000000..d924ba88 --- /dev/null +++ b/S2OJ/1800/1800.cpp @@ -0,0 +1,155 @@ +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 5e5 + 5; + +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_max_xor(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, + v = siz[tr[r][x ^ 1]] > siz[tr[l][x ^ 1]] ? (x ^ 1) : x; + + l = tr[l][v]; + r = tr[r][v]; + res |= v << i; + } + + return res; +} + +int query_leq_cnt(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 (x) res += siz[tr[r][0]] - siz[tr[l][0]]; + + l = tr[l][x]; + r = tr[r][x]; + } + + res += siz[r] - siz[l]; + + return res; +} + +int query_kth(int l, int r, int k) { + int res = 0; + + l = root[l], r = root[r]; + + for (int i = 30; i >= 0; i--) { + if (siz[tr[r][0]] - siz[tr[l][0]] >= k) { + l = tr[l][0]; + r = tr[r][0]; + } else { + res += 1 << i; + k -= siz[tr[r][0]] - siz[tr[l][0]]; + + l = tr[l][1]; + r = tr[r][1]; + } + } + + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int q; + + cin >> q; + + while (q--) { + int op; + + cin >> op; + + switch (op) { + case 0: { + int x; + + cin >> x; + + insert(x); + + break; + } + + case 1: { + int l, r, x; + + cin >> l >> r >> x; + + cout << query_max_xor(l - 1, r, x) << endl; + + break; + } + + case 2: { + int k; + + cin >> k; + + cnt = lst[tot -= k]; + + break; + } + + case 3: { + int l, r, x; + + cin >> l >> r >> x; + + cout << query_leq_cnt(l - 1, r, x) << endl; + + break; + } + + case 4: { + int l, r, k; + + cin >> l >> r >> k; + + cout << query_kth(l - 1, r, k) << endl; + + break; + } + } + } + + return 0; +} diff --git a/S2OJ/1800/data/operator1.ans b/S2OJ/1800/data/operator1.ans new file mode 100644 index 00000000..15fddbff --- /dev/null +++ b/S2OJ/1800/data/operator1.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6738a5c7814f1c2941d9b102babc25a4e1961cab6723ffb0ce0bd17b191eccc0 +size 12147 diff --git a/S2OJ/1800/data/operator1.in b/S2OJ/1800/data/operator1.in new file mode 100644 index 00000000..bad7df63 --- /dev/null +++ b/S2OJ/1800/data/operator1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d233bdf691075cd54120c729582397e51aae0753a5366790d1bbd9f9b1c11210 +size 53797 diff --git a/S2OJ/1800/data/operator10.ans b/S2OJ/1800/data/operator10.ans new file mode 100644 index 00000000..33ee0675 --- /dev/null +++ b/S2OJ/1800/data/operator10.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dbb00b492ed6eb65ac3f402e67a8426e18d119435e2e18a6f537ef06d11f1618 +size 1888628 diff --git a/S2OJ/1800/data/operator10.in b/S2OJ/1800/data/operator10.in new file mode 100644 index 00000000..5e1ea65b --- /dev/null +++ b/S2OJ/1800/data/operator10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:44121d22db30d8c333b04b8b63b72f1be34483cca21b99eb166a23a309afabcd +size 7794464 diff --git a/S2OJ/1800/data/operator2.ans b/S2OJ/1800/data/operator2.ans new file mode 100644 index 00000000..f5fa7424 --- /dev/null +++ b/S2OJ/1800/data/operator2.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b76dcab92c88232efbaa22ae97d29089a95b62d1912af397f19cf0faf5e1c35a +size 11860 diff --git a/S2OJ/1800/data/operator2.in b/S2OJ/1800/data/operator2.in new file mode 100644 index 00000000..9960c120 --- /dev/null +++ b/S2OJ/1800/data/operator2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9b1f9b15ce0f448683a947d9ce239ed9fc732b1f19298a4aabc3b961073b05fd +size 53168 diff --git a/S2OJ/1800/data/operator3.ans b/S2OJ/1800/data/operator3.ans new file mode 100644 index 00000000..91df0aba --- /dev/null +++ b/S2OJ/1800/data/operator3.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2904326a06fd93238286be8875645a99fa8dcf0b676b81ae1176fa461a35fa69 +size 267952 diff --git a/S2OJ/1800/data/operator3.in b/S2OJ/1800/data/operator3.in new file mode 100644 index 00000000..d8c10fc7 --- /dev/null +++ b/S2OJ/1800/data/operator3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9c7857d4e5cf458d8532d8c28ce1af6a8b0ec226668bba50fe78365974c31a50 +size 1342470 diff --git a/S2OJ/1800/data/operator4.ans b/S2OJ/1800/data/operator4.ans new file mode 100644 index 00000000..57786504 --- /dev/null +++ b/S2OJ/1800/data/operator4.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:79dfcbf213e071b34b843305dd168893238408b4019ac79221649f06ed2a5a6d +size 244263 diff --git a/S2OJ/1800/data/operator4.in b/S2OJ/1800/data/operator4.in new file mode 100644 index 00000000..62f58b6d --- /dev/null +++ b/S2OJ/1800/data/operator4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:31e440c6c7f882f48bca1169f68e2fb34f98b217e3694101221a8c3d3c462c3b +size 1303974 diff --git a/S2OJ/1800/data/operator5.ans b/S2OJ/1800/data/operator5.ans new file mode 100644 index 00000000..00d11514 --- /dev/null +++ b/S2OJ/1800/data/operator5.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16a323123e3b47849d2473c03d3797d1e8b034735e0a9c9ae7c2a26170005b8a +size 497625 diff --git a/S2OJ/1800/data/operator5.in b/S2OJ/1800/data/operator5.in new file mode 100644 index 00000000..7e960ec8 --- /dev/null +++ b/S2OJ/1800/data/operator5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3f996011354c8ab0506ece3e9f699ffa6f31734ca82cf4fde3b90e09c6cb9a6b +size 2589509 diff --git a/S2OJ/1800/data/operator6.ans b/S2OJ/1800/data/operator6.ans new file mode 100644 index 00000000..0306a613 --- /dev/null +++ b/S2OJ/1800/data/operator6.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:356e5ac1bba140b061074a35cdfe2ea8de7299262becb13a5884ae6fc42c1067 +size 560069 diff --git a/S2OJ/1800/data/operator6.in b/S2OJ/1800/data/operator6.in new file mode 100644 index 00000000..2156c7ee --- /dev/null +++ b/S2OJ/1800/data/operator6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ddee2150bdcb6622dcc6b5c93d0d1515b31137f32322196bf279647d670ac007 +size 2685894 diff --git a/S2OJ/1800/data/operator7.ans b/S2OJ/1800/data/operator7.ans new file mode 100644 index 00000000..964d3b94 --- /dev/null +++ b/S2OJ/1800/data/operator7.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59f5c31ef0b7709d2af3d648c8eeacadce6d656dcd0b972f30a8ae9f90c5aa71 +size 953696 diff --git a/S2OJ/1800/data/operator7.in b/S2OJ/1800/data/operator7.in new file mode 100644 index 00000000..1724c684 --- /dev/null +++ b/S2OJ/1800/data/operator7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3ecc548b0e04fce71fb5ae27373b47b2f9682768cc4040d8362cac581f7d7fc2 +size 4280296 diff --git a/S2OJ/1800/data/operator8.ans b/S2OJ/1800/data/operator8.ans new file mode 100644 index 00000000..29abd592 --- /dev/null +++ b/S2OJ/1800/data/operator8.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:690e6ba3d2a5d88906889c7597561cbbfe40626078fb85c8c29530cfe4bfe9ce +size 953245 diff --git a/S2OJ/1800/data/operator8.in b/S2OJ/1800/data/operator8.in new file mode 100644 index 00000000..c7c18d16 --- /dev/null +++ b/S2OJ/1800/data/operator8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9906765430b322d8fa0f1fb25927cd54f8ea85a4205a734768547db26f0fb298 +size 4278831 diff --git a/S2OJ/1800/data/operator9.ans b/S2OJ/1800/data/operator9.ans new file mode 100644 index 00000000..a423d38e --- /dev/null +++ b/S2OJ/1800/data/operator9.ans @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:858ba37496f9198e5fe01d907a94d46506f9b55f08fde074a309c48ccc89c139 +size 1889065 diff --git a/S2OJ/1800/data/operator9.in b/S2OJ/1800/data/operator9.in new file mode 100644 index 00000000..65797d75 --- /dev/null +++ b/S2OJ/1800/data/operator9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:99007d8a4f16b06eee069778b9607906c3027525533534b1f1310aee02f23560 +size 7800336 diff --git a/S2OJ/1800/data/problem.conf b/S2OJ/1800/data/problem.conf new file mode 100644 index 00000000..4e43762d --- /dev/null +++ b/S2OJ/1800/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dcf908054c9da65549ec78e124325b36965e16b170b74eea5bafde282d233a88 +size 187