from copy import deepcopy
def test_all(f):
for i, data in enumerate(eval(f'test_data{f.__name__[0]}')):
exp = data["out"]
ans = f(*deepcopy(data["in"]))
result = "AC" if exp == ans else "WA"
print(f"{i+1} {result}: expected: {exp}, output: {ans}")
from io import StringIO
def C(N, Q, TAB):
out = StringIO()
usr = {}
for t, a, b in TAB:
if t == 1:
if a in usr:
usr[a].add(b)
else:
usr[a] = set([b])
elif t == 2:
if a in usr:
try: usr[a].remove(b)
except: pass
else:
print("Yes" if a in usr and b in usr and b in usr[a] and a in usr[b] else "No", file=out)
return out.getvalue()test_all(C)
from collections import defaultdict
def C(N, Q, TAB):
out = StringIO()
friends = defaultdict(set)
for t, a, b in TAB:
if t == 1:
friends[a].add(b)
elif t == 2:
try: friends[a].remove(b)
except: pass
else:
print("Yes" if b in friends[a] and a in friends[b] else "No", file=out)
return out.getvalue()
test_all(C)
def C(N, Q, TAB):
out = StringIO()
friends = set()
for t, a, b in TAB:
if t == 1:
friends.add((a, b))
elif t == 2:
try: friends.remove((a, b))
except: pass
else:
print("Yes" if (a, b) in friends and (b, a) in friends else "No", file=out)
return out.getvalue()
test_all(C)
def D(N, A, Q, query):
out = StringIO()
for i, *q in query:
# print(A)
if i == 1:
allA = q[0]
A = {}
elif i == 2:
if q[0] in A:
A[q[0]] += q[1]
else:
A[q[0]] = allA + q[1]
else:
print(A[q[0]] if q[0] in A else allA, file=out)
return out.getvalue()test_all(D)
from collections import defaultdict
def D(N, A, Q, query):
out = StringIO()
for i, *q in query:
if i == 1:
ini = q[0]
A = defaultdict(lambda: ini)
elif i == 2:
A[q[0]] += q[1]
else:
print(A[q[0]], file=out)
return out.getvalue()test_all(D)
from collections import defaultdict
def E(H, W, N, h, w, A):
out = StringIO()
loc = defaultdict(lambda: dict(minx=W, maxx=0, miny=H, maxy=0))
for i, row in enumerate(A):
for j, a in enumerate(row):
loc[a]["minx"] = min(loc[a]["minx"], j)
loc[a]["maxx"] = max(loc[a]["maxx"], j)
loc[a]["miny"] = min(loc[a]["miny"], i)
loc[a]["maxy"] = max(loc[a]["maxy"], i)
for i in range(H - h + 1):
ans = []
for j in range(W - w + 1):
ans.append(0)
for v in loc.values():
if (
v["minx"] >= j and
v["maxx"] <= j + w - 1 and
v["miny"] >= i and
v["maxy"] <= i + h - 1
): pass
else: ans[-1] += 1
print(*ans, file=out)
return out.getvalue()test_all(E)