<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Sify — Blog</title><description>个人博客 — 技术笔记、教程与随笔</description><link>https://astro-theme-sify-demo.vercel.app/</link><item><title>Markdown 排版示例</title><link>https://astro-theme-sify-demo.vercel.app/blog/markdown-style-guide/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/markdown-style-guide/</guid><description>本主题支持的全部 Markdown 元素一览：标题、列表、表格、引用、代码与图片的渲染效果。</description><pubDate>Sat, 15 Aug 2026 00:00:00 GMT</pubDate><content:encoded># Markdown 排版示例

这篇文章用于展示本主题对 Markdown 各元素的排版支持，撰写文章时可以对照此页确认渲染效果。

## 标题与段落

一级标题用单个 `#`，依次向下。正文段落默认字号 1rem、行高 1.85，中文阅读体验经过专门调校。

这是一段**加粗**、*斜体*、~~删除线~~ 与 `行内代码` 混合的示例文字。行内代码使用等宽字体并带有主题色背景。

## 列表

无序列表：

- 列表项一
- 列表项二
  - 嵌套项
- 列表项三

有序列表：

1. 第一步：安装依赖
2. 第二步：启动开发服务器
3. 第三步：编写内容

## 引用

&gt; 好的工具让正确的事变得容易，让错误的事变得困难。
&gt; —— 这是多行引用的第二行，用于测试引用块换行效果。

## 代码块

语言标注支持语法高亮（shiki / github-dark）：

```ts
function greet(name: string): string {
  return `Hello, ${name}!`;
}

console.log(greet(&apos;Astro&apos;));
```

```bash
# 安装依赖并启动
bun install
bun run dev
```

## 表格

| 框架 | 类型 | 构建产物 |
| --- | --- | --- |
| Astro | 内容型框架 | 静态 HTML |
| Next.js | React 框架 | SSR / SSG |
| Vite | 构建工具 | 原生 ESM |

## 图片

![封面占位图](/images/cover-astro.svg)

## 分隔线与脚注

长文章可以用分隔线划分章节，Markdown 脚注[^1]同样受支持。

[^1]: 脚注内容会渲染在文末，适合放补充说明或参考来源。

---</content:encoded></item><item><title>Go 语言进阶：并发模式</title><link>https://astro-theme-sify-demo.vercel.app/blog/go-concurrency/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/go-concurrency/</guid><description>学习 goroutine 与 channel 的组合方式，掌握 Worker Pool、扇出扇入等经典并发设计模式。</description><pubDate>Wed, 12 Aug 2026 00:00:00 GMT</pubDate><content:encoded># Go 语言进阶：并发模式

goroutine 轻量、channel 安全，但**组合方式**才是并发编程的难点。本文介绍几个经过实战检验的经典模式。

## Worker Pool

固定数量的 worker 从任务队列中消费，控制并发上限：

```go
func worker(id int, jobs &lt;-chan int, results chan&lt;- int) {
    for j := range jobs {
        results &lt;- j * 2
    }
}

jobs := make(chan int, 100)
results := make(chan int, 100)

for w := 0; w &lt; 3; w++ {
    go worker(w, jobs, results)
}
for j := 0; j &lt; 100; j++ {
    jobs &lt;- j
}
close(jobs)
```

## 扇出 / 扇入

多个 goroutine 并发处理，再用一个 channel 汇总结果：

```go
func fanIn[T any](chans ...&lt;-chan T) &lt;-chan T {
    out := make(chan T)
    var wg sync.WaitGroup
    for _, c := range chans {
        wg.Add(1)
        go func(ch &lt;-chan T) {
            defer wg.Done()
            for v := range ch {
                out &lt;- v
            }
        }(c)
    }
    go func() { wg.Wait(); close(out) }()
    return out
}
```

## select 超时

用 `select` + `time.After` 给操作加上超时保护：

```go
select {
case res := &lt;-respChan:
    return res
case &lt;-time.After(2 * time.Second):
    return nil, errors.New(&quot;timeout&quot;)
}
```

## 小结

&gt; 不要通过共享内存来通信；而要通过通信来共享内存。

