Fruit Ninja

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2164    Accepted Submission(s): 838

Problem Description
Recently, dobby is addicted in the Fruit Ninja. As you know, dobby is
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 ?
 
Input
The first line contains a positive integer T(T <= 10), indicates
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.
 
Output
For each test case, ouput the number of triples as the sample below, you just need to output the result mod 100000007.
 
Sample Input
2
6
1 3 2 6 5 4
5
3 5 2 4 1
 
Sample Output
Case #1: 10
Case #2: 1
题解:
给你一个1到n的排列,让求满足posx < posy < posz  && x < z < y 的组数有多少。
宇神写的非常好,思路是对于每个数找出后面比a[i]大的数n2;则可以组成的i < j < k && (a[i] < a[j] < a[k] || a[i] < a[k] < a[j])的组合数为C(2,n2);再减去i < j < k && a[i] < a[j] < a[k]就好了,其实就是前面比a[i]小的数乘以后面比a[i]大的数;另外,要用LL
代码:
 #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(树状数组+思维)的更多相关文章

  1. hdu 4000 Fruit Ninja 树状数组

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4000 Recently, dobby is addicted in the Fruit Ninja. ...

  2. HDU 4000 Fruit Ninja 树状数组 + 计数

    给你N的一个排列,求满足:a[i] < a[k] < a[j] 并且i < j < k的三元组有多少个. 一步转化: 求出所有满足 a[i] < a[k] < a[ ...

  3. hdu 4000Fruit Ninja 树状数组

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission( ...

  4. 【树状数组 思维题】luoguP3616 富金森林公园

    树状数组.差分.前缀和.离散化 题目描述 博艾的富金森林公园里有一个长长的富金山脉,山脉是由一块块巨石并列构成的,编号从1到N.每一个巨石有一个海拔高度.而这个山脉又在一个盆地中,盆地里可能会积水,积 ...

  5. noi.ac #44 链表+树状数组+思维

    \(des\) 给出长度为 \(n\) 的序列,全局变量 \(t\),\(m\) 次询问,询问区间 \([l, r]\) 内出现次数为 \(t\) 的数的个数 \(sol\) 弱化问题:求区间 \([ ...

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

  7. [JZOJ 5908] [NOIP2018模拟10.16] 开荒(kaihuang)解题报告 (树状数组+思维)

    题目链接: https://jzoj.net/senior/#contest/show/2529/1 题目: 题目背景:尊者神高达作为一个萌新,在升级路上死亡无数次后被一只大黄叽带回了师门.他加入师门 ...

  8. zoj 2112 单点修改的主席树(树状数组套主席树)

    题目大意: 区间第k大问题+单点修改 基本思路: 这个题有用整体二分,cdq分治,还有主席树+平衡树的,还有就是主席树+树状数组. 我采用的是b站电子科大大佬的主席树写法,尤其喜欢他的离散化方法,所以 ...

  9. HDU 4000 Fruit Ninja (树状数组+反向思维)

    题意:给你一串数且每个数都不同,问你(x,y,z)出现 x<z<y 的总次数 首先我们直接想的话不能使用O(n*log2 n)解决,所以可以正难则反 可以求得x<(y,z)的值,减去 ...

随机推荐

  1. Linux Centos 系统上安装BT客户端 Transmission

    Linux Centos 系统上安装BT客户端 Transmission   Transmission是一种BitTorrent客户端,特点是一个跨平台的后端和其上的简洁的用户界面,以MIT许可证和G ...

  2. 运行于64操作系统上的C#客户端通过WCF访问Oracle数据库不兼容问题

    运行平台: Windows 7  64位操作系统 运行环境: IIS 7 编程语言:C# 数据库: 32位的Oracle 10g 运行原因:64位操作系统C#客户端程序通过WCF访问ORACLE数据库 ...

  3. [转]WIBKIT技术资料

    WebKit结构和流程分析 http://inedx.blog.hexun.com/28830354_d.html webkit架构 http://inedx.blog.hexun.com/28795 ...

  4. Android中使用NDK

    首先用Android Studio下载NDK 这个比较简单,就不多说了 1.写调用jni的Java代码 新建一个JniUtils类 public class JniUtils { static { S ...

  5. week4_motion_of_ball_1(小球运动)——改进

    # Ball motion with an explicit timer import simplegui # Initialize globals width = 600 height = 600 ...

  6. jbpmAPI-1

    1.1. What is jBPM? jBPM是一个灵活的业务流程管理(BPM)套件.它是轻量级的,完全开源Apache许可下(分布式),用Java编写的.它允许您模型.执行和监控业务流程的整个生命周 ...

  7. Python读取Excel数据并根据列名取值

    一直想将自己接触到的东西梳理一遍,可就是迈不出第一步,希望从这篇总结开始不要再做行动的矮人了. 最近测试过程中需要用到python读取excel用例数据,于是去了解和学习了下xlrd库,这里只记录使用 ...

  8. 数组排序-Objectivec

    发表于昨天(23:33)(2013-11-03 23:33) ,已有15次阅读 ,共0个评论 摘要: 总结OC中数组排序3种方法:sortedArrayUsingSelector:;sortedArr ...

  9. Matlab近期用到的函数(持续更新)

    最近任务用到matlab较多,第一版的代码大部分对于矩阵类的计算都是用for循环来完成的,主要是思维还没有适应matlab.看了同事的一份代码后,现在遇到需要循环的地方第一反应就是如何能够用矩阵的直接 ...

  10. Linux下同步工具inotify+rsync使用详解

    1. rsync 1.1 什么是rsync rsync是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.它使用所谓的“Rsync演算法”来使本地和远程两个主机之间的文件达到同步,这 ...