//Accepted    7552 KB    844 ms
 //dp[i]=sum(dp[j])+1 j<i && a[j]<a[i]
 //可以用线段树求所用小于a[i]的dp[j]的和
 //需要离散化
 #include <cstdio>
 #include <cstring>
 #include <iostream>
 #include <queue>
 #include <cmath>
 #include <algorithm>
 using namespace std;
 /**
   * This is a documentation comment block
   * 如果有一天你坚持不下去了,就想想你为什么走到这儿!
   * @authr songt
   */
 ;
 ;
 struct node
 {
     int l,r;
     long long sum;
 }f[imax_n*];
 void build(int t,int l,int r)
 {
     f[t].l=l;
     f[t].r=r;
     f[t].sum=;
     if (l==r)
     {
         return ;
     }
     ;
     build(*t,l,mid);
     build(*t+,mid+,r);
 }
 long long query(int t,int l,int r)
 {
     if (f[t].l==l && f[t].r==r)
     {
         return f[t].sum%pp;
     }
     ;
     *t,l,r)%pp;
     else
     {
         *t+,l,r)%pp;
         *t,l,mid)+query(*t+,mid+,r))%pp;
     }
 }
 void update(int t,int l,int r,int c)
 {
     if (f[t].l==l && f[t].r==r)
     {
         f[t].sum=(f[t].sum+(r-l+)*c%pp)%pp;
         return ;
     }
     f[t].sum=(f[t].sum+(r-l+)*c%pp)%pp;
     ;
     *t,l,r,c);
     else
     {
         *t+,l,r,c);
         else
         {
             update(*t,l,mid,c);
             update(*t+,mid+,r,c);
         }
     }
     //f[t].sum=(f[2*t].sum+f[2*t+1].sum)%pp;
 }
 int n;
 struct anode
 {
     int a,b;
     int tid;
 }a[imax_n];
 int cmp(anode x,anode y)
 {
     return x.a<y.a;
 }
 int cmp2(anode x,anode y)
 {
     return x.tid<y.tid;
 }
 void pre()
 {
     sort(a+,a+n+,cmp);
     ;
     a[].b=;
     ;
     while (i<=n)
     {
         ].a)
         {
             a[i].b=k;
         }
         else
         {
             a[i].b=k+;
             k++;
         }
         i++;
     }
     sort(a+,a+n+,cmp2);
    // for (int i=1;i<=n;i++)
    // {
    //     printf("%d ",a[i].b);
    // }
     //printf("\n");
 }
 void slove()
 {
     ;
     build(,,n+);
     pre();
     ;i<=n;i++)
     {
         ,,a[i].b-)%pp;
         t++;
         ans=(ans+t)%pp;
         update(,a[i].b,a[i].b,t);
     }
     printf("%lld\n",ans);
 }
 int main()
 {
     //printf("%d\n",2*pp);
     int T;
     scanf("%d",&T);
     ;t<=T;t++)
     {
         scanf("%d",&n);
         ;i<=n;i++)
         {
             scanf("%d",&a[i].a);
             a[i].tid=i;
         }
         printf("Case %d: ",t);
         slove();
     }
     ;
 }

