C - Tax Increase
范围足够小,遍历100/0.08内的整数就好
D - String Formation
设置两个数组分别代表前后加入的字符,reverse时交换数组
# -*- coding: utf-8 -*-
# @time : 2023/6/2 13:30
# @file : atcoder.py
# @software : PyCharmimport bisect
import copy
import sys
from itertools import permutations
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(1000)def main():items = sys.version.split()if items[0] == '3.10.6':fp = open("in.txt")else:fp = sys.stdins = fp.readline().strip()n = int(fp.readline())f, e = [], []over = 0for i in range(n):t = fp.readline().strip()if t[0] == '1':f, e = e, fover = over ^ 1else:_, op, c = t.split()if op == '1':f.append(c)else:e.append(c)fl = ''.join(f[::-1])el = ''.join(e)if over:ans = fl + ''.join(s[::-1]) + elelse:ans = fl + s + elprint(ans)if __name__ == "__main__":main()
E - Divisible Substring
10和大部分质数是互质的,因此可以用前缀和的方法
2和5与10不是互质的,但是只要看尾数即可。
# -*- coding: utf-8 -*-
# @time : 2023/6/2 13:30
# @file : atcoder.py
# @software : PyCharmimport bisect
import copy
import sys
from itertools import permutations
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(1000)def main():items = sys.version.split()if items[0] == '3.10.6':fp = open("in.txt")else:fp = sys.stdinn, p = map(int, fp.readline().split())s = fp.readline().strip()if p == 2 or p == 5:ans = 0for i in range(n):if (ord(s[i]) - ord('0')) % p == 0:ans += i + 1print(ans)returnt, m = 0, 1h = defaultdict(int)ans = 0h[t] = 1for i in range(n - 1, -1, -1):j = ord(s[i]) - ord('0')t = (t + j * m) % pif t in h:ans += h[t]m = (m * 10) % ph[t] += 1print(ans)if __name__ == "__main__":main()
F - Removing Robots
设dp[i]为从i到n的方案数
不选时dp[i]+=dp[i+1]
选中时右边覆盖链一直往右覆盖,需要找到覆盖链不能覆盖的第一个数next dp[i]+=dp[next]
可以用单调栈做
每个数进入后,在被覆盖到的时候出栈,因为被覆盖了以后就没有继续存在的意义了。
为了方便在栈里加入一个很大的数代表位置n
# -*- coding: utf-8 -*-
# @time : 2023/6/2 13:30
# @file : atcoder.py
# @software : PyCharmimport bisect
import copy
import sys
from itertools import permutations
from sortedcontainers import SortedList
from collections import defaultdict, Counter, deque
from functools import lru_cache, cmp_to_key
import heapq
import math
sys.setrecursionlimit(1000)def main():items = sys.version.split()if items[0] == '3.10.6':fp = open("in.txt")else:fp = sys.stdinn = int(fp.readline())items = []for i in range(n):a, b = map(int, fp.readline().split())items.append([a, b])items.sort()x, _ = map(list, zip(*items))x.append(1 << 63)dp = [0] * (n + 1)dp[n] = 1mod = 998244353st = [n]pos = [0] * (n + 1)for i in range(n - 1, -1, -1):t = items[i][0] + items[i][1]while len(st) and t > x[st[-1]]:st.pop()pos[i] = st[-1]dp[i] = (dp[i + 1] + dp[st[-1]]) % modst.append(i)print(dp[0])if __name__ == "__main__":main()