Skip to content

Commit fd4ea95

Browse files
committed
🥺chore
1 parent 48e9809 commit fd4ea95

File tree

15 files changed

+798
-22
lines changed

15 files changed

+798
-22
lines changed

practice2/a/main.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!usr/bin/env python3
2+
from collections import defaultdict, deque, Counter, OrderedDict
3+
from bisect import bisect_left, bisect_right
4+
from functools import reduce, lru_cache
5+
from heapq import heappush, heappop, heapify
6+
7+
import itertools
8+
import math, fractions
9+
import sys, copy
10+
11+
def L(): return sys.stdin.readline().split()
12+
def I(): return int(sys.stdin.readline().rstrip())
13+
def SL(): return list(sys.stdin.readline().rstrip())
14+
def LI(): return [int(x) for x in sys.stdin.readline().split()]
15+
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
16+
def LS(): return [list(x) for x in sys.stdin.readline().split()]
17+
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
18+
def LR(n): return [L() for _ in range(n)]
19+
def IR(n): return [I() for _ in range(n)]
20+
def LIR(n): return [LI() for _ in range(n)]
21+
def LIR1(n): return [LI1() for _ in range(n)]
22+
def SR(n): return [SL() for _ in range(n)]
23+
def LSR(n): return [LS() for _ in range(n)]
24+
25+
def perm(n, r): return math.factorial(n) // math.factorial(r)
26+
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
27+
28+
def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
29+
30+
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
31+
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
32+
alphabets = "abcdefghijklmnopqrstuvwxyz"
33+
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34+
MOD = 1000000007
35+
INF = float("inf")
36+
37+
sys.setrecursionlimit(1000000)
38+
39+
class UnionFind:
40+
def __init__(self, N): self.N, self.group_count, self.root, self.rank = N, N, [-1] * N, [0] * N
41+
def __repr__(self): return str(self.all_groups())
42+
43+
def find(self, x):
44+
while self.root[x] >= 0: x = self.root[x]
45+
return x
46+
47+
def union(self, x, y):
48+
x, y = self.find(x), self.find(y)
49+
if x == y: return
50+
if self.rank[x] > self.rank[y]: x, y = y, x
51+
self.root[y] += self.root[x]
52+
self.root[x] = y
53+
if self.rank[x] == self.rank[y]: self.rank[y] += 1
54+
self.group_count -= 1
55+
56+
def same(self, x, y): return self.find(x) == self.find(y)
57+
def count(self, x): return -self.root[self.find(x)]
58+
def members(self, x): return [i for i in range(self.N) if self.same(x, i)]
59+
def roots(self): return [i for i, x in enumerate(self.root) if x < 0]
60+
def all_groups(self):
61+
d = defaultdict(lambda: [])
62+
for i in range(self.N): d[self.find(i)].append(i)
63+
return dict(d)
64+
65+
66+
def main():
67+
N, Q = LI()
68+
TUV = LIR(Q)
69+
70+
uf = UnionFind(N)
71+
72+
for t, u, v in TUV:
73+
if t == 0:
74+
uf.union(u, v)
75+
else:
76+
print(int(uf.same(u, v)))
77+
78+
if __name__ == '__main__':
79+
main()

