Atcoder ABC179

文章讲述了使用Python编程解决一些算法竞赛中的数学问题,如利用欧拉筛法计算大数的因子个数,通过前缀数组加速求解序列相关问题,以及利用线段树进行区间更新和单点查询。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这期的题都可以用py写

C - A x B + C

因为N非常大,暴力是不可取的
遍历C,将N-C分解求每个数的因子个数

可以用欧拉筛的方法,我这里采用了积性函数的性质

# -*- coding: utf-8 -*-
# @time     : 2023/6/2 13:30
# @file     : atcoder.py
# @software : PyCharm

import 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(100010)


def main():
    items = sys.version.split()
    fp = open("in.txt") if items[0] == "3.10.6" else sys.stdin
    n = int(fp.readline())
    f = [0] * (n + 1)
    f[1] = 1
    for i in range(2, n + 1):
        t = i
        for j in range(2, n):
            c = 0
            while t % j == 0:
                c += 1
                t //= j
            if c > 0:
                f[i] = f[t] * (c + 1)
                break
            if j * j > i:
                break
        if i == t:
            f[i] = 2
    ans = sum(f[1: n])
    print(ans)


if __name__ == "__main__":
    main()

D - Leaping Tak

f(n)=f(n−l)+f(n−l+1)+....f(n−r)f(n)=f(n-l)+f(n -l+1)+....f(n-r)f(n)=f(nl)+f(nl+1)+....f(nr)
前缀数组加速

# -*- coding: utf-8 -*-
# @time     : 2023/6/2 13:30
# @file     : atcoder.py
# @software : PyCharm

import 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(100010)


def main():
    items = sys.version.split()
    fp = open("in.txt") if items[0] == "3.10.6" else sys.stdin
    n, m = map(int, fp.readline().split())
    a = []
    for _ in range(m):
        a.append(list(map(int, fp.readline().split())))
    f = [0] * n
    s = [0] * (n + 1)
    f[0] = 1
    s[0] = 0
    s[1] = 1
    mod = 998244353
    for i in range(1, n):
        for l, r in a:
            sl, sr = i - r, i - l
            sl = max(0, sl)
            if sr >= 0:
                f[i] += s[sr + 1] - s[sl]
        f[i] %= mod
        s[i + 1] = (s[i] + f[i]) % mod
    print(f[n - 1])


if __name__ == "__main__":
    main()

E - Sequence Sum

找循环节啦。。四年级数奥题

# -*- coding: utf-8 -*-
# @time     : 2023/6/2 13:30
# @file     : atcoder.py
# @software : PyCharm

import 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(100010)


def main():
    items = sys.version.split()
    fp = open("in.txt") if items[0] == "3.10.6" else sys.stdin
    n, x, m = map(int, fp.readline().split())
    h = {x: 0}
    seq = [x]
    rep = -1
    while True:
        x = x * x % m
        if x in h:
            rep = h[x]
            break
        h[x] = len(seq)
        seq.append(x)
    l = len(seq)
    if n <= l:
        print(sum(seq[:n]))
        return
    loop = l - rep
    ans = sum(seq[:rep])
    t, r = (n - rep) // loop, (n - rep) % loop
    ans += sum(seq[rep:]) * t + sum(seq[rep: rep + r])
    print(ans)


if __name__ == "__main__":
    main()

F - Simplified Reversi

动手画一画就知道,线段树的入门题
区间更新,单点查询最小值

# -*- coding: utf-8 -*-
# @time     : 2023/6/2 13:30
# @file     : atcoder.py
# @software : PyCharm

import 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(100010)

row, col = [], []
mark_r, mark_c = [], []


