题意:给定一个N个数的数列,求所有不同不下降子序列的乘积之和,其中不同指的是组成它的数字和长度不完全相同

n (1 ≤ n ≤ 10^5) a[i]<=10^6

思路:考虑DP。设DP[a[i]]为最后一位为a[i]时所有序列的积之和,则dp[a[i]]=a[i]+sigma(dp[a[j]]) *a[i] (a[j]<=a[i],j<i)

后一部分可以用树状数组计算

为了去除最后一位相同的序列比如1 2 2 这个序列中1 2这个子序列只能算一遍

要强行去掉原来最后一位为a[i]的序列

 const mo=;
var dp:array[..]of int64;
n,i:longint;
s1,s2,t,ans,x:int64; function lowbit(x:longint):longint;
begin
exit(x and (-x));
end; function sum(x:longint):int64;
var t:int64;
begin
t:=;
while x> do
begin
t:=(t+dp[x]) mod mo;
x:=x-lowbit(x);
end;
exit(t);
end; procedure add(x,s:longint);
begin
while x<= do
begin
dp[x]:=(dp[x]+s) mod mo;
x:=x+lowbit(x);
end;
end; begin
//assign(input,'314C.in'); reset(input);
//assign(output,'314C.out'); rewrite(output);
readln(n);
for i:= to n do
begin
read(x);
s1:=sum(x); s2:=sum(x-);
t:=(s1+) mod mo*(x mod mo) mod mo;
t:=(t-(s1-s2) mod mo) mod mo;
t:=(t+mo) mod mo;
add(x,t);
ans:=(ans+t) mod mo;
end;
writeln(ans);
//close(input);
//close(output);
end.

【CF314C】Sereja and Subsequences(DP,树状数组)的更多相关文章

  1. CodeForces - 314C Sereja and Subsequences (树状数组+dp)

    Sereja has a sequence that consists of n positive integers, a1, a2, ..., an. First Sereja took a pie ...

  2. codeforces 597C C. Subsequences(dp+树状数组)

    题目链接: C. Subsequences time limit per test 1 second memory limit per test 256 megabytes input standar ...

  3. HDU 2227 Find the nondecreasing subsequences (DP+树状数组+离散化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2227 Find the nondecreasing subsequences             ...

  4. CF 314C Sereja and Subsequences(树状数组)

    题目链接:http://codeforces.com/problemset/problem/314/C 题意:给定一个数列a.(1)写出a的不同的所有非下降子列:(2)定义某个子列的f值为数列中各个数 ...

  5. 树形DP+树状数组 HDU 5877 Weak Pair

    //树形DP+树状数组 HDU 5877 Weak Pair // 思路:用树状数组每次加k/a[i],每个节点ans+=Sum(a[i]) 表示每次加大于等于a[i]的值 // 这道题要离散化 #i ...

  6. bzoj 1264 [AHOI2006]基因匹配Match(DP+树状数组)

    1264: [AHOI2006]基因匹配Match Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 793  Solved: 503[Submit][S ...

  7. 【bzoj2274】[Usaco2011 Feb]Generic Cow Protests dp+树状数组

    题目描述 Farmer John's N (1 <= N <= 100,000) cows are lined up in a row andnumbered 1..N. The cows ...

  8. 奶牛抗议 DP 树状数组

    奶牛抗议 DP 树状数组 USACO的题太猛了 容易想到\(DP\),设\(f[i]\)表示为在第\(i\)位时方案数,转移方程: \[ f[i]=\sum f[j]\;(j< i,sum[i] ...

  9. HDU2227Find the nondecreasing subsequences(树状数组+DP)

    题目大意就是说帮你给出一个序列a,让你求出它的非递减序列有多少个. 设dp[i]表示以a[i]结尾的非递减子序列的个数,由题意我们可以写出状态转移方程: dp[i] = sum{dp[j] | 1&l ...

  10. CodeForces - 597C Subsequences 【DP + 树状数组】

    题目链接 http://codeforces.com/problemset/problem/597/C 题意 给出一个n 一个 k 求 n 个数中 长度为k的上升子序列 有多少个 思路 刚开始就是想用 ...

随机推荐

  1. 从屏幕截取一块区域,将其赋给imageView

    UIGraphicsBeginImageContext(self.bounds.size); [self.layerrenderInContext:UIGraphicsGetCurrentContex ...

  2. 经常用到的js函数

    //获取样式 function getStyle(obj,attr){ if(obj.currentStyle){ return obj.currentStyle[attr]; }else{ retu ...

  3. pandas中数据聚合【重点】

    数据聚合 数据聚合是数据处理的最后一步,通常是要使每一个数组生成一个单一的数值. 数据分类处理: 分组:先把数据分为几组 用函数处理:为不同组的数据应用不同的函数以转换数据 合并:把不同组得到的结果合 ...

  4. 配置基于Vim的Python开发环境

    配置基于Vim的Python开发环境插件 Vundle YouCompleteMe NERDTree Vim-Jinja2-Syntax set nocompatible " be iMpr ...

  5. quartz 任务调度

    quartz 设置参数, 获取参数 在job中使用spring注入的service对象 循环获取所有的job 删除job @PersistJobDataAfterExecution @Disallow ...

  6. Laravel中chunk组块结果集处理

    如果你需要处理成千上万个 Eloquent 结果,可以使用 chunk 命令.chunk 方法会获取一个“组块”的 Eloquent 模型,并将其填充到给定闭包进行处理.使用 chunk 方法能够在处 ...

  7. selenium2 TestNG参数化

    想要参数化,首先要加入@Parameters({"参数1","参数2"}) package com.demo.test; import java.util.co ...

  8. 修改const变量

    看下面的一段代码 ; int * j=(int*)(&i); // 运行正确,j确为i的地址,但 int *j=&i; 编译错误 *j=; //确实改变了i的值 printf(&quo ...

  9. luogu1208 尼克的任务

    倒着推就是了 #include <iostream> #include <cstdio> #include <vector> using namespace std ...

  10. 令人惊叹的Chrome浏览器插件

    Chrome是一个简洁而又高效(高性能,高消耗)的浏览器.接下来让我吐血推荐一些常用的Chrome插件. 日常插件 uBlock Origin ----- 比Adblock性能更高的广告插件. Adk ...