lightoj1085 线段树+dp的更多相关文章

  1. Tsinsen A1219. 采矿(陈许旻) (树链剖分,线段树 + DP)

    [题目链接] http://www.tsinsen.com/A1219 [题意] 给定一棵树,a[u][i]代表u结点分配i人的收益,可以随时改变a[u],查询(u,v)代表在u子树的所有节点,在u- ...

  2. HDU 3016 Man Down (线段树+dp)

    HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Ja ...

  3. [CF 474E] Pillars (线段树+dp)

    题目链接:http://codeforces.com/contest/474/problem/F 意思是给你两个数n和d,下面给你n座山的高度. 一个人任意选择一座山作为起始点,向右跳,但是只能跳到高 ...

  4. HDU-3872 Dragon Ball 线段树+DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3872 题意:有n个龙珠按顺序放在一列,每个龙珠有一个type和一个权值,要求你把这n个龙珠分成k个段, ...

  5. HDU4521+线段树+dp

    题意:在一个序列中找出最长的某个序列.找出的序列满足题中的条件. 关键:对于 第 i 个位置上的数,要知道与之相隔至少d的位置上的数的大小.可以利用线段树进行统计,查询.更新的时候利用dp的思想. / ...

  6. Codeforces Round #343 (Div. 2) D - Babaei and Birthday Cake 线段树+DP

    题意:做蛋糕,给出N个半径,和高的圆柱,要求后面的体积比前面大的可以堆在前一个的上面,求最大的体积和. 思路:首先离散化蛋糕体积,以蛋糕数量建树建树,每个节点维护最大值,也就是假如节点i放在最上层情况 ...

  7. Special Subsequence(离散化线段树+dp)

    Special Subsequence Time Limit: 5 Seconds      Memory Limit: 32768 KB There a sequence S with n inte ...

  8. hdu 4117 GRE Words (ac自动机 线段树 dp)

    参考:http://blog.csdn.net/no__stop/article/details/12287843 此题利用了ac自动机fail树的性质,fail指针建立为树,表示父节点是孩子节点的后 ...

  9. hdu4521(线段树+dp)

    传送门:小明系列问题——小明序列 题意:有n个数,求间距大于d的最长上升序列. 分析:dp[i]表示在i点以a[i]结束距离大于d的最长上升序列,然后每更新到第i点时,取i-d之前小于a[i]的数为结 ...

随机推荐

  1. java多线程下载网络图片

    import java.io.BufferedInputStream;import java.io.BufferedOutputStream;import java.io.BufferedReader ...

  2. License Manager 10.3启动失败解决方法

    参考:http://jingyan.baidu.com/article/c275f6bac8763ae33d756788.html 安装ARCGIS10.3过程中无法启动license. 解决办法: ...

  3. Tomcat Manager用户配置详解

      Tomcat Manager是Tomcat自带的.用于对Tomcat自身以及部署在Tomcat上的应用进行管理的web应用.Tomcat是Java领域使用最广泛的服务器之一,因此Tomcat Ma ...

  4. Batman+joker乱谈

      偶然一天内两次看到关于希斯·莱杰的文章(上面这个joker),貌似很多地方看到过这个,但是为什么他这么出名.知乎上的一篇文章 http://daily.zhihu.com/story/434137 ...

  5. Word Search [LeetCode]

    Problem Description: http://oj.leetcode.com/problems/word-search/ Basic idea: recursively go forward ...

  6. 84. Largest Rectangle in Histogram *HARD* -- 求柱状图中的最大矩形面积

    Given n non-negative integers representing the histogram's bar height where the width of each bar is ...

  7. 如何查看,关闭和开启selinux

    以下介绍一下SELinux相关的工具/usr/bin/setenforce 修改SELinux的实时运行模式setenforce 1 设置SELinux 成为enforcing模式setenforce ...

  8. jQuery Easing动画效果扩展(转)

    jQuery API提供了简单的动画效果如淡入淡出以及自定义动画效果,而今天我给大家分享的是一款jQuery动画效果扩展增强插件jquery.easing.js,使用该插件可以实现直线匀速运功.变加速 ...

  9. lmdb简介——结合MVCC的B+树嵌入式数据库

    lmdb简介 lmdb是openLDAP项目开发的嵌入式(作为一个库嵌入到宿主程序)存储引擎.其主要特性有: 基于文件映射IO(mmap) 基于B+树的key-value接口 基于MVCC(Multi ...

  10. Java DES 加解密文件

    import com.mchange.v2.io.DirectoryDescentUtils; import javax.crypto.Cipher;import javax.crypto.Ciphe ...