把 goroutine 视为廉价的&quot;工人&quot;，用 channel 定义他们之间的**数据流**，并始终记得关闭 channel 与等待 goroutine 收尾。</content:encoded></item><item><title>Astro 内容集合完全指南</title><link>https://astro-theme-sify-demo.vercel.app/blog/astro-content-collections/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/astro-content-collections/</guid><description>从 schema 定义到类型安全查询，系统讲解 Astro Content Collections 的使用方法。</description><pubDate>Mon, 10 Aug 2026 00:00:00 GMT</pubDate><content:encoded># Astro 内容集合完全指南

Astro Content Collections 让 Markdown 内容拥有**类型安全**的管理方式：每个文档的 frontmatter 都会经过 zod schema 校验，并在编辑器与构建期获得完整的类型提示。

## 定义集合 Schema

在 `src/content.config.ts` 中声明集合及其字段：

```ts
import { defineCollection, z } from &apos;astro:content&apos;;

const blog = defineCollection({
  type: &apos;content&apos;,
  schema: z.object({
    title: z.string(),
    description: z.string(),
    pubDate: z.coerce.date(),
    updatedDate: z.coerce.date().optional(),
    tags: z.array(z.string()).default([]),
    cover: z.string().optional(),
    draft: z.boolean().default(false),
  }),
});

export const collections = { blog };
```

&gt; 字段写错、类型不符时，构建会直接报错并指出是哪一篇文章——这正是集合存在的意义。

## 查询内容

```ts
import { getCollection } from &apos;astro:content&apos;;

// 过滤草稿，按日期倒序
const posts = (await getCollection(&apos;blog&apos;, ({ data }) =&gt; !data.draft)).sort(
  (a, b) =&gt; b.data.pubDate.getTime() - a.data.pubDate.getTime(),
);
```

## 渲染文章

详情页通过 `getStaticPaths` 生成路由，用 `render()` 得到内容组件：

```ts
export async function getStaticPaths() {
  return posts.map((post) =&gt; ({
    params: { id: post.slug },
    props: { post },
  }));
}

const { Content } = await render(post);
```

## 小结

内容集合是 Astro 内容型站点的基础设施。配合子目录 slug、分页与草稿机制，可以构建出结构清晰、可维护的博客系统——本主题的博客、系列、标签、归档全部建立在这套机制之上。</content:encoded></item><item><title>TypeScript 高级类型技巧</title><link>https://astro-theme-sify-demo.vercel.app/blog/typescript-advanced/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/typescript-advanced/</guid><description>深入理解泛型、条件类型、模板字面量类型与 infer 推断，写出更安全的类型代码。</description><pubDate>Sat, 08 Aug 2026 00:00:00 GMT</pubDate><content:encoded># TypeScript 高级类型技巧

TypeScript 的类型系统能力远超大多数人的想象。掌握下面几个高级技巧，可以让类型真正成为你的&quot;文档&quot;。

## 条件类型与 infer

条件类型 `T extends U ? X : Y` 允许在类型层面做分支判断，配合 `infer` 可以从类型中&quot;提取&quot;出结构：

```ts
type ElementType&lt;T&gt; = T extends (infer U)[] ? U : never;

type A = ElementType&lt;string[]&gt;; // string
type B = ElementType&lt;number[]&gt;; // number
```

## 模板字面量类型

借助模板字符串，可以构造出受约束的字符串类型：

```ts
type EventName&lt;T extends string&gt; = `on${Capitalize&lt;T&gt;}`;
type ClickEvent = EventName&lt;&apos;click&apos;&gt;; // &quot;onClick&quot;
```

## 映射类型

遍历联合类型的每个成员并转换：

```ts
type ReadonlyRecord&lt;T&gt; = {
  readonly [K in keyof T]: T[K];
};

interface User { name: string; age: number }
type Frozen = ReadonlyRecord&lt;User&gt;;
```

## 实用工具类型

`Partial`、`Pick`、`Omit`、`ReturnType` 等工具类型覆盖了绝大多数日常需求：

```ts
type Result = ReturnType&lt;typeof fetch&gt;; // Promise&lt;Response&gt;
type Name = Pick&lt;User, &apos;name&apos;&gt;;
```

## 小结

高级类型技巧的关键是**让非法状态在编译期就不可表达**。建议从条件类型与 `infer` 开始练习，逐步构建你自己的类型工具库。</content:encoded></item><item><title>环境变量管理最佳实践</title><link>https://astro-theme-sify-demo.vercel.app/blog/env-best-practices/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/env-best-practices/</guid><description>从 .env 文件到密钥管理，如何在项目中安全、高效地管理环境变量。</description><pubDate>Wed, 05 Aug 2026 00:00:00 GMT</pubDate><content:encoded># 环境变量管理最佳实践

