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

Problem Description
Give you an array A[1..n],you need to calculate how many tuples (i,j,k) satisfy that (i<j<k) and ((A[i] xor A[j])<(A[j] xor A[k]))

There are T test cases.

1≤T≤20

1≤∑n≤5∗105

0≤A[i]<230

 
Input
There is only one integer T on first line.

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]

 
Output
For each test case , output an integer , which means the answer.
 
Sample Input
1
5
1 2 3 4 5
 
Sample Output
6
Source
Recommend
liuyiding   |   We have carefully selected several similar problems for you:  6119 6118 6117 6116 6115 
 

题解: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(字典树)的更多相关文章

  1. HDU 6059 - Kanade's trio | 2017 Multi-University Training Contest 3

    思路来自题解(看着题解和标程瞎吉尔比划了半天) /* HDU 6059 - Kanade's trio [ 字典树 ]  |  2017 Multi-University Training Conte ...

  2. hdu6059 Kanade's trio 字典树+容斥

    转自:http://blog.csdn.net/dormousenone/article/details/76570172 /** 题目:hdu6059 Kanade's trio 链接:http:/ ...

  3. hdu 6059 Kanade's trio

    题 OwO http://acm.hdu.edu.cn/showproblem.php?pid=6059 解 由于每个数字最多是30位,枚举数字每一位考虑, 建一棵记录前缀(位的前缀,比如10拆成10 ...

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

  5. HDU 4287 Intelligent IME(字典树数组版)

    Intelligent IME Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  6. HDU 4757 Tree 可持久化字典树

    Tree Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4757 Des ...

  7. hdu 4099 Revenge of Fibonacci 字典树+大数

    将斐波那契的前100000个,每个的前40位都插入到字典树里(其他位数删掉),然后直接查询字典树就行. 此题坑点在于 1.字典树的深度不能太大,事实上,超过40在hdu就会MLE…… 2.若大数加法时 ...

  8. HDU 1247 - Hat’s Words - [字典树水题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247 Problem DescriptionA hat’s word is a word in the ...

  9. HDU 1251 统计难题(字典树模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=1251 题意:给出一些单词,然后有多次询问,每次输出以该单词为前缀的单词的数量. 思路: 字典树入门题. #inc ...

随机推荐

  1. 【web Api性能提升技巧】(2)从DataReader手工创建Json字符串

    这个思路是从 一篇文章,关于<提升web api的性能>上看到的.自己实践了一番,写下步骤. 传统的DataReader是遵循这样的一个步骤: While(reader.Read()) { ...

  2. 利用python获取nginx服务的ip以及流量统计信息

    #!/usr/bin/python #coding=utf8 log_file = "/usr/local/nginx/logs/access.log" with open(log ...

  3. Codeforces679E. Bear and Bad Powers of 42

    传送门 今天子帧的一套模拟题的T3. 考试的时候其实已经想到了正解了,但是一些地方没有想清楚,就没敢写,只打了个暴力. 首先考虑用线段树维护区间信息. 先把每个值拆成两个信息,一是距离他最近的且大于他 ...

  4. ERROR 1093 (HY000): You can't specify target table 'test' for update in FROM clause

    MySQL执行更新语句报错: 更新语句:UPDATE test SET state=50 WHERE num IN(SELECT num FROM test WHERE state=60): 报错:E ...

  5. spring定时器(注解的形式)

    最近有个需求,要在凌晨的时候,根据某几张表生成一张定时任务表里的数据,数据的状态为0(未整改),然后在当天晚上,再把这些数据的状态没改变的,改变状态为1(待整改),然后要用到定时器,百度了一下用注解形 ...

  6. TCP协议三次握手过程分析(改)

    TCP(Transmission Control Protocol) 传输控制协议 TCP是主机对主机层的传输控制协议,提供可靠的连接服务,采用三次握手确认建立一个连接: 位码即tcp标志位,有6种标 ...

  7. RabbitMQ 安装使用教程

    环境 CentOS7 + Python3.5 yum -y install epel-release erlang socat cd /usr/local/src wget http://www.ra ...

  8. [BZOJ4010]菜肴制作

    Description 知名美食家小 A被邀请至ATM 大酒店,为其品评菜肴. ATM 酒店为小 A 准备了 N 道菜肴,酒店按照为菜肴预估的质量从高到低给予 1到N的顺序编号,预估质量最高的菜肴编号 ...

  9. Css初步认识

    css 美化页面 cascading style sheet 层叠样式表 css语法:  选择器{ css属性名:属性值;css属性名:属性值;} css引入方式:  方式一:内联样式表   通过标签 ...

  10. JDK 中的监控与故障处理工具-04 (jmap)

    jmap : memory map for java jmap 命令用于生成堆转储快照文件, 一般称为heapdump 或者 dump 文件.如果不是用 jmap 命令, 要获得 java 堆转储快照 ...