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 = 0
  • a[j] >> k & 1 = 0
  • a[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 = 0
  • b[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的更多相关文章

  1. Div.2 C. Dasha and Password

    C. Dasha and Password time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  2. CF1100D Dasha and Chess

    题目地址:CF1100D Dasha and Chess 这是我的第一道交互题 思路不难,主要讲讲这条语句: fflush(stdout); stdout是标准输出的意思.因为有时候,我们输出到std ...

  3. 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 ...

  4. 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 ...

  5. 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 ...

  6. Codeforces Round #394 (Div. 2) C. Dasha and Password 暴力

    C. Dasha and Password 题目连接: http://codeforces.com/contest/761/problem/C Description After overcoming ...

  7. Codeforces Round #394 (Div. 2) B. Dasha and friends 暴力

    B. Dasha and friends 题目连接: http://codeforces.com/contest/761/problem/B Description Running with barr ...

  8. 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 ...

  9. codeforces 761D - Dasha and Very Difficult Problem

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  10. 761A Dasha and Stairs

    A. Dasha and Stairs time limit per test 2 seconds memory limit per test 256 megabytes input standard ...

随机推荐

  1. Linux电脑如何下载QGIS?

      本文介绍在Linux操作系统Ubuntu版本中,通过命令行的方式,配置QGIS软件的方法.   在Ubuntu等Linux系统中,可以对空间信息加以可视化的遥感.GIS软件很少,比如ArcGIS下 ...

  2. 2022福州大学MEM复试英语口语准备

    一.自我介绍 Dear professors, it's my honor to be here for my interview. My name is ,I finished my undergr ...

  3. #根号分治,背包#51nod 1597 有限背包计数问题 LOJ 6089 小Y的背包计数问题

    题目 有一个大小为\(n\)的背包,有\(n\)种物品, 第\(i\)种物品的大小为\(i\),且有\(i\)个, 求装满这个背包的方案数 \(n\leq 10^5\) 分析 直接多重背包会有问题,考 ...

  4. 【直播回顾】参与ArkUI,共建OpenHarmony繁荣生态

    5月31日晚上19点,战"码"先锋第三期直播 <参与ArkUI,共建OpenHarmony繁荣生态> ,在OpenHarmony社群内成功举行.   本期课程,由华为终 ...

  5. C++ 智能指针和内存管理:使用指南和技巧

    C++是一门强大的编程语言,但是在内存管理方面却存在着一些问题.手动管理内存不仅费时费力,而且容易出错.因此,C++中引入了智能指针这一概念,以更好地管理内存. 什么是智能指针? 在C++中,内存的分 ...

  6. Docker 学习之道: 容器注册表及其最佳实践

    容器注册表是Docker容器镜像的集中存储和分发系统.它允许开发人员以这些镜像的形式轻松共享和部署应用程序.容器注册表在容器化应用程序的部署中发挥着关键作用,因为它们提供了一种快速.可靠和安全的方式, ...

  7. MogDB学习笔记之 -- 了解pagewriter线程

    MogDB 学习笔记之 -- 了解 pagewriter 线程 本文出处:https://www.modb.pro/db/183172 在前面的 MogDB 学习系列中,我们了解了核心的 bgwrit ...

  8. openGauss社区入门(openGauss-定时任务)

    为什么要使用定时任务 在一个固定的时间点活间隔一段时间需要频繁触发某一动作,为了使用便捷,有了定时任务,极大的减少了工作的重复性,提高了效率. 定时任务的内容 基于定时任务产生的背景,定时任务内容包括 ...

  9. 教你构建一个优秀的SD Prompt

    构建一个优秀的Prompt 在使用Stable Diffusion AI时,构建一个有效的提示(Prompt)是至关重要的第一步.这个过程涉及到创造性的尝试和对AI行为的理解.这里我会对如何构建一个好 ...

  10. Centos8安装docker-ce

    一.安装步骤 1.安装yum-utils yum install -y yum-utils 2.配置阿里源 yum-config-manager --add-repo http://mirrors.a ...