环境变量是应用配置的&quot;最后一公里&quot;。管理不当，轻则配置混乱，重则密钥泄露。

## 基本原则

1. **绝不硬编码**：密钥、连接串一律走环境变量
2. **区分环境**：开发、测试、生产使用不同的变量集合
3. **显式声明**：缺失必填变量时启动即失败，而不是运行时才崩溃

## 目录结构

```
project/
├── .env              # 本地开发（提交到 git）
├── .env.example      # 变量清单（必须提交）
├── .env.production   # 生产（绝不提交）
└── .gitignore        # 忽略真实 .env*
```

## 启动时校验

用 zod 在进程启动时校验并归一化配置：

```ts
import { z } from &apos;zod&apos;;

const envSchema = z.object({
  DATABASE_URL: z.string().url(),
  PORT: z.coerce.number().default(3000),
  NODE_ENV: z.enum([&apos;development&apos;, &apos;test&apos;, &apos;production&apos;]),
});

const env = envSchema.parse(process.env);
```

校验失败会立刻抛出清晰的错误，避免带着残缺配置运行。

## 密钥管理

- 本地：`.env` + 密钥管理工具（如 `direnv`）
- CI：平台的 Secrets 面板（GitHub Actions / GitLab CI）
- 生产：Vault / 云厂商 Secret Manager，**不要**把密钥写进镜像

## 小结

环境变量的目标只有一个：**让配置可审查、可追溯、可安全替换**。从 `.env.example` 和启动校验开始，建立一条清晰的配置流水线。</content:encoded></item><item><title>Vite 构建优化实战</title><link>https://astro-theme-sify-demo.vercel.app/blog/vite-build-optimization/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/vite-build-optimization/</guid><description>从分包策略到产物瘦身，总结 Vite 构建优化的几个实用切入点。</description><pubDate>Sat, 18 Jul 2026 00:00:00 GMT</pubDate><content:encoded># Vite 构建优化实战

Vite 开发时很快，但生产构建的**产物质量**同样值得打磨。下面几个优化点按性价比排序。

## 手动分包

第三方依赖打进同一个 chunk 会拖慢首屏，按需拆分：

```ts
// vite.config.ts
export default defineConfig({
  build: {
    rollupOptions: {
      output: {
        manualChunks: {
          react: [&apos;react&apos;, &apos;react-dom&apos;],
          ui: [&apos;antd&apos;],
        },
      },
    },
  },
});
```

## 按需加载

路由级懒加载配合 `React.lazy`，让首屏只加载必要代码：

```tsx
const Dashboard = lazy(() =&gt; import(&apos;./pages/Dashboard&apos;));
```

## 产物分析

用 `rollup-plugin-visualizer` 生成依赖体积报告，找出&quot;隐形胖子&quot;：

```bash
bun add -d rollup-plugin-visualizer
```

```ts
plugins: [visualizer({ open: true })],
```

## 图片与字体

- 图片交给 `vite-plugin-imagemin` 或压缩后再入库
- 字体使用 `font-display: swap`，避免阻塞渲染

## 小结

构建优化的核心是**为浏览器减负**：更小的包、更少的请求、更合理的缓存。先分析、再动手，避免无谓的微优化。</content:encoded></item><item><title>功能验证：Mermaid、KaTeX 与代码复制</title><link>https://astro-theme-sify-demo.vercel.app/blog/feature-verification/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/feature-verification/</guid><description>用于验证本主题集成的 Mermaid 流程图渲染、KaTeX 数学公式渲染与代码块一键复制功能。</description><pubDate>Wed, 15 Jul 2026 00:00:00 GMT</pubDate><content:encoded># 功能验证

本文将构造一个包含 Mermaid 流程图、KaTeX 数学公式与代码块的页面，用于验证三项集成是否生效。

## Mermaid 流程图

```mermaid
flowchart TD
    A[开始] --&gt; B{是否已有账号?}
    B -- 否 --&gt; C[注册账号]
    C --&gt; D[登录]
    B -- 是 --&gt; D
    D --&gt; E[进入工作台]
    E --&gt; F[（结束）]
```

## KaTeX 数学公式

