惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Hacker News
The Hacker News
F
Full Disclosure
Cloudbric
Cloudbric
Blog — PlanetScale
Blog — PlanetScale
W
WeLiveSecurity
N
News and Events Feed by Topic
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
B
Blog
GbyAI
GbyAI
C
Check Point Blog
B
Blog RSS Feed
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Recorded Future
Recorded Future
The Last Watchdog
The Last Watchdog
N
News and Events Feed by Topic
T
The Blog of Author Tim Ferriss
O
OpenAI News
V
V2EX
人人都是产品经理
人人都是产品经理
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
IT之家
IT之家
WordPress大学
WordPress大学
www.infosecurity-magazine.com
www.infosecurity-magazine.com
S
Security @ Cisco Blogs
C
Cisco Blogs
Security Latest
Security Latest
S
Security Affairs
V
Visual Studio Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Hacker News - Newest:
Hacker News - Newest: "LLM"
博客园 - 司徒正美
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Microsoft Azure Blog
Microsoft Azure Blog
Last Week in AI
Last Week in AI
AWS News Blog
AWS News Blog
雷峰网
雷峰网
Apple Machine Learning Research
Apple Machine Learning Research
PCI Perspectives
PCI Perspectives
博客园_首页
U
Unit 42
Google DeepMind News
Google DeepMind News
Hugging Face - Blog
Hugging Face - Blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
The Register - Security
The Register - Security
N
Netflix TechBlog - Medium
L
LINUX DO - 热门话题
H
Hacker News: Front Page

某岛

AtCoder Beginner Contest 409 Luogu P5325. 【模板】Min_25 筛 UOJ #188. 【UR #13】Sanrd AtCoder Beginner Contest 371 AtCoder Beginner Contest 369 RPGMaker 2k3 百科 OneShot 的考古 2024“开创拓芯”游戏创享节的相关记录 CJ 回来后的戒断反应 Luogu P10221. [省选联考 2024] 重塑时光 Luogu P5308 [COCI2018-2019#4] Akvizna wqs 二分 歌唱王国 Lean 相关 BZOJ 3153. Sone1 The 2023 ICPC World Finals Luxor 新巴别塔 Sora 的想象与思考 Facebook Hacker Cup 2023 Round 1 AtCoder Beginner Contest 322 LLaMA 2 相关 HuggingFace AI Game Jam ACL 2023 Trans 相关… Luogu P2053. [SCOI2007] 修车 Luogu P1973. [NOI2011] NOI 嘉年华 Luogu P1933. [NOI2010] 旅行路线 Luogu P1954. [NOI2010] 航空管制 Luogu P2048. [NOI2010] 超级钢琴 Luogu P2046. [NOI2010] 海拔 Luogu P3227. [HNOI2013] 切糕 Luogu P8500. [NOI2022] 冒泡排序 Luogu P3629. [APIO2010] 巡逻 USACO 2018 February Contest, Gold Problem 2. Directory Traversal Luogu P3647. [APIO2014] 连珠线 IZhO 2017. Problem F. Hard route SPOJ TWOPATHS. Two Paths 换根 dp 洪恩电脑 —— 开天辟地 Facebook Hacker Cup 2022 Round 2 Codeforces Round #875 Luogu P5828 边双连通图计数 EC Final 拉格朗日反演定理 Luogu P5827. 点双连通图计数 无标号连通图 AtCoder Beginner Contest 284 Luogu P4708. 画画 Luogu P6295. 有标号 DAG 计数 BZOJ #2863. 愤怒的元首 HDU 3303. Harmony Forever 聊聊《明日方舟 Side Story 孤星》与《崩坏:星穹铁道》 SGU 208. Toral Tickets 后日谈,SHLUG 月度分享(上) 钢琴练习 EasyRPG x ChatGPT ControlNet 相关 The 1st Universal Cup, Stage 4, Ukraine EasyRPG —— Sliding Puzzle The 1st Universal Cup, Stage 3, Poland DP 优化练习 NOI 2009 TypeDB Forces 2023 Nas 买来做什么… Global Game Jam 2023 参赛纪录 The 1st Universal Cup, Stage 2, Hongkong The 1st Universal Cup, Stage 0, Nanjing Codeforces Round #850 舟游同人游戏 RM2k3 机能增强 —— EasyRPG Player 魔改版 《海之歌》设定与剧本 dfs 序求 lca Codeforces Round #844 P3768 简单的数学题 AtCoder Beginner Contest 281 ChatGPT 相关 AtCoder Grand Contest 059 AtCoder Beginner Contest 280 Codeforces Global Round 24 事实核查,以乌鲁木齐火灾为例 SPOJ MUSKET. Musketeers Pinely Round 1 Note about FTX Permutation ICPC World Final 2021 CodeTON Round 3 Codeforces Round #831 Educational Codeforces Round 138 NovelAI 法术指南 卡农 Educational Codeforces Round 135 Codeforces Round #819 瓦喵之夏 NOI 2022 Luogu P3765 总统选举 Luogu P3369 【模板】普通平衡树 网络国家 旋转卡壳 OFAC Sanctions && Tornado Cash BZOJ 1185. [HNOI2007]最小矩形覆盖
Facebook Hacker Cup 2021 Round 1
2021-10-21 · via 某岛

