mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 21:08:47 +00:00
parent
8eaf5442ec
commit
b1d87c3ee5
77
S2OJ/138/138.cpp
Normal file
77
S2OJ/138/138.cpp
Normal file
@ -0,0 +1,77 @@
|
||||
#include <iostream>
|
||||
#include <algorithm>
|
||||
#include <iterator>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 2e5 + 5;
|
||||
const int mod = 998244353;
|
||||
|
||||
int n, m, fa[N << 1], s[N << 1];
|
||||
|
||||
constexpr int binpow(int a, int b, int mod = ::mod) {
|
||||
int res = 1;
|
||||
|
||||
while (b) {
|
||||
if (b & 1) res = static_cast<long long>(res) * a % mod;
|
||||
a = static_cast<long long>(a) * a % mod;
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int find(int x) {
|
||||
return fa[x] == x ? x : find(fa[x]);
|
||||
}
|
||||
|
||||
int query(int x) {
|
||||
int res = binpow(3, n);
|
||||
|
||||
while (fa[x] != x) {
|
||||
res = static_cast<long long>(res) * s[x] % mod;
|
||||
x = fa[x];
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> m;
|
||||
|
||||
std::iota(std::begin(fa), std::end(fa), 0);
|
||||
std::fill(std::begin(s), std::end(s), 1);
|
||||
|
||||
for (int i = 1, op; i <= m; i++) {
|
||||
cin >> op;
|
||||
|
||||
if (op == 1) {
|
||||
int u, v;
|
||||
|
||||
cin >> u >> v;
|
||||
|
||||
int x = find(u),
|
||||
y = find(v);
|
||||
|
||||
s[x] = 2 * binpow(3, mod - 2) % mod;
|
||||
s[y] = binpow(3, mod - 2) % mod;
|
||||
fa[x] = n + i;
|
||||
fa[y] = n + i;
|
||||
} else { // op == 2
|
||||
int u;
|
||||
|
||||
cin >> u;
|
||||
|
||||
cout << query(u) << endl;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
BIN
S2OJ/138/data/cong1.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong1.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong10.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong10.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong11.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong11.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong11.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong11.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong12.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong12.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong12.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong12.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong13.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong13.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong13.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong13.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong14.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong14.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong14.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong14.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong15.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong15.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong15.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong15.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong16.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong16.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong16.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong16.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong17.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong17.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong17.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong17.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong18.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong18.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong18.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong18.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong19.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong19.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong19.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong19.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong2.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong2.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong20.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong20.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong20.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong20.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong3.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong3.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong4.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong4.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong5.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong5.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong6.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong6.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong7.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong7.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong8.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong8.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong9.ans
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong9.ans
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/cong9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/cong9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/138/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/138/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user