【codeforces 314C】Sereja and Subsequences
【题目链接】:http://codeforces.com/problemset/problem/314/C
【题意】
让你从n个元素的数组中选出所有的不同的非递减子数列;
然后计算比这个子数列小的和它的长度一样长的数列的个数;
“小”的定义在题目里有说;
【题解】
设dp[i]表示以i作为非递减子数列的最后一个数的比它小的数列的个数;
则有递推式
dp[i] = (dp[1]+dp[2]+…+dp[i])*i+i;
写个树状数组,来快速求和就好;
要写出原数组,维护原数组;
不然求dp[i]比较麻烦;
最后输出∑dpi就好
【Number Of WA】
1(数组开小了)
【完整代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0),cin.tie(0)
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e6;
const int N1 = 1e5;
const int MOD = 1e9+7;
struct BIT{
LL a[N+10];
int lowbit(int x){
return x&(-x);
}
void add(int x,LL y){
while (x<=N){
a[x] = (a[x]+y)%MOD;
x+=lowbit(x);
}
}
LL sum(int x){
LL temp = 0;
while (x>0){
temp = (temp+a[x])%MOD;
x-=lowbit(x);
}
return temp;
}
}c;
int n;
LL dp[N+10];
int main(){
//Open();
Close();
cin >> n;
rep1(i,1,n){
int x;
cin >> x;
LL temp = (c.sum(x)*x + x)%MOD;
c.add(x,(temp-dp[x]+MOD)%MOD);
dp[x] = temp;
}
cout << c.sum(N) << endl;
return 0;
}
【codeforces 314C】Sereja and Subsequences的更多相关文章
- 【codeforces 367C】Sereja and the Arrangement of Numbers
[题目链接]:http://codeforces.com/problemset/problem/367/C [题意] 我们称一个数列a[N]美丽; 当且仅当,数列中出现的每一对数字都有相邻的. 给你n ...
- 【22.48%】【codeforces 689D】Friends and Subsequences
time limit per test2 seconds memory limit per test512 megabytes inputstandard input outputstandard o ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 803F】Coprime Subsequences
[题目链接]:http://codeforces.com/contest/803/problem/F [题意] 给你一个序列; 问你这个序列里面有多少个子列; 且这个子列里面的所有数字互质; [题解] ...
- 【codeforces 766A】Mahmoud and Longest Uncommon Subsequence
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- redis 篇 - hash
hash 可以认为是 python 中的字典 field 不允许重复 string类型的field和value的映射表 每个hash可以存储 232 - 1 键值对(40多亿) 方法 hest key ...
- [置顶]
智能家居开源项目 The open Home Automation Bus (openHAB)
================================================================================ 2014-05-19 论文的事情太多, ...
- HDU 5918 Sequence I
题目来源:2016 CCPC 长春站 题意:给出两个序列 a[] , b[] ,如果b1,b2....bm能够与aq,aq+p,aq+2p...aq+(m-1)p对应( q+(m-1)p<=n ...
- BZOJ 3786 星系探索 (splay+dfs序)
题目大意:给你一棵树,支持一下三种操作 1.获取某节点到根节点的路径上所有节点的权值和 2.更换某棵子树的父亲 3.某子树内所有节点的权值都增加一个值w 当时想到了splay维护dfs序,查完题解发现 ...
- 安装虚拟机和Linux系统
- 安装虚拟机 点击下载虚拟机 点击下载Linux系统 菜鸟网的Linux系统教程 1.安装虚拟机 在弹出的面板中选择标准--继续. 选择第二个选项,因为我们下载的光盘的镜像,所以直接选择刚才的dvd ...
- java.lang.RuntimeException: java.sql.SQLSyntaxErrorException: ORA-00911: 无效字符
这种情况可能是因为在设置数据库的时候,没有配置数据库的方言,导致sql语句无法被识别. 例如在配置Jfinal的配置文件的时候 如果不配置数据库的方言,默认下它是MySQL的,当使用oracle数据库 ...
- Android Java 程序员必备开发工具
对于Java,有两种截然不同的观点:一种认为Java是最简单功能最强大的编程语言之一,另一种则表示这种编程语言既难用又复杂. 下面这些工具或许功能和作用不同,但是有着一个共同的主旨,那就是——它们都是 ...
- NHibernate3剖析:Mapping篇之集合映射基础(3):List映射
系列引入 NHibernate3.0剖析系列分别从Configuration篇.Mapping篇.Query篇.Session策略篇.应用篇等方面全面揭示NHibernate3.0新特性和应用及其各种 ...
- cmd 下命令
tasklist 查看当前进程 taskkill /? 查看taskkill 的帮助信息 详情 cmd /? 查看cmd详情 color /? 查看颜色详情 比如 color 2 md d:\ji ...
- 解决django.db.utils.InternalError: (1049, "Unknown database 'exam_db'")
先检查seeting数据库配置DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', 'NAME': 'eaxm_db', ' ...