行内公式：欧拉恒等式 $e^{i\pi} + 1 = 0$。

独立公式：

$$
\sum_{n=1}^{\infty} \frac{1}{n^2} = \frac{\pi^2}{6}
$$

## 时序图

```mermaid
sequenceDiagram
    participant 客户端
    participant 服务端
    客户端-&gt;&gt;服务端: POST /api/login
    服务端--&gt;&gt;客户端: 200 + JWT
    客户端-&gt;&gt;服务端: GET /api/me (Bearer)
    服务端--&gt;&gt;客户端: user profile
```

## 矩阵

$$
\begin{pmatrix} a &amp; b \\ c &amp; d \end{pmatrix}
^{-1} = \frac{1}{ad - bc}
\begin{pmatrix} d &amp; -b \\ -c &amp; a \end{pmatrix}
$$

## 代码块

```ts
interface Parser {
  parse(source: string): AST;
}

const p: Parser = {
  parse(src) {
    return { src };
  },
};
```

## Bash

```bash
# 安装依赖
bun install --frozen-lockfile
```

## 总结

- ✅ `mermaid` 前端运行时渲染流程图与时序图为内联 SVG
- ✅ `remark-math` + `rehype-katex` 渲染行内/块级公式
- ✅ 每个代码块右上角带「复制」按钮</content:encoded></item><item><title>CSS 现代化实践</title><link>https://astro-theme-sify-demo.vercel.app/blog/css-modern-practices/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/css-modern-practices/</guid><description>容器查询、:has()、级联层与逻辑属性——这些新特性正在改变我们写 CSS 的方式。</description><pubDate>Sun, 05 Jul 2026 00:00:00 GMT</pubDate><content:encoded># CSS 现代化实践

CSS 在近年迎来了一批真正改变开发体验的特性，本文挑选四个高频场景介绍。

## 容器查询

不再只能&quot;看窗口&quot;，组件可以根据自身容器尺寸响应：

```css
.card {
  container-type: inline-size;
}

@container (min-width: 400px) {
  .card-title {
    font-size: 1.5rem;
  }
}
```

## :has() 选择器

&quot;父选择器&quot;让状态驱动的样式变得简洁：

```css
/* 含图片的卡片增加间距 */
.card:has(img) {
  padding-top: 1rem;
}
```

## 级联层

用 `@layer` 明确管理样式优先级，告别 `!important` 军备竞赛：

```css
@layer base, components, utilities;
```

## 逻辑属性

`margin-inline`、`padding-block` 让样式天然适配书写方向：

```css
/* 物理属性 */ margin-left: 1rem;
/* 逻辑属性 */ margin-inline-start: 1rem;
```

## 小结

新特性不是玩具，而是让 CSS 更**可维护**的工具。建议从逻辑属性和 `:has()` 开始，逐步迁移存量代码。</content:encoded></item><item><title>Docker 容器化入门</title><link>https://astro-theme-sify-demo.vercel.app/blog/docker-getting-started/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/docker-getting-started/</guid><description>从 Dockerfile 到多阶段构建与 Compose，快速上手容器化部署。</description><pubDate>Tue, 30 Jun 2026 00:00:00 GMT</pubDate><content:encoded># Docker 容器化入门

容器让&quot;在我机器上能跑&quot;成为历史。本文用一个 Node 服务带你走完容器化全流程。

## 编写 Dockerfile

```dockerfile
FROM node:22-alpine AS build
WORKDIR /app
COPY package.json bun.lock ./
RUN bun install --frozen-lockfile
COPY . .
RUN bun run build

FROM node:22-alpine
WORKDIR /app
COPY --from=build /app/dist ./dist
ENV NODE_ENV=production
EXPOSE 3000
CMD [&quot;node&quot;, &quot;dist/server.js&quot;]
```

多阶段构建让最终镜像只包含运行所需文件。

## 构建与运行

```bash
docker build -t my-app .
docker run -p 3000:3000 --env-file .env my-app
```

## Compose 编排

本地开发一键拉起多服务：

```yaml
services:
  web:
    build: .
    ports: [&quot;3000:3000&quot;]
    depends_on:
      - db
  db:
    image: postgres:16
    environment:
      POSTGRES_PASSWORD: devpass
```

## 小结