practice2/b/main.py

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!usr/bin/env python3
2+
from collections import defaultdict, deque, Counter, OrderedDict
3+
from bisect import bisect_left, bisect_right
4+
from functools import reduce, lru_cache
5+
from heapq import heappush, heappop, heapify
6+
7+
import itertools
8+
import math, fractions
9+
import sys, copy
10+
11+
def L(): return sys.stdin.readline().split()
12+
def I(): return int(sys.stdin.readline().rstrip())
13+
def SL(): return list(sys.stdin.readline().rstrip())
14+
def LI(): return [int(x) for x in sys.stdin.readline().split()]
15+
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
16+
def LS(): return [list(x) for x in sys.stdin.readline().split()]
17+
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
18+
def LR(n): return [L() for _ in range(n)]
19+
def IR(n): return [I() for _ in range(n)]
20+
def LIR(n): return [LI() for _ in range(n)]
21+
def LIR1(n): return [LI1() for _ in range(n)]
22+
def SR(n): return [SL() for _ in range(n)]
23+
def LSR(n): return [LS() for _ in range(n)]
24+
25+
def perm(n, r): return math.factorial(n) // math.factorial(r)
26+
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
27+
28+
def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
29+
30+
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
31+
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
32+
alphabets = "abcdefghijklmnopqrstuvwxyz"
33+
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34+
MOD = 1000000007
35+
INF = float("inf")
36+
37+
sys.setrecursionlimit(1000000)
38+
39+
class BIT:
40+
def __init__(self, li):
41+
self.n, self.data = len(li) + 1, [0] + li
42+
for i in range(1, self.n):
43+
if i + (i & -i) < self.n: self.data[i + (i & -i)] += self.data[i]
44+
45+
def add(self, i, a):
46+
i += 1
47+
while i < self.n:
48+
self.data[i] += a
49+
i += i & -i
50+
51+
# sum of [0, i)
52+
def acc(self, i):
53+
res = 0
54+
while i > 0:
55+
res += self.data[i]
56+
i -= i & -i
57+
return res
58+
59+
# sum of [l, r)
60+
def get(self, l, r = None):
61+
if r is None: r = l+1
62+
return self.acc(r) - self.acc(l)
63+
64+
65+
def main():
66+
N, Q = LI()
67+
A = LI()
68+
query = LIR(Q)
69+
bit = BIT(A)
70+
71+
for a, b, c in query:
72+
if a == 0:
73+
bit.add(b, c)
74+
else:
75+
print(bit.get(b, c))
76+
77+
78+
79+
80+
if __name__ == '__main__':
81+
main()

practice2/c/main.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!usr/bin/env python3
2+
from collections import defaultdict, deque, Counter, OrderedDict
3+
from bisect import bisect_left, bisect_right
4+
from functools import reduce, lru_cache
5+
from heapq import heappush, heappop, heapify
6+
7+
import itertools
8+
import math, fractions
9+
import sys, copy
10+
11+
def L(): return sys.stdin.readline().split()
12+
def I(): return int(sys.stdin.readline().rstrip())
13+
def SL(): return list(sys.stdin.readline().rstrip())
14+
def LI(): return [int(x) for x in sys.stdin.readline().split()]
15+
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
16+
def LS(): return [list(x) for x in sys.stdin.readline().split()]
17+
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
18+
def LR(n): return [L() for _ in range(n)]
19+
def IR(n): return [I() for _ in range(n)]
20+
def LIR(n): return [LI() for _ in range(n)]
21+
def LIR1(n): return [LI1() for _ in range(n)]
22+
def SR(n): return [SL() for _ in range(n)]
23+
def LSR(n): return [LS() for _ in range(n)]
24+
25+
def perm(n, r): return math.factorial(n) // math.factorial(r)
26+
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
27+
28+
def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
29+
30+
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
31+
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
32+
alphabets = "abcdefghijklmnopqrstuvwxyz"
33+
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34+
MOD = 1000000007
35+
INF = float("inf")
36+
37+
sys.setrecursionlimit(1000000)
38+
39+
def main():
40+
N = I()
41+
42+
if __name__ == '__main__':
43+
main()

