Skip to content

Commit b510c72

Browse files
Codeforces Round 950
1 parent da3886b commit b510c72

File tree

48 files changed

+1425
-82
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+1425
-82
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR = ((-1, 0), (0, 1), (1, 0), (0, -1))
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
16+
def solve() -> None:
17+
n, l, r = mint()
18+
ans = list(range(1, l)) + list(range(r, l - 1, -1)) + list(range(r + 1, n + 1))
19+
print(*ans)
20+
21+
22+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR = ((-1, 0), (0, 1), (1, 0), (0, -1))
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
16+
def solve() -> None:
17+
n, m = mint()
18+
nums = ints()
19+
for _ in range(n):
20+
food = ints()
21+
for i, x in enumerate(food):
22+
nums[i] -= x
23+
print("Yes" if all(x <= 0 for x in nums) else "No")
24+
25+
26+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR = ((-1, 0), (0, 1), (1, 0), (0, -1))
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
16+
def solve() -> None:
17+
n, m, k = mint()
18+
keys = [[] for _ in range(m)]
19+
R = [False] * m
20+
for i in range(m):
21+
s = input().split()
22+
if s.pop() == 'o':
23+
R[i] = True
24+
for c in s[1:]:
25+
keys[i].append(int(c) - 1)
26+
def check(mask: int) -> int:
27+
for i in range(m):
28+
cnt = 0
29+
for j in keys[i]:
30+
cnt += (mask >> j) & 1
31+
if (cnt >= k) != R[i]:
32+
return 0
33+
return 1
34+
ans = sum(check(mask) for mask in range(1 << n))
35+
print(ans)
36+
37+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR = ((-1, 0), (0, 1), (1, 0), (0, -1))
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
16+
def solve() -> None:
17+
n, m = mint()
18+
ans = 0
19+
for bit in range(60):
20+
if not (m >> bit) & 1:
21+
continue
22+
ans = (ans + (n >> (bit + 1) << bit) + ((n >> bit) & 1) * ((n & ((1 << bit) - 1)) + 1)) % MOD
23+
print(ans)
24+
25+
26+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import sys
2+
from collections import Counter
3+
# from bisect import bisect_left
4+
5+
# region fastio
6+
input = lambda: sys.stdin.readline().rstrip()
7+
sint = lambda: int(input())
8+
mint = lambda: map(int, input().split())
9+
ints = lambda: list(map(int, input().split()))
10+
# endregion fastio
11+
12+
# MOD = 998_244_353
13+
# MOD = 10 ** 9 + 7
14+
# DIR = ((-1, 0), (0, 1), (1, 0), (0, -1))
15+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
16+
17+
18+
def solve() -> None:
19+
n = sint()
20+
nums = ints()
21+
ans = 0
22+
cnt = Counter(nums)
23+
mx = max(nums)
24+
d = [0] * (mx + 1)
25+
for x in set(nums):
26+
for j in range(x, mx + 1, x):
27+
d[j] += cnt[x]
28+
c = 0
29+
for i, c1 in enumerate(d):
30+
c += c1
31+
if cnt[i]:
32+
ans += c * cnt[i] - cnt[i] * cnt[i] + cnt[i] * (cnt[i] - 1) // 2
33+
34+
print(ans)
35+
36+
37+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
import sys
2+
import math
3+
from collections import Counter
4+
from bisect import bisect_left, bisect_right
5+
from typing import Generic, Iterable, Iterator, List, TypeVar, Union
6+
7+
T = TypeVar('T')
8+
9+
class SortedSet(Generic[T]):
10+
BUCKET_RATIO = 50
11+
REBUILD_RATIO = 170
12+
13+
def _build(self, a=None) -> None:
14+
"Evenly divide `a` into buckets."
15+
if a is None: a = list(self)
16+
size = self.size = len(a)
17+
bucket_size = int(math.ceil(math.sqrt(size / self.BUCKET_RATIO)))
18+
self.a = [a[size * i // bucket_size : size * (i + 1) // bucket_size] for i in range(bucket_size)]
19+
20+
def __init__(self, a: Iterable[T] = []) -> None:
21+
"Make a new SortedSet from iterable. / O(N) if sorted and unique / O(N log N)"
22+
a = list(a)
23+
if not all(a[i] < a[i + 1] for i in range(len(a) - 1)):
24+
a = sorted(set(a))
25+
self._build(a)
26+
27+
def __iter__(self) -> Iterator[T]:
28+
for i in self.a:
29+
for j in i: yield j
30+
31+
def __reversed__(self) -> Iterator[T]:
32+
for i in reversed(self.a):
33+
for j in reversed(i): yield j
34+
35+
def __len__(self) -> int:
36+
return self.size
37+
38+
def __repr__(self) -> str:
39+
return "SortedSet" + str(self.a)
40+
41+
def __str__(self) -> str:
42+
s = str(list(self))
43+
return "{" + s[1 : len(s) - 1] + "}"
44+
45+
def _find_bucket(self, x: T) -> List[T]:
46+
"Find the bucket which should contain x. self must not be empty."
47+
for a in self.a:
48+
if x <= a[-1]: return a
49+
return a
50+
51+
def __contains__(self, x: T) -> bool:
52+
if self.size == 0: return False
53+
a = self._find_bucket(x)
54+
i = bisect_left(a, x)
55+
return i != len(a) and a[i] == x
56+
57+
def add(self, x: T) -> bool:
58+
"Add an element and return True if added. / O(√N)"
59+
if self.size == 0:
60+
self.a = [[x]]
61+
self.size = 1
62+
return True
63+
a = self._find_bucket(x)
64+
i = bisect_left(a, x)
65+
if i != len(a) and a[i] == x: return False
66+
a.insert(i, x)
67+
self.size += 1
68+
if len(a) > len(self.a) * self.REBUILD_RATIO:
69+
self._build()
70+
return True
71+
72+
def discard(self, x: T) -> bool:
73+
"Remove an element and return True if removed. / O(√N)"
74+
if self.size == 0: return False
75+
a = self._find_bucket(x)
76+
i = bisect_left(a, x)
77+
if i == len(a) or a[i] != x: return False
78+
a.pop(i)
79+
self.size -= 1
80+
if len(a) == 0: self._build()
81+
return True
82+
83+
def lt(self, x: T) -> Union[T, None]:
84+
"Find the largest element < x, or None if it doesn't exist."
85+
for a in reversed(self.a):
86+
if a[0] < x:
87+
return a[bisect_left(a, x) - 1]
88+
89+
def le(self, x: T) -> Union[T, None]:
90+
"Find the largest element <= x, or None if it doesn't exist."
91+
for a in reversed(self.a):
92+
if a[0] <= x:
93+
return a[bisect_right(a, x) - 1]
94+
95+
def gt(self, x: T) -> Union[T, None]:
96+
"Find the smallest element > x, or None if it doesn't exist."
97+
for a in self.a:
98+
if a[-1] > x:
99+
return a[bisect_right(a, x)]
100+
101+
def ge(self, x: T) -> Union[T, None]:
102+
"Find the smallest element >= x, or None if it doesn't exist."
103+
for a in self.a:
104+
if a[-1] >= x:
105+
return a[bisect_left(a, x)]
106+
107+
def __getitem__(self, x: int) -> T:
108+
"Return the x-th element, or IndexError if it doesn't exist."
109+
if x < 0: x += self.size
110+
if x < 0: raise IndexError
111+
for a in self.a:
112+
if x < len(a): return a[x]
113+
x -= len(a)
114+
raise IndexError
115+
116+
def index(self, x: T) -> int:
117+
"Count the number of elements < x."
118+
ans = 0
119+
for a in self.a:
120+
if a[-1] >= x:
121+
return ans + bisect_left(a, x)
122+
ans += len(a)
123+
return ans
124+
125+
def index_right(self, x: T) -> int:
126+
"Count the number of elements <= x."
127+
ans = 0
128+
for a in self.a:
129+
if a[-1] > x:
130+
return ans + bisect_right(a, x)
131+
ans += len(a)
132+
return ans
133+
134+
# region fastio
135+
input = lambda: sys.stdin.readline().rstrip()
136+
sint = lambda: int(input())
137+
mint = lambda: map(int, input().split())
138+
ints = lambda: list(map(int, input().split()))
139+
# endregion fastio
140+
141+
# MOD = 998_244_353
142+
# MOD = 10 ** 9 + 7
143+
# DIR = ((-1, 0), (0, 1), (1, 0), (0, -1))
144+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
145+
146+
147+
def solve() -> None:
148+
ss = SortedSet()
149+
q, k = mint()
150+
right = Counter()
151+
left = Counter()
152+
for _ in range(q):
153+
t, x = mint()
154+
if t == 1:
155+
l = ss.lt(x)
156+
r = ss.gt(x)
157+
if x in ss:
158+
ss.discard(x)
159+
if l is not None:
160+
right[l] = 0 if r is None or r > l + k else right[r] + 1
161+
if r is not None:
162+
left[r] = 0 if l is None or l < r - k else left[l] + 1
163+
left[x] = right[x] = 0
164+
else:
165+
ss.add(x)
166+
if l is not None:
167+
right[l] = 0 if x > l + k else 1 if r is None or r > x + k else right[r] + 2
168+
if r is not None:
169+
left[r] = 0 if x < r - k else 1 if l is None or l < x - k else left[l] + 1
170+
left[x] = 0 if l is None or l < x - k else left[l] + 1
171+
right[x] = 0 if r is None or r > x + k else right[r] + 1
172+
else:
173+
print(left[x] + right[x] + 1)
174+
175+
176+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
def solve() -> None:
16+
return
17+
18+
19+
for _ in range(int(input())):
20+
solve()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
3+
# region fastio
4+
input = lambda: sys.stdin.readline().rstrip()
5+
sint = lambda: int(input())
6+
mint = lambda: map(int, input().split())
7+
ints = lambda: list(map(int, input().split()))
8+
# endregion fastio
9+
10+
# MOD = 998_244_353
11+
# MOD = 10 ** 9 + 7
12+
# DIR4 = ((-1, 0), (0, 1), (1, 0), (0, -1)) #URDL
13+
# DIR8 = ((-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1))
14+
15+
def solve() -> None:
16+
return
17+
18+
19+
for _ in range(int(input())):
20+
solve()

0 commit comments

Comments
 (0)