题意:

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

思路:

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

最终答案就是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. TCP 同步传输:客户端发送,服务器段接收

    1.服务器端程序 可以在TcpClient上调用GetStream()方法来获的链接到远程计算机的网络流NetworkStream.当在客户端调用时,他获的链接服务器端的流:当在服务器端调用时,他获得 ...

  2. oracle 的sys 和 system 账号

    sys 和 system 账号有啥区别?一直以来懵懵懂懂,只想当然的认为就是权限大小不一样. 但是,它们都是管理员? 现在,我知道有一个区别了: [sys]只能用sysdba身份登录(也许还有syso ...

  3. 2018.11.22-day24 面向对象-继承

    1.归一化设计 2.抽象类 3.钻石继承 4.C3算法 5.新式类中的super

  4. wprintf、wcout无法输出中文的解决方案

    在C语言中,若wprintf无法输出中文,调用函数setlocale(int category, const char *locale)设置locale即可输出中文 此方法也可用于C++中 例: #i ...

  5. 深入浅出谈DM

  6. Python 的枚举类型

    起步 Python 中的枚举类型 Python 的原生类型中并不包含枚举类型.为了提供更好的解决方案,Python 通过 PEP 435 在 3.4 版本中添加了 enum 标准库. 枚举类型可以看作 ...

  7. codeforces 的 Codeforces Round #273 (Div. 2) --C Table Decorations

    C. Table Decorations time limit per test 1 second memory limit per test 256 megabytes input standard ...

  8. codeforces 669B B. Little Artem and Grasshopper(水题)

    题目链接: B. Little Artem and Grasshopper time limit per test 2 seconds memory limit per test 256 megaby ...

  9. 【C/C++】任意大于1的整数分解成素数因子乘积的形式

    // #include<stdio.h> #include<math.h> #include<malloc.h> int isprime(long n); void ...

  10. 动态调试Android程序

    最近好几天来一直在看动态调试.首先是这一篇(http://www.52pojie.cn/forum.php?mod=viewthread&tid=293648)里面介绍了多种IDA动态调试的情 ...