practice2/contest.acc.json

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
"contest": {
3+
"id": "practice2",
4+
"title": "AtCoder Library Practice Contest",
5+
"url": "https://atcoder.jp/contests/practice2"
6+
},
7+
"tasks": [
8+
{
9+
"id": "practice2_a",
10+
"label": "A",
11+
"title": "Disjoint Set Union",
12+
"url": "https://atcoder.jp/contests/practice2/tasks/practice2_a",
13+
"directory": {
14+
"path": "a",
15+
"testdir": "test",
16+
"submit": "main.py"
17+
}
18+
},
19+
{
20+
"id": "practice2_b",
21+
"label": "B",
22+
"title": "Fenwick Tree",
23+
"url": "https://atcoder.jp/contests/practice2/tasks/practice2_b",
24+
"directory": {
25+
"path": "b",
26+
"testdir": "test",
27+
"submit": "main.py"
28+
}
29+
},
30+
{
31+
"id": "practice2_c",
32+
"label": "C",
33+
"title": "Floor Sum",
34+
"url": "https://atcoder.jp/contests/practice2/tasks/practice2_c",
35+
"directory": {
36+
"path": "c",
37+
"testdir": "test",
38+
"submit": "main.py"
39+
}
40+
},
41+
{
42+
"id": "practice2_d",
43+
"label": "D",
44+
"title": "Maxflow",
45+
"url": "https://atcoder.jp/contests/practice2/tasks/practice2_d",
46+
"directory": {
47+
"path": "d",
48+
"testdir": "test",
49+
"submit": "main.py"
50+
}
51+
},
52+
{
53+
"id": "practice2_e",
54+
"label": "E",
55+
"title": "MinCostFlow",
56+
"url": "https://atcoder.jp/contests/practice2/tasks/practice2_e",
57+
"directory": {
58+
"path": "e",
59+
"testdir": "test",
60+
"submit": "main.py"
61+
}
62+
},
63+
{
64+
"id": "practice2_f",
65+
"label": "F",
66+
"title": "Convolution",
67+
"url": "https://atcoder.jp/contests/practice2/tasks/practice2_f",
68+
"directory": {
69+
"path": "f",
70+
"testdir": "test",
71+
"submit": "main.py"
72+
}
73+
},
74+
{
75+
"id": "practice2_g",
76+
"label": "G",
77+
"title": "SCC",
78+
"url": "https://atcoder.jp/contests/practice2/tasks/practice2_g",
79+
"directory": {
80+
"path": "g",
81+
"testdir": "test",
82+
"submit": "main.py"
83+
}
84+
},
85+
{
86+
"id": "practice2_h",
87+
"label": "H",
88+
"title": "Two SAT",
89+
"url": "https://atcoder.jp/contests/practice2/tasks/practice2_h",
90+
"directory": {
91+
"path": "h",
92+
"testdir": "test",
93+
"submit": "main.py"
94+
}
95+
},
96+
{
97+
"id": "practice2_i",
98+
"label": "I",
99+
"title": "Number of Substrings",
100+
"url": "https://atcoder.jp/contests/practice2/tasks/practice2_i",
101+
"directory": {
102+
"path": "i",
103+
"testdir": "test",
104+
"submit": "main.py"
105+
}
106+
},
107+
{
108+
"id": "practice2_j",
109+
"label": "J",
110+
"title": "Segment Tree",
111+
"url": "https://atcoder.jp/contests/practice2/tasks/practice2_j",
112+
"directory": {
113+
"path": "j",
114+
"testdir": "test",
115+
"submit": "main.py"
116+
}
117+
},
118+
{
119+
"id": "practice2_k",
120+
"label": "K",
121+
"title": "Range Affine Range Sum",
122+
"url": "https://atcoder.jp/contests/practice2/tasks/practice2_k",
123+
"directory": {
124+
"path": "k",
125+
"testdir": "test",
126+
"submit": "main.py"
127+
}
128+
},
129+
{
130+
"id": "practice2_l",
131+
"label": "L",
132+
"title": "Lazy Segment Tree",
133+
"url": "https://atcoder.jp/contests/practice2/tasks/practice2_l",
134+
"directory": {
135+
"path": "l",
136+
"testdir": "test",
137+
"submit": "main.py"
138+
}
139+
}
140+
]
141+
}

practice2/d/main.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!usr/bin/env python3
2+
from collections import defaultdict, deque, Counter, OrderedDict
3+
from bisect import bisect_left, bisect_right
4+
from functools import reduce, lru_cache
5+
from heapq import heappush, heappop, heapify
6+
7+
import itertools
8+
import math, fractions
9+
import sys, copy
10+
11+
def L(): return sys.stdin.readline().split()
12+
def I(): return int(sys.stdin.readline().rstrip())
13+
def SL(): return list(sys.stdin.readline().rstrip())
14+
def LI(): return [int(x) for x in sys.stdin.readline().split()]
15+
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
16+
def LS(): return [list(x) for x in sys.stdin.readline().split()]
17+
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
18+
def LR(n): return [L() for _ in range(n)]
19+
def IR(n): return [I() for _ in range(n)]
20+
def LIR(n): return [LI() for _ in range(n)]
21+
def LIR1(n): return [LI1() for _ in range(n)]
22+
def SR(n): return [SL() for _ in range(n)]
23+
def LSR(n): return [LS() for _ in range(n)]
24+
25+
def perm(n, r): return math.factorial(n) // math.factorial(r)
26+
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
27+
28+
def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
29+
30+
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
31+
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
32+
alphabets = "abcdefghijklmnopqrstuvwxyz"
33+
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34+
MOD = 1000000007
35+
INF = float("inf")
36+
37+
sys.setrecursionlimit(1000000)
38+
39+
def main():
40+
N = I()
41+
42+
if __name__ == '__main__':
43+
main()

0 commit comments

Comments
 (0)