【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个) 问你最少走多远; [题解] 肯定不多走啊; ...
随机推荐
- php 密码hash加密
做密码加密,记录一下. password_hash 函数在 PHP 5.5 时被引入. 此函数现在使用的是目前 PHP 所支持的最强大的加密算法 BCrypt .例子: $passwordHash = ...
- 2019-03-20 Python爬取需要登录的有验证码的网站
当你向验证码发起请求的时候,就有session了,记录下这次session 因为每当你请求一次验证码 或者 请求一次登录首页,验证码都在变动 验证码的链接可能不是固定的,可能需要GET/POST请求, ...
- Hash大法
内容参考<算法竞赛进阶指南> 之前集训的时候听老师讲过,字符串题目中,hash一般不是正解,但是是一个优秀的暴力,可以拿比较多的部分分. hash涉及内容很多,这里只讨论字符串hash 可 ...
- 洛谷 P1414 又是毕业季II (多个数的最大公因数)
这道题其实不难,但是我想复杂了 我想的是把每个数质因数分解,然后每次就枚举每个质因数 来求最小公倍数. 然后想了想这样复杂度将会非常的大,肯定超时 然后看了题解发现不需要质因数分解,直接存因数的个数就 ...
- 初识单点登录及JWT实现
单点登录 多系统,单一位置登录,实现多系统同时登录的一种技术 (三方登录:某系统使用其他系统的用户,实现本系统登录的方式.如微信登录.支付宝登录) 单点登录一般是用于互相授信的系统,实现单一位置登录, ...
- SPOJ 4491
不妨先把所有要求的素数的对的个数写出来 f(2)=u(1)G(2)+u(2)*G(2*2)+u(3)*G(2*3)+.....u(k2)*G(2*k2) f(3)=u(1)G(3)+u(2)*G(2* ...
- OpenMp之reduction求和
// OpenMP1.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include"omp.h" #include& ...
- shareSDK的初步使用(shareSDK中微信、qq等兼容问题,以及cocoapods支持架构冲突问题的解决)
第一次使用shareSDK来做第三方分享,可是.昨天一天都是在调试bug,一直错误不断! 先说下我的开发环境: xcode:5.1 真机调试:iPhone5s 我们都知道xcode5.1以后開始是支持 ...
- 【手势交互】9. PS Move
索尼研发体感控制技术已有10年,在过去那么多年里.尝试了3D摄像头.超声波和电磁感应等各种技术.最后还是觉得眼下的MOVE所使用的技术最为合适.PS Move是索尼于2010年9月份推出.用来让PS3 ...
- doT.js的使用
引言 doT.js可以更好的在html端使用json数据. {{ }} for evaluation 模板标记符 {{= }} for interpolation 输出显示,默认变量名叫it {{! ...