CF1800F Dasha and Nightmares
F.Dasha and Nightmares
题意:\(n\) 个字符串 \(s_i\),问有多少对不同的 \((i, j) \ (1 \le i \le j \le n)\),使得 \(s_i\) 和 \(s_j\) 拼接后的字符串满足下列条件:
- 长度为奇数
- 恰好出现 25 个字母
- 每个字母出现次数为奇数
显然,如果满足后两个条件,第一个条件也满足。
由于只与是否出现和出现次数有关,不妨用两个数 \(a_i, b_i\) 代替 \(s_i\)。
\(a\) 表示出现过哪些字符,\(b\) 表示出现过哪些次数为奇的字符。
for(char c : s) {
a[i] |= 1 << c - 'a';
b[i] ^= 1 << c - 'a';
}
如果 \(i, j\) 满足条件,则
a[i] | a[j]恰好 25 位。a[i] | a[j] = b[i] ^ b[j]。
枚举没出现的那一位 k,则
a[i] >> k & 1 = 0a[j] >> k & 1 = 0a[i] | a[j] = b[i] ^ b[j] = ((1 << 26) - 1) ^ (1 << k)
令 val = ((1 << 26) - 1) ^ (1 << k)
一个第 k 位为 0 的 a[i] 对答案的贡献是满足以下条件的 j 的个数
a[j] >> k & 1 = 0b[j] = val ^ b[i]
用哈希表或者桶记录先前 b 出现的次数即可。
rep(k, 0, 25) {
int val = ((1 << 26) - 1) ^ 1 << k;
vector<int> t;
rep(i, 1, n) {
if(a[i] >> k & 1 ^ 1) {
++ cnt[b[i]];
t.pb(b[i]);
}
}
for(int x : t) ans += cnt[val ^ x];
for(int x : t) cnt[x] = 0;
}
我这里由于 i,j 是无序的,所以最终答案除二(自己和自己一定不行)。
CF1800F Dasha and Nightmares的更多相关文章
- Div.2 C. Dasha and Password
C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- CF1100D Dasha and Chess
题目地址:CF1100D Dasha and Chess 这是我的第一道交互题 思路不难,主要讲讲这条语句: fflush(stdout); stdout是标准输出的意思.因为有时候,我们输出到std ...
- Codeforces Round #394 (Div. 2) C. Dasha and Password
C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- Codeforces Round #394 (Div. 2) E. Dasha and Puzzle 构造
E. Dasha and Puzzle 题目连接: http://codeforces.com/contest/761/problem/E Description Dasha decided to h ...
- Codeforces Round #394 (Div. 2) D. Dasha and Very Difficult Problem 贪心
D. Dasha and Very Difficult Problem 题目连接: http://codeforces.com/contest/761/problem/D Description Da ...
- Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力
C. Dasha and Password 题目连接: http://codeforces.com/contest/761/problem/C Description After overcoming ...
- Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力
B. Dasha and friends 题目连接: http://codeforces.com/contest/761/problem/B Description Running with barr ...
- Codeforces Round #394 (Div. 2) A. Dasha and Stairs 水题
A. Dasha and Stairs 题目连接: http://codeforces.com/contest/761/problem/A Description On her way to prog ...
- codeforces 761D - Dasha and Very Difficult Problem
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 761A Dasha and Stairs
A. Dasha and Stairs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- 重返ubuntu世界
一直对"重返"两个字充满了情怀感,因为会想起小时候看的一本龙珠同人的标题,它就唤作<重回龙珠世界>.最近这五年基本都是在MacOS下工作和学习的,也习惯用MacOS.就 ...
- Scratch基础(一):安装和了解软件
Scratch基础(一):安装和了解软件 编写计算机程序代码的能力是当今社会读写能力的重要组成部分.当人们学习使用Scratch进行编码时,他们将学习解决问题,设计项目和交流思想的重要策略. 1.安装 ...
- GitHub WebHook 使用教程
本文收录于 Github.com/niumoo/JavaNotes,Java 系列文档,数据结构与算法! 本文收录于网站:https://www.wdbyte.com/,我的公众号:程序猿阿朗 什么是 ...
- C#调用HTTP POST请求上传图片
public static string UploadImage(string uploadUrl, string imgPath, string fileparameter = "file ...
- CPU上下文切换 CPU的调度策略
CPU上下文切换 就是先把前一个任务的CPU上下文(也就是CPU寄存器和程序计数器)保存起来,然后加载新任务的上下文,到这些寄存器和程序计数器,最后再跳转到程序计数器所指的新位置,运行新任务. 根据任 ...
- Dynamic ReLU:微软推出提点神器,可能是最好的ReLU改进 | ECCV 2020
论文提出了动态ReLU,能够根据输入动态地调整对应的分段激活函数,与ReLU及其变种对比,仅需额外的少量计算即可带来大幅的性能提升,能无缝嵌入到当前的主流模型中 来源:晓飞的算法工程笔记 公众号 ...
- KingbaseES数据库-生产环境慢查询性能优化案例
一.背景 在生产环境中,慢查询不仅影响系统.业务的正常处理.同时严重影响用户的使用感受. 二.表相关信息 2.1 表结构及索引: Table "yktcore.t_dtl_ymt" ...
- wordpress自建博客站,为文章添加显示浏览次数功能
wordpress自建博客站,为文章添加显示浏览次数功能 笔者使用的主题是 GeneratePress 版本:3.1.3 1.后台文章管理列表添加浏览次数列 效果如图: 实现: 编辑funct ...
- FreeSql生产环境自动升级数据库解决方案
项目场景: 使用FreeSql,包含所有的ORM数据库,都会存在这样的问题.在codefirst模式下,根据代码自动更新数据库,都建议不要在生产环境使用.为什么呢? 其实不建议使用,主要是根据代码自动 ...
- #三分,分治,计算几何,prim#JZOJ 3860 地壳运动
题目 \(q\)组询问查询最小生成树,边权为\(u*k1+v*k2\)(\(k1,k2\)每次询问都不同) \(n\leq 35,m\leq 25000,q\leq 200000\) 分析 纯\(\t ...