容器化的收益在**一致性**：镜像即部署单元，环境差异被彻底抹平。从多阶段构建开始，逐步引入镜像仓库与 CI 流水线。</content:encoded></item><item><title>Git 协作工作流指南</title><link>https://astro-theme-sify-demo.vercel.app/blog/git-workflow-guide/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/git-workflow-guide/</guid><description>功能分支、提交规范与代码评审——建立可持续的团队协作方式。</description><pubDate>Fri, 12 Jun 2026 00:00:00 GMT</pubDate><content:encoded># Git 协作工作流指南

多人协作的痛点大多不在 Git 命令本身，而在**约定**。一套清晰的规范比任何技巧都重要。

## 功能分支模型

每个需求一条分支，主干保持可发布：

```bash
git checkout -b feat/user-profile
# 开发、提交……
git push origin feat/user-profile
```

## 提交信息规范

采用 Conventional Commits，让历史可读、可自动生成 changelog：

```text
feat: 增加用户资料编辑
fix: 修复移动端菜单无法关闭的问题
docs: 更新 README 部署说明
```

## 合并策略

- 主干合并：**rebase** 保持线性历史
- 功能分支并入：**squash merge** 压缩为一次提交

```bash
git fetch origin
git rebase origin/main
```

## 保护规则

- 主干禁止直接推送
- PR 至少一人评审通过
- CI 全绿才可合并

## 小结

&gt; 好的工作流不是约束，而是让每个成员都清楚&quot;下一步该做什么&quot;。

从提交规范和保护规则入手，小团队也能获得大厂级的协作体验。</content:encoded></item><item><title>数据库索引原理与调优</title><link>https://astro-theme-sify-demo.vercel.app/blog/database-indexing/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/database-indexing/</guid><description>B-Tree 为什么快？覆盖索引是什么？用 EXPLAIN 分析并优化慢查询。</description><pubDate>Wed, 20 May 2026 00:00:00 GMT</pubDate><content:encoded># 数据库索引原理与调优

索引是数据库性能的第一杠杆。理解它的原理，才能做出正确的取舍。

## B-Tree 为什么快

B-Tree 让查找复杂度维持在 **O(log n)**，且节点按页存储、磁盘 IO 次数极少：

```text
        [ 30 | 60 ]
       /     |      \
   [10|20] [40|50] [70|80]
```

每次查询只需访问 3~4 层节点，这就是&quot;千万行也能毫秒返回&quot;的秘密。

## 覆盖索引

当索引包含查询所需的全部列时，可以**免回表**：

```sql
CREATE INDEX idx_user_email ON users(email) INCLUDE (name);

-- 下面的查询只需读索引
SELECT name FROM users WHERE email = &apos;a@b.com&apos;;
```

## 用 EXPLAIN 分析

```sql
EXPLAIN ANALYZE
SELECT * FROM orders
WHERE user_id = 42 AND status = &apos;paid&apos;;
```

关注三个指标：

| 指标 | 含义 |
| --- | --- |
| type | 访问类型，`ref`/`range` 优于 `ALL` |
| rows | 预估扫描行数 |
| Actual Time | 实际执行耗时 |

## 常见误区

- 索引不是越多越好——每个索引都有写入成本
- 前导列才能命中联合索引
- 对低选择性的列建索引往往得不偿失

## 小结

调优的顺序应该是：**先 EXPLAIN，再建索引，最后观察**。索引是银弹的&quot;前提是选对了子弹&quot;。</content:encoded></item><item><title>HTTP 网络基础速览</title><link>https://astro-theme-sify-demo.vercel.app/blog/http-network-basics/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/http-network-basics/</guid><description>请求响应模型、状态码语义、缓存与 HTTP/2/3——一次讲清 Web 传输层。</description><pubDate>Wed, 08 Apr 2026 00:00:00 GMT</pubDate><content:encoded># HTTP 网络基础速览

无论前端还是后端，HTTP 都是必须吃透的基础。本文帮你建立完整的知识框架。

## 请求与响应

一次 HTTP 交互由请求行、首部、消息体组成：

```http
GET /blog/astro-content-collections HTTP/1.1
Host: example.com
Accept: text/html
User-Agent: Mozilla/5.0
```

## 状态码语义

| 范围 | 含义 | 常见示例 |
| --- | --- | --- |
| 2xx | 成功 | 200 OK、204 No Content |
| 3xx | 重定向 | 301、302、304 Not Modified |
| 4xx | 客户端错误 | 400、401、404 |
| 5xx | 服务端错误 | 500、502、503 |

