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 ...
随机推荐
- SparkSQL程序设计
1.创建Spark Session val spark = SparkSession.builder . master("local") .appName("spark ...
- rz时提示command not found
-bash: rz: command not found rz命令没找到? 执行sz,同样也没找到. 安装lrzsz: # yum -y install lrzsz 现在就可以正常使用rz ...
- click事件多次触发 jQuery
jQuery 中 click事件会累计绑定 例如下列代码: aNode.click(function(){ bNode.click(function(){ console.log('haha'); } ...
- 20145314郑凯杰《信息安全系统设计基础》第9周学习总结 PART B
20145314郑凯杰<信息安全系统设计基础>第9周学习总结 PART B 明确教材学习目标 注意每个系统调用的参数.返回值,会查帮助文档 阅读教材,完成课后练习(书中有参考答案),考核: ...
- SVN 命令符号详解
L abc.c # svn已经在.svn目录锁定了abc.c M bar.c # bar.c的内容已经在本地修改过了 M baz.c # baz.c属性有修改,但没有内容修改 X 3rd_party ...
- MR案例:CombineFileInputFormat
CombineFileInputFormat是一个抽象类.Hadoop提供了两个实现类CombineTextInputFormat和CombineSequenceFileInputFormat. 此案 ...
- Mac下需要安装的一些软件及常用的配置文件
常用软件配置文件 1..gitconfig # This is Git's per-user configuration file. [user] name = 张文 email = zhangwen ...
- mac下ssh到远程服务器时中文乱码
前言:mac本地的语言环境为英文,远程是支持中文的, 问题: 一开始是在iterm2下登录远程服务器更新数据库时发现中文注释不能正常显示,以为是iterms2下设置有问题,使用系统自带的termina ...
- Implement JSON Web Tokens Authentication in ASP.NET Web API and Identity 2.1 Part 3 (by TAISEER)
http://bitoftech.net/2015/02/16/implement-oauth-json-web-tokens-authentication-in-asp-net-web-api-an ...
- Elasticsearch之中文分词器
前提 什么是倒排索引? Elasticsearch之分词器的作用 Elasticsearch之分词器的工作流程 Elasticsearch之停用词 Elasticsearch的中文分词器 1.单字分词 ...