lightoj1085 线段树+dp
//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的更多相关文章
- Tsinsen A1219. 采矿(陈许旻) (树链剖分,线段树 + DP)
[题目链接] http://www.tsinsen.com/A1219 [题意] 给定一棵树,a[u][i]代表u结点分配i人的收益,可以随时改变a[u],查询(u,v)代表在u子树的所有节点,在u- ...
- HDU 3016 Man Down (线段树+dp)
HDU 3016 Man Down (线段树+dp) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- [CF 474E] Pillars (线段树+dp)
题目链接:http://codeforces.com/contest/474/problem/F 意思是给你两个数n和d,下面给你n座山的高度. 一个人任意选择一座山作为起始点,向右跳,但是只能跳到高 ...
- HDU-3872 Dragon Ball 线段树+DP
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3872 题意:有n个龙珠按顺序放在一列,每个龙珠有一个type和一个权值,要求你把这n个龙珠分成k个段, ...
- HDU4521+线段树+dp
题意:在一个序列中找出最长的某个序列.找出的序列满足题中的条件. 关键:对于 第 i 个位置上的数,要知道与之相隔至少d的位置上的数的大小.可以利用线段树进行统计,查询.更新的时候利用dp的思想. / ...
- Codeforces Round #343 (Div. 2) D - Babaei and Birthday Cake 线段树+DP
题意:做蛋糕,给出N个半径,和高的圆柱,要求后面的体积比前面大的可以堆在前一个的上面,求最大的体积和. 思路:首先离散化蛋糕体积,以蛋糕数量建树建树,每个节点维护最大值,也就是假如节点i放在最上层情况 ...
- Special Subsequence(离散化线段树+dp)
Special Subsequence Time Limit: 5 Seconds Memory Limit: 32768 KB There a sequence S with n inte ...
- hdu 4117 GRE Words (ac自动机 线段树 dp)
参考:http://blog.csdn.net/no__stop/article/details/12287843 此题利用了ac自动机fail树的性质,fail指针建立为树,表示父节点是孩子节点的后 ...
- hdu4521(线段树+dp)
传送门:小明系列问题——小明序列 题意:有n个数,求间距大于d的最长上升序列. 分析:dp[i]表示在i点以a[i]结束距离大于d的最长上升序列,然后每更新到第i点时,取i-d之前小于a[i]的数为结 ...
随机推荐
- SAP SD你要知道的透明表
一.客户主数据 基本数据放在KNA1里: 公司代码放在KNB1里: 销售视图放在KNVV里: 合作伙伴放在KNVP里: 二.信用主数据 KNKK里有信贷限额.应收总额.特别往来: S066里是未清订单 ...
- 能源项目xml文件 -- springMVC-servlet.xml
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...
- 5.6 WebDriver API实例讲解(31-35)
31.判断页面元素是否存在 public static void testElementExist(){ driver.get("http://www.sogou.com"); t ...
- 《javascript高级程序设计》 第25章 新兴的API
25.1 requestAnimationFrame() 25.1.1 早期动画循环 25.1.2 循环间隔的问题 25.1.3 mozRequestAnimation-Frame.webkitReq ...
- 安装 request模块
python3 requests 安装包下载安装[windows] 听语音 | 浏览:54 | 更新:2016-07-25 17:09 windows下直接使用:easy_install reques ...
- Eclipse Maven Web Application 设置配置文件
默认的项目添加会有问题,各种版本和编译版本错误造成. 1.更改Maven编译版本 2.更改项目Facets针对的版本 3.更改Settings
- Javascript的"预编译"思考
今天工作需要,搜索下JS面试题,看到一个题目,大约是这样的 <script> var x = 1, y = z = 0; function add(n) { n = n+1; } y = ...
- 189. Rotate Array -- 将数组前一半移到后一半
Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array ...
- cd命令进入D盘
CD命令是更改目录命令如果要进入D盘 不用这个命令 直接输入 D: 回车 即可要是你非要使用CD命令那要加参数/DCD D:系统只是认为你想在系统中记忆一下D盘所以还是返回原先目录例:D盘下有一个目录 ...
- Java 集合系列 04 LinkedList详细介绍(源码解析)和使用示例
java 集合系列目录: Java 集合系列 01 总体框架 Java 集合系列 02 Collection架构 Java 集合系列 03 ArrayList详细介绍(源码解析)和使用示例 Java ...