hdu6059[字典树+思维] 2017多校3
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int trie[ * ][];
int no[ * ];
int sz[ * ];
int sum[][];
int T, n, temp, tot = ;
LL ans = ;
void solve(int x) {
int now = ;
for (int i = ; ~i; i--) {
int bit = (x & ( << i)) ? : ;
sum[i][bit]++;
if (!trie[now][bit]) {
trie[now][bit] = ++tot;
}
if (trie[now][ ^ bit]) { //存在兄弟节点,即有符合的(Ai,Aj)
int bro = trie[now][ ^ bit];
ans += 1LL * sz[bro] * (sz[bro] - ) / ;
ans += 1LL * (sum[i][ ^ bit] - sz[bro]) * sz[bro] - no[bro];
}
now = trie[now][bit];
sz[now]++;
no[now] += sum[i][bit] - sz[now];//除去不符合j>i的(Ai,Aj),要累加
//cout << now << ' ' << no[now] << endl;
}
}
void init() {
memset(trie, , sizeof(trie));
memset(no, , sizeof(no));
memset(sum, , sizeof(sum));
memset(sz, , sizeof(sz));
ans = , tot = ;
}
int main() {
scanf("%d", &T);
while (T--) {
init();
scanf("%d", &n);
for (int i = ; i < n; i++) {
scanf("%d", &temp);
solve(temp);
}
printf("%lld\n", ans);
}
}
hdu6059[字典树+思维] 2017多校3的更多相关文章
- hdu6035[dfs+思维] 2017多校1
/*hdu6035[dfs+思维] 2017多校1*/ //合并色块, 妙啊妙啊 #include<bits/stdc++.h> using namespace std; ; const ...
- hdu6074[并查集+LCA+思维] 2017多校4
看了标答感觉思路清晰了许多,用并查集来维护全联通块的点数和边权和. 用另一个up[]数组(也是并查集)来保证每条边不会被重复附权值,这样我们只要将询问按权值从小到大排序,一定能的到最小的边权和与联通块 ...
- Choosing The Commander CodeForces - 817E (01字典树+思维)
As you might remember from the previous round, Vova is currently playing a strategic game known as R ...
- codeforces 842 D. Vitya and Strange Lesson(01字典树+思维+贪心)
题目链接:http://codeforces.com/contest/842/problem/D 题解:像这种求一段异或什么的都可以考虑用字典树而且mex显然可以利用贪心+01字典树,和线段树差不多就 ...
- HDU6038-Function-数学+思维-2017多校Team01
学长讲座讲过的,代码也讲过了,然而,当时上课没来听,听代码的时候也一脸o((⊙﹏⊙))o 我的妈呀,语文不好是硬伤,看题意看了好久好久好久(死一死)... 数学+思维题,代码懂了,也能写出来,但是还是 ...
- hdu6059 Kanade's trio 字典树+容斥
转自:http://blog.csdn.net/dormousenone/article/details/76570172 /** 题目:hdu6059 Kanade's trio 链接:http:/ ...
- Trie树/字典树题目(2017今日头条笔试题:异或)
/* 本程序说明: [编程题] 异或 时间限制:1秒 空间限制:32768K 给定整数m以及n个数字A1,A2,..An,将数列A中所有元素两两异或,共能得到n(n-1)/2个结果,请求出这些结果中大 ...
- HDU 6059 17多校3 Kanade's trio(字典树)
Problem Description Give you an array A[1..n],you need to calculate how many tuples (i,j,k) satisfy ...
- 2017ACM暑期多校联合训练 - Team 6 1001 HDU 6096 String (字符串处理 字典树)
题目链接 Problem Description Bob has a dictionary with N words in it. Now there is a list of words in wh ...
随机推荐
- 洛谷 P2126 Mzc家中的男家丁
题目背景 mzc与djn的…还没有众人皆知,所以我们要来宣传一下. 题目描述 mzc家很有钱(开玩笑),他家有n个男家丁,现在mzc要将她们全都聚集起来(干什么就不知道了).现在知道mzc与男家丁们互 ...
- dubbo 分布式治理
1. dubbo 仅支持java语言之间的通讯. 2. dubbo 产生的背景是因为分布式的情况下产生的. 3. 解决服务治理的问题,通过注册中心进行管理 4.SOA 治理方案 tcp 协议传输,只需 ...
- CSS3与弹性盒布局
1.弹性盒布局对齐模式 1.1.弹性盒子 在规定弹性盒子之中的子级元素换行显示之前父级元素必须是弹性盒子模型,也就是设置 display 为 flex 代码如下: <!DOCTYPE html& ...
- CPP-基础:字节对齐
一. 什么是字节对齐,为什么要对齐? 现代计算机中内存空间都是按照byte划分的,从理论上讲似乎对任何类型的变量的访问可以从任何地址开始,但实际情况是在访问特定类型变量的时候经常在特定的 ...
- Codeforces Round #273 (Div. 2)-C. Table Decorations
http://codeforces.com/contest/478/problem/C C. Table Decorations time limit per test 1 second memory ...
- python之道04
1.写代码,有如下列表,按照要求实现每一个功能 li = ["alex", "WuSir", "ritian", "barry&q ...
- 2019的hdu暑假作业(欢迎纠错)
1219 遍历计数. #include<bits/stdc++.h> #define QAQ 0 using namespace std; ]; ]; int main(){ )){ me ...
- Jarvis OJ-Level3-x64
linux64位ROP技术 #!/usr/bin/env python from pwn import * elf = ELF('level3_x64') Io = remote('pwn2.jarv ...
- javase(14)_java基础增强
一.Eclipse的使用 1.在eclipse下Java程序的编写和run as,debug as,及java运行环境的配置. 2.快捷键的配置,常用快捷键: •内容提示:Alt + / •快速修复: ...
- shell脚本调试打印日志问题
shell脚本调试打印日志问题 1. 需求 我们在编写脚本的时候,有时候需要做调试,便于我们定位问题,有时候等脚本上线之后,我们需要保留脚本执行过程中的记录.便于我们在出问题的时候,定位问题. 2. ...