//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. 解决点击a标签返回页面顶部的问题

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  2. jq实现全选非全选

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  3. .net 时间戳和日期互转 【转】http://www.cnblogs.com/zhuiyi/p/5307540.html

    .net 时间戳和日期互转 1.时间戳转日期public static DateTime IntToDateTime(int timestamp){ return TimeZone.CurrentTi ...

  4. JS回调函数(callback)

    在使用Jquery的时候,用到Callback(),回调函数的概念.而且很多. 比如: $.ajax({ url:"test.json", type: "GET" ...

  5. jdk 安装

    安装JDK 选择安装目录 安装过程中会出现两次 安装提示 .第一次是安装 jdk ,第二次是安装 jre .建议两个都安装在同一个java文件夹中的不同文件夹中.(不能都安装在java文件夹的根目录下 ...

  6. SpringMVC整合Quartz实现定时任务以及Tomcat服务执行初始化定时任务

    1.导入quartz.jar包,或者pom.xml 配置对应的依赖: <dependency> <groupId>org.quartz-scheduler</groupI ...

  7. 报错解决:No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here

    大概分析一般使用了注解才会报这方面的错 1.没有在spring的ApplicationContext.xml中开启注解事务 <!-- 开启注解事务 --> <tx:annotatio ...

  8. 创建交货单/外向交货BAPI_OUTB_DELIVERY_CREATE_SLS/STO

    FUNCTION Z_SD_CREATE_DN. *"-------------------------------------------------------------------- ...

  9. Entity Framework - 理清关系 - 基于外键关联的单向一对一关系

      注:本文针对的是 Entity Framework Code First 场景. 之前写过三篇文章试图理清Entity Framework中的一对一关系(单相思(单向一对一), 两情相悦(双向一对 ...

  10. [转]C#取得内网IP、外网IP、客户端IP方法

    前言 在 Windows Form Application 里对于取得 IP Address 有内网.外网两种 IP Address ,如果只需要取得内网 IP Address ,可以透过使用 IPH ...