第十四个目标 (fzu)
Problem Description
目暮警官、妃英里、阿笠博士等人接连遭到不明身份之人的暗算,柯南追踪伤害阿笠博士的凶手,根据几起案件现场留下的线索发现凶手按照扑克牌的顺序行凶。在经过一系列的推理后,柯南发现受害者的名字均包含扑克牌的数值,且扑克牌的大小是严格递增的,此外遇害者与毛利小五郎有关。
为了避免下一个遇害者的出现,柯南将可能遭到暗算的人中的数字按关联程度排列了出来,即顺序不可改变。柯南需要知道共有多少种可能结果,满足受害人名字出现的数字严格递增,但是他柯南要找出关键的证据所在,所以这个任务就交给你了。
(如果你看不懂上面在说什么,这题是求一个数列中严格递增子序列的个数。比如数列(1,3,2)的严格递增子序列有(1)、(3)、(2)、(1,3)、(1,2),共5个。长得一样的但是位置不同的算不同的子序列,比如数列(3,3)的答案是2。)
Input
多组数据(<=10),处理到EOF。
第一行输入正整数N(N≤100 000),表示共有N个人。
第二行共有N个整数Ai(1≤Ai≤10^9),表示第i个人名字中的数字。
Output
每组数据输出一个整数,表示所有可能的结果。由于结果可能较大,对1 000 000 007取模后输出。
Sample Input
Sample Output
#include<stdio.h>
#include<stack>
#include<algorithm>
using namespace std; #define Lson r<<1
#define Rson r<<1|1 const int maxn = 1e5+;
const int Mod = 1e9+; struct node
{
int L, R, Mid;
long long sum;
}a[maxn<<]; int val[maxn], Hash[maxn]; void Build(int r, int L, int R)
{
a[r].L = L;
a[r].R = R;
a[r].Mid = (L+R) / ;
a[r].sum = ; if(L == R)
return ; Build(Lson, L, a[r].Mid);
Build(Rson, a[r].Mid+, R);
}
///x位置加上一个值val
void Insert(int r, int x, int sum)
{
(a[r].sum += sum) %= Mod; if(a[r].L == a[r].R)
return ; if(x <= a[r].Mid)
Insert(Lson, x, sum);
else
Insert(Rson, x, sum);
}
int Query(int r, int L, int R)
{
if(L > R)
return ; if(a[r].L == L && a[r].R == R)
return a[r].sum; if(R <= a[r].Mid)
return Query(Lson, L, R);
else if(L > a[r].Mid)
return Query(Rson, L, R);
else
{
int Lval = Query(Lson, L, a[r].Mid);
int Rval = Query(Rson, a[r].Mid+, R); return (Lval+Rval) % Mod;
}
} int main()
{
int N; while(scanf("%d", &N) != EOF)
{
for(int i=; i<N; i++)
{
scanf("%d", &val[i]);
Hash[i] = val[i];
} Hash[N] = ; sort(Hash, Hash+N+);
int hn = unique(Hash, Hash+N+)-Hash; Build(, , hn+); for(int i=; i<N; i++)
{
int x = lower_bound(Hash, Hash+hn, val[i]) - Hash;
int sum = Query(, , x-);
Insert(, x, sum+);
} int ans = Query(, , hn+); printf("%d\n", ans);
} return ;
}
第十四个目标 (fzu)的更多相关文章
- FZu Problem 2236 第十四个目标 (线段树 + dp)
题目链接: FZu Problem 2236 第十四个目标 题目描述: 给出一个n个数的序列,问这个序列内严格递增序列有多少个?不要求连续 解题思路: 又遇到了用线段树来优化dp的题目,线段树节点里 ...
- 第十四个目标(dp + 树状数组 + 线段树)
Problem 2236 第十四个目标 Accept: 17 Submit: 35 Time Limit: 1000 mSec Memory Limit : 32768 KB Probl ...
- Problem 2236 第十四个目标
Problem 2236 第十四个目标 Accept: 4 Submit: 6Time Limit: 1000 mSec Memory Limit : 32768 KB Problem D ...
- FZU2236 第十四个目标 dp+树状数组优化
分析:这种题烂大街,n^2,然后数据结构优化下到nlogn,离散化 #include <cstdio> #include <cstring> #include <queu ...
- FZU Monthly-201903 tutorial
FZU Monthly-201903 tutorial 题目(难度递增) easy easy-medium medium medium-hard hard 思维难度 ABF G CH D E A. D ...
- FZU Monthly-201906 tutorial
FZU Monthly-201906 tutorial 题目(难度递增) easy easy-medium medium medium-hard hard 思维难度 AE B DG CF H A. X ...
- arcgis api for js入门开发系列五地图态势标绘(含源代码)
上一篇实现了demo的地图查询功能,本篇新增地图态势标绘模块,截图如下: 本篇核心的在于调用API的Draw工具:https://developers.arcgis.com/javascript/3/ ...
- Entity Framework 6 Recipes 2nd Edition(10-3)译 -> 返回结果是一个标量值
10-3. 返回结果是一个标量值 问题 想取得存储过程返回的一个标量值. 解决方案 假设我们有如Figure 10-2所示的ATM机和ATM机取款记录的模型 Figure 10-2. 一个ATM机和A ...
- Entity Framework 6 Recipes 2nd Edition(11-1)译 -> 从“模型定义”函数返回一个标量值
第11章函数 函数提供了一个有力代码复用机制, 并且让你的代码保持简洁和易懂. 它们同样也是EF运行时能利用的数据库层代码.函数有几类: Rowset Functions, 聚合函数, Ranking ...
随机推荐
- javascript 生存周期
生存周期: 局部 JavaScript 变量 在 JavaScript 函数内部声明的变量(使用 var)是局部变量,所以只能在函数内部访问它.(该变量的作用域是局部的). 您可以在不同的函数中使用名 ...
- opencv 线,椭圆 圆
//void MyLines() { // Point p1 = Point(20, 30); // Point p2; // p2.x = 400; // p2.y = 400; // Scalar ...
- JTable 查询
public JTable query(String table) throws SQLException { DefaultTableModel tablemodel = new DefaultTa ...
- spring读取properties的几种方式
参考链接:http://www.cnblogs.com/zxf330301/p/6184139.html
- Mac 下配置Nginx安装环境配置详细说明
环境信息: Mac OS X 10.11.1 Homebrew 0.9.5 正文 一.安装 Nginx 1.终端执行: ? 1 2 brew search nginx brew install ng ...
- codeforces round#509
博主水平不高, 只能打完$4$题, QAQ什么时候才能变强啊嘤嘤嘤 订正完6题了, 还想打今天下午的CF , 只能迟十分钟了, 掉分预定 A. Heist 输出 $max - min + n - 1 ...
- Linux快速安装apache+mysql+php环境
yum -y install httpd mysql mysql-server php php-mysql postgresql postgresql-server php-postgresql ph ...
- libpcap 库使用(一)
参考资料: http://www.tcpdump.org/ DESCRIPTION The Packet Capture library provides a high level interface ...
- [Jmeter] 用xsltproc生成html格式的报告
1.下载xsltproc 下载地址:ftp://ftp.zlatkovic.com/libxml/libxslt-1.1.26.win32.zip 其中包含我们所需要的xsltproc可执行文件:xs ...
- system v 共享内存
#include <stdio.h> #include <string.h> #include <errno.h> #include <unistd.h> ...