## 缓存策略

缓存是性能的关键，也是事故的高发区：

```http
Cache-Control: public, max-age=3600
ETag: &quot;abc123&quot;
```

- `max-age` 控制新鲜度
- `ETag` / `If-None-Match` 实现条件请求，命中返回 304

## HTTP/2 与 HTTP/3

- **HTTP/2**：多路复用、首部压缩，解决队头阻塞
- **HTTP/3**：基于 QUIC（UDP），弱网环境表现更好

## 小结

把 HTTP 当成**协议的语言**去理解：方法、状态码、首部共同构成服务之间的交流语法。掌握它，调试网络问题会事半功倍。</content:encoded></item><item><title>正则表达式进阶指南</title><link>https://astro-theme-sify-demo.vercel.app/blog/regex-advanced/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/regex-advanced/</guid><description>前瞻断言、命名分组、回溯陷阱与性能优化——从会用走向用好。</description><pubDate>Sun, 15 Mar 2026 00:00:00 GMT</pubDate><content:encoded># 正则表达式进阶指南

正则的入门很容易，精通很难。本文聚焦几个&quot;进阶分水岭&quot;特性。

## 前瞻与后顾

断言不消耗字符，只检查位置：

```js
// 前瞻：后面跟着数字的单词
const re = /\b\w+(?=\d)/;

// 负前瞻：后面不是 @ 的单词
const re2 = /\b\w+(?!@)/;
```

## 命名分组

用名字代替数字下标，可读性提升一个档次：

```js
const re = /(?&lt;year&gt;\d{4})-(?&lt;month&gt;\d{2})-(?&lt;day&gt;\d{2})/;
const m = &apos;2026-08-15&apos;.match(re);
console.log(m.groups.year); // 2026
```

## 回溯陷阱

嵌套量词可能引发灾难性回溯（ReDoS）：

```js
// 危险：/(a+)+$/ 在特定输入下指数级回溯
// 优化：用原子组或改写为 (a+)$
```

&gt; 处理不可信输入时，优先使用非回溯引擎（如 RE2），或对输入长度设限。

## 性能建议

- 能不用正则就不用：字符串方法通常更快
- 避免 `.*` 贪婪匹配跨越大段文本
- 编译一次、复用多次：`const re = new RegExp(...)` 移出循环

## 小结

正则的进阶之路 = **断言 + 分组 + 对引擎特性的敬畏**。用得好是利器，用不好是灾难。</content:encoded></item><item><title>AtCoder ABC424 解题报告</title><link>https://astro-theme-sify-demo.vercel.app/blog/atcoder/abc424/</link><guid isPermaLink="true">https://astro-theme-sify-demo.vercel.app/blog/atcoder/abc424/</guid><description>AtCoder Beginner Contest 424 题解：从签到题到数据结构优化，记录思路与代码。</description><pubDate>Tue, 10 Feb 2026 00:00:00 GMT</pubDate><content:encoded># AtCoder ABC424 解题报告

这篇文章位于 `content/blog/atcoder/` 子目录，用于演示博客详情页对**子目录 slug** 的支持（URL 为 `/blog/atcoder/abc424`）。

## A 题：签到

题意：读入一个整数并原样输出。注意用 `long long` 防止溢出：

```cpp
#include &lt;bits/stdc++.h&gt;
using namespace std;

int main() {
  long long n;
  cin &gt;&gt; n;
  cout &lt;&lt; n &lt;&lt; &apos;\n&apos;;
  return 0;
}
```

## B 题：模拟

直接按题意模拟，复杂度 O(N)：

```cpp
for (int i = 0; i &lt; n; i++) {
  if (check(i)) ans++;
}
```

## C 题：前缀和优化

暴力会超时，用前缀和把区间查询降到 O(1)：

```cpp
vector&lt;long long&gt; pref(n + 1, 0);
for (int i = 0; i &lt; n; i++) pref[i + 1] = pref[i] + a[i];

// 查询 [l, r]
long long sum = pref[r + 1] - pref[l];
```

## 小结

ABC 的难度梯度非常适合练手：A/B 保稳、C/D 练思维、E 之后挑战自我。保持每周一场，进步看得见。</content:encoded></item></channel></rss>