hdu 6059 Kanade's trio(字典树)
Kanade's trio
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 960 Accepted Submission(s): 361
There are T test cases.
1≤T≤20
1≤∑n≤5∗105
0≤A[i]<230
For each test case , the first line consists of one integer n ,and the second line consists of n integers which means the array A[1..n]
题解:http://blog.csdn.net/dormousenone/article/details/76570172
这题:一直wa,把 tree[] 数组中的int改 long long 就错了,诶找了半天错误
#include <iostream>
#include<cstring>
#include<cstdio>
using namespace std; struct node
{
int cnt,ext;
int nxt[];
}tree[*];
int a[+],num[],cnt[][];
long long ans,ext;
int T,n,tsize; void cal(int k,long long c)
{
ans+=(tree[k].cnt-)*tree[k].cnt/;
ext+=tree[k].cnt*(c-tree[k].cnt)-tree[k].ext;
} void solve()
{
int tmp=;
for(int i=;i<=;i++)
{
if (!tree[tmp].nxt[num[i]])
tree[tmp].nxt[num[i]]=++tsize;
if (tree[tmp].nxt[-num[i]])
cal(tree[tmp].nxt[-num[i]],cnt[i][-num[i]]);
tmp=tree[tmp].nxt[num[i]];
tree[tmp].cnt++;
tree[tmp].ext+=cnt[i][num[i]]-tree[tmp].cnt;
}
return;
} int main()
{
scanf("%d",&T);
for(;T>;T--)
{
scanf("%d",&n);
memset(cnt,,sizeof(cnt));
memset(tree,,tsize*+);
tsize=;
ans=ext=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
int tmp=a[i];
for(int j=;j>=;j--)
{
cnt[j][tmp%]++;
num[j]=tmp%;
tmp/=;
}
solve();
}
printf("%lld\n",ans+ext);
}
return ;
}
hdu 6059 Kanade's trio(字典树)的更多相关文章
- HDU 6059 - Kanade's trio | 2017 Multi-University Training Contest 3
思路来自题解(看着题解和标程瞎吉尔比划了半天) /* HDU 6059 - Kanade's trio [ 字典树 ] | 2017 Multi-University Training Conte ...
- hdu6059 Kanade's trio 字典树+容斥
转自:http://blog.csdn.net/dormousenone/article/details/76570172 /** 题目:hdu6059 Kanade's trio 链接:http:/ ...
- hdu 6059 Kanade's trio
题 OwO http://acm.hdu.edu.cn/showproblem.php?pid=6059 解 由于每个数字最多是30位,枚举数字每一位考虑, 建一棵记录前缀(位的前缀,比如10拆成10 ...
- hdu 6059---Kanade's trio(字典树)
题目链接 Problem Description Give you an array A[1..n],you need to calculate how many tuples (i,j,k) sat ...
- HDU 4287 Intelligent IME(字典树数组版)
Intelligent IME Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 4757 Tree 可持久化字典树
Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4757 Des ...
- hdu 4099 Revenge of Fibonacci 字典树+大数
将斐波那契的前100000个,每个的前40位都插入到字典树里(其他位数删掉),然后直接查询字典树就行. 此题坑点在于 1.字典树的深度不能太大,事实上,超过40在hdu就会MLE…… 2.若大数加法时 ...
- HDU 1247 - Hat’s Words - [字典树水题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247 Problem DescriptionA hat’s word is a word in the ...
- HDU 1251 统计难题(字典树模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...
随机推荐
- 【转】深入浅出UML类图
转自:http://www.cppblog.com/API/archive/2013/07/04/201506.html 在UML 2.0的13种图形中,类图是使用频率最高的UML图之一.Martin ...
- Ubuntu16.04系统中Nmon的安装
Nmon的安装,亲民的安装方法: apt install nmon 不再需要源码编译安装和下载文件到指定目录,解压再运行了.
- java单例模式之懒汉式分析
转自:http://blog.csdn.net/withiter/article/details/8140338 今天中午闲着没事,就随便写点关于Java单例模式的.其实单例模式实现有很多方法,这里我 ...
- [Linux 006]——grep和正则表达式
在使用系统时,我们或多或少的有一些搜索.查找的需求,必须要在文本中搜索某个关键字,或者过滤出文本中某些特定的行.grep 命令就为我们提供了这样一个功能,同时,grep 还可以使用正则表达式进行匹配, ...
- 20135302魏静静——linux课程第七周实验及总结
linux课程第七周实验及总结 实验及学习总结 1. 编译链接的过程和ELF可执行文件格式(以hello为例) GNU编译系统编译源码: 首先,运行C预处理器(cpp),将.c文件翻译成.i文件——g ...
- LeetCode (262):Nim Game
You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...
- 机器学习:让我们彻底搞懂CNN【转】
本文转载自:http://115.com/182920/T1266078.html 机器学习:让我们彻底搞懂CNN 上世纪科学家们发现了几个视觉神经特点,视神经具有局部感受眼,一整张图的识别由多个局部 ...
- 混合开发的大趋势之一React Native之简单的登录界面
转载请注明出处:王亟亟的大牛之路 这些天都在学习RN这部分吧,然后写了个简单的登陆业务,从"实战"中讲解吧 还是继续安利:https://github.com/ddwhan0123 ...
- Linux 修改SSH端口及禁用ROOT远程SSH登陆
打开配置文件: vim /etc/ssh/sshd_config 修改Port及PermitRootLogin节点 : //默认为yes 允许 no表示禁止 PermitRootLogin no // ...
- 04_MySQL常见函数_单行函数
#单行函数细分1.字符函数2.数学函数3.日期函数4.其他函数5.流程控制函数 #单行函数 - 字符函数#一.字符函数#1. length 获取参数的字节长度SELECT LENGTH('john') ...