【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个) 问你最少走多远; [题解] 肯定不多走啊; ... 
随机推荐
- shell脚本杀死某个服务的进程
			摘抄如下: 新建sh结尾的文件内容如下: NAME=$1echo $NAMEID=`ps -ef | grep "$NAME" | grep -v "$0" | ... 
- gcp – 源于CP的高级命令行文件拷贝工具
			作者:linux 出处:http://linux.cn/thread/11868/1/1/ gcp – 源于CP的高级命令行文件拷贝工具 几周前,我们讨论了高级拷贝(修改于cp命令,让其可以显示复制进 ... 
- vue项目初始化步骤
			项目初始化:() 1. 安装vue-cli : npm install -g vue-cli 2.初始化项目: vue init webpack my-project 3.进入项目: c ... 
- HDU 1005 Number Sequence(找规律)
			链接:传送门 题意:略 思路:f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7 -> f(n) = (A * f(n-1)%7 + B * f(n-1)%7) ... 
- LAMP自动安装脚本
			#!/bin/bash # 功能描述:LAMP自动安装脚本 # 初始化 if [ "$(cat /etc/system-release | awk '{print $(NF-1)}' | a ... 
- W10子系统UBantu命令安装Redis及其启动
			W10子系统UBantu命令安装Redis及其启动 打开W10子系统UBantu 安装Redis $sudo apt-get install redis-server 启动Redis redis-se ... 
- tomcat使用及原理
			1,Tomcat作为Servlet容器的基本功能 2,Tomcat的组成结构 Tomcat本身由一列的可配置的组件构成,其中核心组件是Servlet容器组件,它是所有其他Tomcat组件的顶层容器.T ... 
- Vitual Router in The Cloud
			VyOS and ESXi,VyOS Configuration The next step is to configure both VyOS routers. Before we do, we s ... 
- 浅谈关于collection接口及相关容器类(一)
			Collection在英文单词的意思是:採集,收集. 而在JAVA API 文档中它是一个收集数据对象的容器. Collection作为容器类的根接口.例如以下图(部分子接口未写出): waterma ... 
- android全磁盘加密
			android 全磁盘加密 什么是全磁盘加密? 全磁盘加密是使用一个密钥来为android设备上全部的用户数据加密的过程.一旦设备被加密,全部的用户创建的数据都将会在提交的磁盘之前自己主动加密,在读取 ... 
