Fruit Ninja(树状数组+思维)
Fruit Ninja
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2164 Accepted Submission(s): 838
a free elf, so unlike other elves, he could do whatever he wants.But
the hands of the elves are somehow strange, so when he cuts the fruit,
he can only make specific move of his hands. Moreover, he can only start
his hand in point A, and then move to point B,then move to point C,and
he must make sure that point A is the lowest, point B is the highest,
and point C is in the middle. Another elf, Kreacher, is not interested
in cutting fruits, but he is very interested in numbers.Now, he wonders,
give you a permutation of 1 to N, how many triples that makes such a
relationship can you find ? That is , how many (x,y,z) can you find such
that x < z < y ?
the number of test cases.For each test case, the first line of input is a
positive integer N(N <= 100,000), and the second line is a
permutation of 1 to N.
6
1 3 2 6 5 4
5
3 5 2 4 1
Case #2: 1
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define mem(x,y) memset(x,y,sizeof(x))
typedef long long LL;
const int MAXN=1e5+;
const int MOD=;
LL tree[MAXN+];
int lowbit(int x){return x&(-x);}
void update(int x,int y){
while(x<=MAXN){
tree[x]++;
x+=lowbit(x);
}
}
LL sum(int x){
LL sum=;
while(x>){
sum+=tree[x];
x-=lowbit(x);
}
return sum;
}
int main(){
int T,N,temp,flot=;
scanf("%d",&T);
while(T--){
scanf("%d",&N);
mem(tree,);
LL n1,n2;
LL ans=;
for(int i=;i<=N;i++){
scanf("%d",&temp);
update(temp,);
n1=sum(temp-);//比temp小的;
n2=N-temp-(i-n1-);
// printf("%d %d\n",n1,n2);
ans+=n2*(n2-)/;
ans-=n1*n2;
}
printf("Case #%d: %lld\n",++flot,ans%MOD);
}
return ;
}
Fruit Ninja(树状数组+思维)的更多相关文章
- hdu 4000 Fruit Ninja 树状数组
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4000 Recently, dobby is addicted in the Fruit Ninja. ...
- HDU 4000 Fruit Ninja 树状数组 + 计数
给你N的一个排列,求满足:a[i] < a[k] < a[j] 并且i < j < k的三元组有多少个. 一步转化: 求出所有满足 a[i] < a[k] < a[ ...
- hdu 4000Fruit Ninja 树状数组
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...
- 【树状数组 思维题】luoguP3616 富金森林公园
树状数组.差分.前缀和.离散化 题目描述 博艾的富金森林公园里有一个长长的富金山脉,山脉是由一块块巨石并列构成的,编号从1到N.每一个巨石有一个海拔高度.而这个山脉又在一个盆地中,盆地里可能会积水,积 ...
- noi.ac #44 链表+树状数组+思维
\(des\) 给出长度为 \(n\) 的序列,全局变量 \(t\),\(m\) 次询问,询问区间 \([l, r]\) 内出现次数为 \(t\) 的数的个数 \(sol\) 弱化问题:求区间 \([ ...
- The Preliminary Contest for ICPC Asia Nanjing 2019 A The beautiful values of the palace(树状数组+思维)
Here is a square matrix of n * nn∗n, each lattice has its value (nn must be odd), and the center val ...
- [JZOJ 5908] [NOIP2018模拟10.16] 开荒(kaihuang)解题报告 (树状数组+思维)
题目链接: https://jzoj.net/senior/#contest/show/2529/1 题目: 题目背景:尊者神高达作为一个萌新,在升级路上死亡无数次后被一只大黄叽带回了师门.他加入师门 ...
- zoj 2112 单点修改的主席树(树状数组套主席树)
题目大意: 区间第k大问题+单点修改 基本思路: 这个题有用整体二分,cdq分治,还有主席树+平衡树的,还有就是主席树+树状数组. 我采用的是b站电子科大大佬的主席树写法,尤其喜欢他的离散化方法,所以 ...
- HDU 4000 Fruit Ninja (树状数组+反向思维)
题意:给你一串数且每个数都不同,问你(x,y,z)出现 x<z<y 的总次数 首先我们直接想的话不能使用O(n*log2 n)解决,所以可以正难则反 可以求得x<(y,z)的值,减去 ...
随机推荐
- 《Java4Android视频教程》学习笔记(一)
此为个人的学习笔记,所以不具备太强的学习性,若有错误请谅解,如果能指出我的错误,我将万分感谢~ 一:java历史 java诞生 前身:Oak->java 曾经的名字C++(++--) 原意是在C ...
- A/B(扩展欧几里德)
A/B Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...
- mahout贝叶斯算法开发思路(拓展篇)2
如果想直接下面算法调用包,可以直接在mahout贝叶斯算法拓展下载,该算法调用的方式如下: $HADOOP_HOME/bin hadoop jar mahout.jar mahout.fansy.ba ...
- IE浏览器下<A>标签不能显示背景图片
修改前 background: url('./img/active/legendBg.png')no-repeat 修改后 background: url('./img/active/legendBg ...
- 使用uWSGI+nginx部署Django项目
最近使用django写了一些项目,不过部署到服务器上碰到一些问题,还有静态文件什么的一堆问题,这里总结一下碰到的问题和解决方案,总体思路是按照官方文档走的. 原文地址:http://uwsgi-doc ...
- Android操作HTTP实现和服务器通信
众所周知,Android与服务器通信通常采用HTTP通信方式和Socket通信方式,而HTTP通信方式又分get和post两种方式.至于Socket通信会在以后的博文中介绍. HTTP协议简介: HT ...
- XML 学习之保存节点
XmlDocumnet WriteTo 方法 说明: 保存xmldocument对象节点到xmlwriter(即xml文件写入流) 实例: public static void WriteXml( X ...
- 什么是AOI自动光学检测机测试技术
前言 当印刷电路板的价格以每年六到八个百分点的速度持续滑落,产品的生产良率就成为维持产业竞争力的要素.要获得高的良品率需要有良好的制造控制能力,而要获得良好的制程控制,似乎就必须要在各个制程中执行良好 ...
- js 选择器
a>b 获取a下面的直接子元素
- ThinkPHP 3.1.2 模板的使用技巧
本节课大纲: 一.模板包含 <include file="完整模板文件名" /> <include file="./Tpl/default/Public ...