题意:

求所有的上升子序列种数;

思路:

我想先离散化一下,然后用树状数组维护一下。

最终答案就是sum(n) ?

卧槽,好像是;然后就过了。。

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL mod=1000000007;
const int N=1e5+10; LL arr[N],n;
LL c[N*4]; void add(LL i,LL v)
{
while(i<=n)
{
c[i]=(c[i]+v)%mod;
i+=i&(-i);
}
} LL Sum(LL i)
{
LL ans=0;
while(i>0)
{
ans=(ans+c[i])%mod;
i-=i&(-i);
}
return ans%mod;
} vector<LL>xs;
int main()
{
int T,cas=1;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n); xs.clear();
for(int i=1;i<=n;i++)
{
scanf("%lld",&arr[i]);
xs.push_back(arr[i]);
}
sort(xs.begin(),xs.end());
vector<LL>::iterator e=unique(xs.begin(),xs.end());
for(int i=1;i<=n;i++)
arr[i]=lower_bound(xs.begin(),e,arr[i])-xs.begin()+1; memset(c,0,sizeof(c));
LL temp;
for(int i=1;i<=n;i++)
{
temp=(Sum(arr[i]-1)+1%mod);
add(arr[i],temp);
}
printf("Case %d: %lld\n",cas++,Sum(n));
}
return 0;
}

lightoj 1085【离散化+树状数组】的更多相关文章

  1. CodeForces 540E - Infinite Inversions(离散化+树状数组)

    花了近5个小时,改的乱七八糟,终于A了. 一个无限数列,1,2,3,4,...,n....,给n个数对<i,j>把数列的i,j两个元素做交换.求交换后数列的逆序对数. 很容易想到离散化+树 ...

  2. Ultra-QuickSort(归并排序+离散化树状数组)

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 50517   Accepted: 18534 ...

  3. HDU 5862 Counting Intersections(离散化+树状数组)

    HDU 5862 Counting Intersections(离散化+树状数组) 题目链接http://acm.split.hdu.edu.cn/showproblem.php?pid=5862 D ...

  4. BZOJ_4627_[BeiJing2016]回转寿司_离散化+树状数组

    BZOJ_4627_[BeiJing2016]回转寿司_离散化+树状数组 Description 酷爱日料的小Z经常光顾学校东门外的回转寿司店.在这里,一盘盘寿司通过传送带依次呈现在小Z眼前.不同的寿 ...

  5. poj-----Ultra-QuickSort(离散化+树状数组)

    Ultra-QuickSort Time Limit: 7000MS   Memory Limit: 65536K Total Submissions: 38258   Accepted: 13784 ...

  6. Code Forces 652D Nested Segments(离散化+树状数组)

     Nested Segments time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...

  7. hdu 3015 Disharmony Trees (离散化+树状数组)

    Disharmony Trees Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. 【bzoj4627】[BeiJing2016]回转寿司 离散化+树状数组

    题目描述 给出一个长度为n的序列,求所有元素的和在[L,R]范围内的连续子序列的个数. 输入 第一行包含三个整数N,L和R,分别表示寿司盘数,满意度的下限和上限. 第二行包含N个整数Ai,表示小Z对寿 ...

  9. HDU 6318.Swaps and Inversions-求逆序对-线段树 or 归并排序 or 离散化+树状数组 (2018 Multi-University Training Contest 2 1010)

    6318.Swaps and Inversions 这个题就是找逆序对,然后逆序对数*min(x,y)就可以了. 官方题解:注意到逆序对=交换相邻需要交换的次数,那么输出 逆序对个数 即可. 求逆序对 ...

  10. 【bzoj5055】膜法师 离散化+树状数组

    题目描述 给定一个序列$a$,求满足$i<j<k$且$a_i<a_j<a_k$的三元组$(i,j,k)$的个数. 输入 第一行1个数 n 第二行n个数 a_i 输出 一个数,表 ...

随机推荐

  1. NoSQL的四大类型

    1 键值数据库 相关产品:Redis.Riak.SimpleDB.Chordless.Scalaris.Memcached 应用:内容缓存 优点:扩展性好.灵活性好.大量写操作时性能高 缺点:无法存储 ...

  2. MongoDB复制集架构搭建

    创建目录 mkdir -p /data/r0 /data/r1 /data/r2 声明实例 ./bin/mongod --port 27017 --dbpath /home/workspace/dat ...

  3. linux socket详解

    1 linux socket编程的固定模式 server端,bind.listen.accept client端,connect client端和server端之间的一次通信: client端,wri ...

  4. Netty 100万级高并发服务器配置

    前言 每一种该语言在某些极限情况下的表现一般都不太一样,那么我常用的Java语言,在达到100万个并发连接情况下,会怎么样呢,有些好奇,更有些期盼. 这次使用经常使用的顺手的netty NIO框架(n ...

  5. The threads in the thread pool will process the requests on the connections concurrently.

    https://docs.oracle.com/javase/tutorial/essential/concurrency/pools.html Most of the executor implem ...

  6. linux 脚本统计代码行数

    由于实际需求,需要统计开源产品的代码行数,so,以下命令统计*.c的行数. .h,.java  .同理 find . -name *.c|xargs wc -l

  7. 区分:WebElement, MobileElement, AndroidElement, and iosElement

    区分:WebElement, MobileElement, AndroidElement, and iosElement 原文地址:https://discuss.appium.io/t/differ ...

  8. 往android的内核添加驱动及 ueventd.rc 修改【转】

    本文转载自:http://blog.csdn.net/lkqboy2599/article/details/8350100 向android的内核添加驱动,其实就是向linux内核添加驱动.主要在两个 ...

  9. hihocoder#1050 : 树中的最长路(树中最长路算法 两次BFS找根节点求最长+BFS标记路径长度+bfs不容易超时,用dfs做TLE了)

    #1050 : 树中的最长路 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 上回说到,小Ho得到了一棵二叉树玩具,这个玩具是由小球和木棍连接起来的,而在拆拼它的过程中, ...

  10. Codeforces Round #394 (Div. 2) C. Dasha and Password —— 枚举

    题目链接:http://codeforces.com/problemset/problem/761/C C. Dasha and Password time limit per test 2 seco ...