A1.
给定一个 ’01-‘ 组成的字符串 s,设 f(s) 为忽略掉 s 中所有 ‘-‘ 字符后,相邻字符发生变换的次数。
求 f(s)。
扫一遍即可。

A2
统计所有 s 的子串的 f 值。
统计相邻的 ’01’ pair 的贡献即可。

const int N = int(1e6) + 9;
char s[N];
int n;

int main() {

#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

    Rush {
        RD(n); RS(s);
        Int z = 0;
        char lc = '?'; // 上一个字符
        int lp = 0; // 上一个字符的位置

        REP(i, n) {
            char c = s[i];
            if(c != 'F') {
                if (lc != c) {
                    if(lc != '?') z += Int(lp) * (n-i);
                    lc = c;
                }
                lp = i+1;
            }
        }
        OT(z);
    }
}

A3
s 中还包含 ‘.’ 字符,如果出现 ‘.’ 字符,则用此前的字符串替换 ‘.’ 位置,询问 A2。

延续 A2 的思路,我们需要对每个 pair 统计出左边和右边分别有多少字符。
这个比较简单,但是每个 ‘.’ 内部还会出现很多 pair,我们需要对这些内部的 pair 也 O(1) 时间统计。
这样首先我们需要改进 A2 的算法,再开一个 ls 变量记录前面所有 pair 的贡献,这样就可以不支持后续长度的情况下 incremental 的维护答案。

const int N = int(1e6) + 9;
char s[N];
int n;

int main() {

#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

    Rush {
        RD(n); RS(s);
        Int z = 0;
        char lc = '?'; // 上一个字符
        int lp = 0; // 上一个字符的位置
        Int ls = 0; // 右边新增加一个字符时答案的增量。

        REP(i, n) {
            z += ls;
            char c = s[i];
            if (c != 'F') {
                if (lc != '?' && lc != c) {
                    z += lp;
                    ls += lp;
                }
                lp = i+1;
                lc = c;
            }
        }
        OT(z);
    }
}

进一步考虑 ‘.’ 的影响,我们不仅需要知道当右边新增加一个字符时的增量 ls,还需要对称的,知道当左边新增加一个字符时的增量 rs,
那么新的答案就是 2z + len(ls+rs),还要考虑合并的位置会不会产生一组新的 pair。
因此还需要维护左右第一个字符是什么和所在位置以及一共有多少 pair。各种维护即可。

const int N = int(1e6) + 9;
char s[N];
int n;

int main() {

#ifndef ONLINE_JUDGE
    freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif

    Rush {
        RD(n); RS(s);
        Int z = 0;
        char lc = '?', rc = '?'; //
        Int lp = 0, rp = 0, ct = 0;
        Int ls = 0, rs = 0;
        Int len = 0;

        REP(i, n) {
            char c = s[i];
            if (c == '.') {

                z = z*2 + len*(ls+rs);
                ls = ls*2 + len*ct;
                rs = rs*2 + len*ct;
                ct *= 2;

                if (lc != rc) {
                    ct += 1; ls += lp; rs += (len-rp+1);
                    z += lp * (len-rp+1);
                }
                if (lc != '?') lp += len;
                len *= 2;

            } else {

                z += ls;
                len += 1;

                if (c != 'F') {

                    if (rc == '?') {
                        rc = c, rp = len;
                    }

                    if (lc != '?' && lc != c) {
                        z += lp;
                        ls += lp;
                        ct += 1;
                    }
                    lp = len;
                    lc = c;
                }

                rs += ct;
            }
        }
        OT(z);
    }
}

C.
感觉是树形 dp 基本功题,最简单的方法应该是 dfs() 两次,
一次得到子树的 dp 状态,一次得到子树外的 dp 状态,但是比赛时思路比较混乱。

赛后读了一下 nhb 的代码,发现忽略了一个重要得条件,就是边权 <= 20。。。
然后就可以直接暴力加维了。。囧。

当然边分治也可以,参考 neal wu 的代码

不知道没有边权的限制还能不能做。

Posted by xiaodao
Category: 日常