diff --git a/S2OJ/1612/1612.cpp b/S2OJ/1612/1612.cpp new file mode 100644 index 00000000..74573749 --- /dev/null +++ b/S2OJ/1612/1612.cpp @@ -0,0 +1,119 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 5e5 + 5; + +int n, m, fa[N]; +std::vector son[N]; + +struct node { + int l, r, max, min; + + node(int _l = 0, int _r = 0) + : l(_l), + r(_r), + max(std::numeric_limits::min()), + min(std::numeric_limits::max()) {} +} tr[N << 2]; + +void pushup(int u) { + tr[u].max = std::max(tr[u << 1].max, tr[u << 1 | 1].max); + tr[u].min = std::min(tr[u << 1].min, tr[u << 1 | 1].min); +} + +void build(int u, int l, int r) { + tr[u] = node(l, r); + + if (l == r) { + tr[u].max = tr[u].min = l; + + return; + } + + int mid = (l + r) >> 1; + + build(u << 1, l, mid); + build(u << 1 | 1, mid + 1, r); + + pushup(u); +} + +void modify(int u, int x, int v) { + if (tr[u].l == tr[u].r) { + tr[u].max = tr[u].min = v; + + return; + } + + int mid = (tr[u].l + tr[u].r) >> 1; + + if (x <= mid) modify(u << 1, x, v); + else modify(u << 1 | 1, x, v); + + pushup(u); +} + +std::pair query(int u, int l, int r) { + if (l <= tr[u].l && tr[u].r <= r) return std::make_pair(tr[u].max, tr[u].min); + + int mid = (tr[u].l + tr[u].r) >> 1; + + if (r <= mid) return query(u << 1, l, r); + if (l > mid) return query(u << 1 | 1, l, r); + + auto res1 = query(u << 1, l, r); + auto res2 = query(u << 1 | 1, l, r); + + return std::make_pair(std::max(res1.first, res2.first), std::min(res1.second, res2.second)); +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1; i <= n; i++) { + fa[i] = i; + + son[i].emplace_back(i); + } + + build(1, 1, n); + + while (m--) { + int op, l, r; + + cin >> op >> l >> r; + + if (op == 1) { + int x = fa[l], + y = fa[r]; + + if (x != y) { + if (son[x].size() < son[y].size()) std::swap(x, y); + + for (int v : son[y]) { + modify(1, v, fa[v] = x); + son[x].emplace_back(v); + } + + son[y].clear(); + } + } else { // op == 2 + if (l > r) std::swap(l, r); + + auto res = query(1, l, r); + + cout << (res.first == res.second ? "zzy" : "orz") << endl; + } + } + + return 0; +} diff --git a/S2OJ/1612/data/ex_graph1.in b/S2OJ/1612/data/ex_graph1.in new file mode 100644 index 00000000..f6b12e92 --- /dev/null +++ b/S2OJ/1612/data/ex_graph1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:91ffbab65f82d3188e070a8266b3ec3bae8ef031a55b805d200678ef9868e361 +size 34 diff --git a/S2OJ/1612/data/ex_graph1.out b/S2OJ/1612/data/ex_graph1.out new file mode 100644 index 00000000..808c05b9 --- /dev/null +++ b/S2OJ/1612/data/ex_graph1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bcdb05f10c255159cfbc7c618f8424902d26037a45dc28b316b6d1d263588350 +size 8 diff --git a/S2OJ/1612/data/ex_graph2.in b/S2OJ/1612/data/ex_graph2.in new file mode 100644 index 00000000..4f3d52ec --- /dev/null +++ b/S2OJ/1612/data/ex_graph2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d2f0cebdfdc26eacbe42b3065a24e4e62a2afffbc3887f2b6726400e732a10f8 +size 6778119 diff --git a/S2OJ/1612/data/ex_graph2.out b/S2OJ/1612/data/ex_graph2.out new file mode 100644 index 00000000..382fe04d --- /dev/null +++ b/S2OJ/1612/data/ex_graph2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a36593b30c66308f3468bdc5d47fbafbadb67a2e30baf30032b992079762b894 +size 502916 diff --git a/S2OJ/1612/data/graph1.in b/S2OJ/1612/data/graph1.in new file mode 100644 index 00000000..eb8b4751 --- /dev/null +++ b/S2OJ/1612/data/graph1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:776ced3897d864d00479a09017ddfa31c79b5b1d91579f250f63f071e4436fc2 +size 9115 diff --git a/S2OJ/1612/data/graph1.out b/S2OJ/1612/data/graph1.out new file mode 100644 index 00000000..ea93ed6c --- /dev/null +++ b/S2OJ/1612/data/graph1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:faa6e675a6eb9ffa165894f8e718e985e43de003ee7f57d94af94daba0203b95 +size 768 diff --git a/S2OJ/1612/data/graph10.in b/S2OJ/1612/data/graph10.in new file mode 100644 index 00000000..192dbc4e --- /dev/null +++ b/S2OJ/1612/data/graph10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d8235ee63754ba1480ca2ccaaf1d846176e85256c089c9f04d91c3a6311f216e +size 4393363 diff --git a/S2OJ/1612/data/graph10.out b/S2OJ/1612/data/graph10.out new file mode 100644 index 00000000..f3169636 --- /dev/null +++ b/S2OJ/1612/data/graph10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:68972bbdb534ac0e44043c987daa494c8d000d2391260b016f2b5dd919b08900 +size 359444 diff --git a/S2OJ/1612/data/graph11.in b/S2OJ/1612/data/graph11.in new file mode 100644 index 00000000..0c96e4a0 --- /dev/null +++ b/S2OJ/1612/data/graph11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c45216c17780a10d70346769e02429971572fabb872f6ca200b814591c57439 +size 4394861 diff --git a/S2OJ/1612/data/graph11.out b/S2OJ/1612/data/graph11.out new file mode 100644 index 00000000..0f4eeb06 --- /dev/null +++ b/S2OJ/1612/data/graph11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ec21306ba6376ee60060360189d9fa163d7582e6a5b2be7db7e8cb396631707b +size 360664 diff --git a/S2OJ/1612/data/graph12.in b/S2OJ/1612/data/graph12.in new file mode 100644 index 00000000..4fb8cb6b --- /dev/null +++ b/S2OJ/1612/data/graph12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9db47272c499ca72be9fd2844a8476cf0a4375ef53aabc1e4efbc635d62c9e20 +size 7571780 diff --git a/S2OJ/1612/data/graph12.out b/S2OJ/1612/data/graph12.out new file mode 100644 index 00000000..0ec362c7 --- /dev/null +++ b/S2OJ/1612/data/graph12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:446439dfff481446f4580f15d0cece24ea22b5a4535b93624047919181abd061 +size 558132 diff --git a/S2OJ/1612/data/graph13.in b/S2OJ/1612/data/graph13.in new file mode 100644 index 00000000..3cee13ef --- /dev/null +++ b/S2OJ/1612/data/graph13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a5f3a702396bfc06e82ad367457e869a13a640fd9e619793b70b96397c592dce +size 7576649 diff --git a/S2OJ/1612/data/graph13.out b/S2OJ/1612/data/graph13.out new file mode 100644 index 00000000..b967fff9 --- /dev/null +++ b/S2OJ/1612/data/graph13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a1768dc7c1858a42c78caeea72b836eb62482994b83dc098df8a9181a2cc5e1 +size 559576 diff --git a/S2OJ/1612/data/graph14.in b/S2OJ/1612/data/graph14.in new file mode 100644 index 00000000..e91126a4 --- /dev/null +++ b/S2OJ/1612/data/graph14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2991fae4d26f61d62ea0123d4649145380a2a119d6936725aa2fcca000cbd1d5 +size 1289860 diff --git a/S2OJ/1612/data/graph14.out b/S2OJ/1612/data/graph14.out new file mode 100644 index 00000000..b30efe36 --- /dev/null +++ b/S2OJ/1612/data/graph14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:41242921c625edc898faf6f1d754b9d3eb4ac06fa2fec30cbd59dafb80477301 +size 160264 diff --git a/S2OJ/1612/data/graph15.in b/S2OJ/1612/data/graph15.in new file mode 100644 index 00000000..e8dd60ff --- /dev/null +++ b/S2OJ/1612/data/graph15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2f4f89c0a8c5f0aedafe06ce0b1aad039587b05da7a1984265a78786f086f08a +size 1289974 diff --git a/S2OJ/1612/data/graph15.out b/S2OJ/1612/data/graph15.out new file mode 100644 index 00000000..3a0195c5 --- /dev/null +++ b/S2OJ/1612/data/graph15.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d9f3a81d9cdb96a533641a9d4fe9efc8ad106faddd91ba74b468f017e8f5f9b6 +size 159576 diff --git a/S2OJ/1612/data/graph16.in b/S2OJ/1612/data/graph16.in new file mode 100644 index 00000000..a27679f9 --- /dev/null +++ b/S2OJ/1612/data/graph16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a355e73a7901997d7e4a97209fbd0e7571673bb17ab595b69cae14db5a4f4e79 +size 1262164 diff --git a/S2OJ/1612/data/graph16.out b/S2OJ/1612/data/graph16.out new file mode 100644 index 00000000..6f232d0b --- /dev/null +++ b/S2OJ/1612/data/graph16.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d5e67442822fbf6505a07f7371d9467a6e9baf286506d8d34ce81cc983021f10 +size 200144 diff --git a/S2OJ/1612/data/graph17.in b/S2OJ/1612/data/graph17.in new file mode 100644 index 00000000..0003f6c1 --- /dev/null +++ b/S2OJ/1612/data/graph17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4cbb24649137bbcd76aa4927735e7793e714fee737f1684f597ba376ce169236 +size 7537949 diff --git a/S2OJ/1612/data/graph17.out b/S2OJ/1612/data/graph17.out new file mode 100644 index 00000000..bc57262f --- /dev/null +++ b/S2OJ/1612/data/graph17.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c2eb6f77811ab8719b1bd4b960f29e9bd49508f576b5f3a6e102df359e2eaecb +size 609896 diff --git a/S2OJ/1612/data/graph18.in b/S2OJ/1612/data/graph18.in new file mode 100644 index 00000000..212f4225 --- /dev/null +++ b/S2OJ/1612/data/graph18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e4f872487fa392f404ff1cb4319552036a07519316055f2b20945499884fb1e3 +size 7550393 diff --git a/S2OJ/1612/data/graph18.out b/S2OJ/1612/data/graph18.out new file mode 100644 index 00000000..f9dbdd72 --- /dev/null +++ b/S2OJ/1612/data/graph18.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8ec941a5dfef52169a849a704afd57b389f7f56889afc879c25f3f3d7b78dccc +size 610168 diff --git a/S2OJ/1612/data/graph19.in b/S2OJ/1612/data/graph19.in new file mode 100644 index 00000000..51fa359e --- /dev/null +++ b/S2OJ/1612/data/graph19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3d9ec90a7d69ba0e03635a8ff8508564dc3785ce7ac82b41365055a702ef6c62 +size 7536485 diff --git a/S2OJ/1612/data/graph19.out b/S2OJ/1612/data/graph19.out new file mode 100644 index 00000000..6c33b6ea --- /dev/null +++ b/S2OJ/1612/data/graph19.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:813971fbc4c113a61ec060b9bd959504e0d3e9749390ae6052956f157e75e517 +size 610256 diff --git a/S2OJ/1612/data/graph2.in b/S2OJ/1612/data/graph2.in new file mode 100644 index 00000000..354bc24c --- /dev/null +++ b/S2OJ/1612/data/graph2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4f3b6474409181f425c4e44b3668e01d524871f0c603ed5d7a4d5e3a8e041cd6 +size 9648 diff --git a/S2OJ/1612/data/graph2.out b/S2OJ/1612/data/graph2.out new file mode 100644 index 00000000..5dc9ff89 --- /dev/null +++ b/S2OJ/1612/data/graph2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a9163f23477b8fbef715da72abfcd996b5972763a3a54852a0f56fcc65fb6535 +size 360 diff --git a/S2OJ/1612/data/graph20.in b/S2OJ/1612/data/graph20.in new file mode 100644 index 00000000..26193ee6 --- /dev/null +++ b/S2OJ/1612/data/graph20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:33c41db07bd164a679e8e97fed184ade1d38110e180c8dde9810205ef57748a6 +size 7537170 diff --git a/S2OJ/1612/data/graph20.out b/S2OJ/1612/data/graph20.out new file mode 100644 index 00000000..ee8e0b7b --- /dev/null +++ b/S2OJ/1612/data/graph20.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d97dbc8c7c5d5dfc384f0e21e696bd60d9d932a4fa5325a0e493e9088bffa457 +size 611684 diff --git a/S2OJ/1612/data/graph3.in b/S2OJ/1612/data/graph3.in new file mode 100644 index 00000000..222d033c --- /dev/null +++ b/S2OJ/1612/data/graph3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:663efc6a83ce45d621663176f6c037b2e81e830d1c27f2ed0dd24d01e0f547ff +size 9805 diff --git a/S2OJ/1612/data/graph3.out b/S2OJ/1612/data/graph3.out new file mode 100644 index 00000000..85641fc8 --- /dev/null +++ b/S2OJ/1612/data/graph3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c99386702fea823bbcc31e5e7b507c0737f28a756dc04610bfa2cb37cfb3f59 +size 1952 diff --git a/S2OJ/1612/data/graph4.in b/S2OJ/1612/data/graph4.in new file mode 100644 index 00000000..ed213c16 --- /dev/null +++ b/S2OJ/1612/data/graph4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c534bb4ee0a66373edd9e0a81cbbc51fd2b789ad97e186af075e86b0c2f2eeec +size 9592 diff --git a/S2OJ/1612/data/graph4.out b/S2OJ/1612/data/graph4.out new file mode 100644 index 00000000..a8041f24 --- /dev/null +++ b/S2OJ/1612/data/graph4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7580a629b6cb1c681fd01233a0e0e6c6122c1bbb4b6f2c466bdf80033631ce4b +size 1980 diff --git a/S2OJ/1612/data/graph5.in b/S2OJ/1612/data/graph5.in new file mode 100644 index 00000000..9a473172 --- /dev/null +++ b/S2OJ/1612/data/graph5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5d5b8ec772a76c7a71a6490e65c45a56494ff755846aac63d7c9725605c377a8 +size 9819 diff --git a/S2OJ/1612/data/graph5.out b/S2OJ/1612/data/graph5.out new file mode 100644 index 00000000..fc8badb4 --- /dev/null +++ b/S2OJ/1612/data/graph5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b41542e54804a99cd11053d4618c869a73dd73b571a4a6421a7b246dbacbab45 +size 1384 diff --git a/S2OJ/1612/data/graph6.in b/S2OJ/1612/data/graph6.in new file mode 100644 index 00000000..f5ecd578 --- /dev/null +++ b/S2OJ/1612/data/graph6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:706f53579a3b376ebdbc7c1ccd37fe5ceb5df1c723aecdfb3691096ee9e58e7f +size 7777697 diff --git a/S2OJ/1612/data/graph6.out b/S2OJ/1612/data/graph6.out new file mode 100644 index 00000000..ed9329d4 --- /dev/null +++ b/S2OJ/1612/data/graph6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:baa35e9b7f4c470dce9219a9d1a9d2ae07c765fbe937ec8fdf917e9edb91fe12 +size 1000936 diff --git a/S2OJ/1612/data/graph7.in b/S2OJ/1612/data/graph7.in new file mode 100644 index 00000000..a8a00096 --- /dev/null +++ b/S2OJ/1612/data/graph7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b857d4a14c87e0105561a9a99a76d6442172d027c93333ef9be7ed09c86df2b0 +size 7776977 diff --git a/S2OJ/1612/data/graph7.out b/S2OJ/1612/data/graph7.out new file mode 100644 index 00000000..aa0c8d03 --- /dev/null +++ b/S2OJ/1612/data/graph7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:caf4fd28abcb0fe9fcf6652ccf61de064452d0232b5f1d492833033443cf3268 +size 667024 diff --git a/S2OJ/1612/data/graph8.in b/S2OJ/1612/data/graph8.in new file mode 100644 index 00000000..3b8b9ab4 --- /dev/null +++ b/S2OJ/1612/data/graph8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c9e722c1d249587e34074a37192189310e0576523906f60c71f2bd28c36f750 +size 7777075 diff --git a/S2OJ/1612/data/graph8.out b/S2OJ/1612/data/graph8.out new file mode 100644 index 00000000..7c9ba500 --- /dev/null +++ b/S2OJ/1612/data/graph8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb448449131e4b4416b4009175b775008a271121b55d5bba094e48d69f7463e9 +size 499280 diff --git a/S2OJ/1612/data/graph9.in b/S2OJ/1612/data/graph9.in new file mode 100644 index 00000000..33d36ede --- /dev/null +++ b/S2OJ/1612/data/graph9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e0874ba377304fd9b950967558006ab5760f51e331563ad62d3db8755e2af667 +size 7777840 diff --git a/S2OJ/1612/data/graph9.out b/S2OJ/1612/data/graph9.out new file mode 100644 index 00000000..7c69be0d --- /dev/null +++ b/S2OJ/1612/data/graph9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d1a6621045bef2f73fa9894a19259be285ed0ea6eb3b6621c41fbaf1fd464e04 +size 501720 diff --git a/S2OJ/1612/data/problem.conf b/S2OJ/1612/data/problem.conf new file mode 100644 index 00000000..206724d8 --- /dev/null +++ b/S2OJ/1612/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2ed5a9ce0d729e7355402488f177fbb11b0ca16d9642214943d957c1f4f32699 +size 179