def push_down(op, idx):
    if op == 1:
        a, mark_a = row, mark_r
    else:
        a, mark_a = col, mark_c
    if mark_a[idx] == 1e9:
        return
    a[idx * 2] = min(a[idx * 2], mark_a[idx])
    a[idx * 2 + 1] = min(a[idx * 2 + 1], mark_a[idx])
    mark_a[idx * 2] = min(mark_a[idx * 2], mark_a[idx])
    mark_a[idx * 2 + 1] = min(mark_a[idx * 2 + 1], mark_a[idx])
    mark_a[idx] = 1e9


def update(op, L, R, l, r, idx, val):
    if op == 1:
        a, mark_a = row, mark_r
    else:
        a, mark_a = col, mark_c
    if L <= l and r <= R:
        a[idx] = min(a[idx], val)
        mark_a[idx] = min(a[idx], val)
        return
    push_down(op, idx)
    m = (l + r) >> 1
    if L <= m:
        update(op, L, R, l, m, idx * 2, val)
    if m < R:
        update(op, L, R, m + 1, r, idx * 2 + 1, val)


def query(op, l, r, x, idx):
    if op == 1:
        a, mark_a = row, mark_r
    else:
        a, mark_a = col, mark_c
    if l == r:
        return a[idx]
    push_down(op, idx)
    m = (l + r) >> 1
    if x <= m:
        return query(op, l, m, x, idx * 2)
    else:
        return query(op, m + 1, r, x, idx * 2 + 1)


def main():
    items = sys.version.split()
    fp = open("in.txt") if items[0] == "3.10.6" else sys.stdin
    n, q = map(int, fp.readline().split())
    global row, col, mark_r, mark_c
    row = [n] * (n << 2)
    col = [n] * (n << 2)
    mark_r = [1e9] * (n << 2)
    mark_c = [1e9] * (n << 2)
    tot_w = (n - 2) * (n - 2)
    for _ in range(q):
        op, b = map(int, fp.readline().split())
        op -= 1
        pos = query(1 - op, 1, n, b, 1)
        tot_w -= pos - 2
        update(op, 1, pos, 1, n, 1, b)
    print(tot_w)


if __name__ == "__main__":
    main()

关于 AtCoder Beginner Contest 387 的信息如下: ### 关于 AtCoder Beginner Contest 387 AtCoder Beginner Contest (ABC) 是一项面向编程爱好者的定期在线竞赛活动。对于 ABC387,该赛事通常会在周末举行,并持续大约100分钟,在此期间参赛者需解决一系列算法挑战问题。 #### 比赛详情 - **举办平台**: AtCoder Online Judge System[^2] - **比赛时间长度**: 大约为1小时40分钟 - **难度级别**: 初学者友好型,适合那些刚开始接触竞争性程序设计的人群参与 - **题目数量**: 一般情况下会提供四到六道不同难度级别的题目供选手解答 #### 题目概览 虽然具体细节可能因官方发布而有所变化,但可以预期的是,这些题目将会覆盖基础的数据结构、字符串处理以及简单图论等方面的知识点。每一道题目的描述都会清晰给出输入输出格式说明及样例测试数据以便理解需求并验证解决方案的有效性。 为了获取最准确的比赛时间和确切的题目列表,请访问 [AtCoder 官方网站](https://atcoder.jp/) 并查看最新的公告板或直接导航至对应编号的具体页面来获得更新的信息。 ```python import requests from bs4 import BeautifulSoup def get_contest_info(contest_id): url = f"https://atcoder.jp/contests/{contest_id}" response = requests.get(url) if response.status_code == 200: soup = BeautifulSoup(response.text, 'html.parser') title_element = soup.find('title') problem_list_elements = soup.select('.panel.panel-default a[href^="/contests/{}/tasks"]'.format(contest_id)) contest_title = title_element.string.strip() if title_element else "Contest Title Not Found" problems = [element['href'].split('/')[-1] for element in problem_list_elements] return { "name": contest_title, "problems": problems } else: raise Exception(f"Failed to fetch data from {url}") abc_387_details = get_contest_info("abc387") print(abc_387_details) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值