Increasing Speed Limits
Increasing Speed Limits |
Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) |
Total Submission(s): 186 Accepted Submission(s): 86 |
Problem Description
You were driving along a highway when you got caught by the road police for speeding. It turns out that they\'ve been following you, and they were amazed by the fact that you were accelerating the whole time without using the brakes! And now you desperately need an excuse to explain that.
You've decided that it would be reasonable to say "all the speed limit signs I saw were in increasing order, that\'s why I've been accelerating". The police officer laughs in reply, and tells you all the signs that are placed along the segment of highway you drove, and says that's unlikely that you were so lucky just to see some part of these signs that were in increasing order. Now you need to estimate that likelihood, or, in other words, find out how many different subsequences of the given sequence are strictly increasing. The empty subsequence does not count since that would imply you didn't look at any speed limits signs at all! For example, (1, 2, 5) is an increasing subsequence of (1, 4, 2, 3, 5, 5), and we count it twice because there are two ways to select (1, 2, 5) from the list. |
Input
The first line of input gives the number of cases, N. N test cases follow. The first line of each case contains n, m, X, Y and Z each separated by a space. n will be the length of the sequence of speed limits. m will be the length of the generating array A. The next m lines will contain the m elements of A, one integer per line (from A[0] to A[m-1]).
Using A, X, Y and Z, the following pseudocode will print the speed limit sequence in order. mod indicates the remainder operation. for i = 0 to n-1 Note: The way that the input is generated has nothing to do with the intended solution and exists solely to keep the size of the input files low. 1 ≤ m ≤ n ≤ 500 000 |
Output
For each test case you should output one line containing "Case #T: S" (quotes for clarity) where T is the number of the test case and S is the number of non-empty increasing subsequences mod 1 000 000 007.
|
Sample Input
2 |
Sample Output
Case #1: 15 |
Source
2009 Multi-University Training Contest 6 - Host by WHU
|
Recommend
gaojie
|
/*
题意:按照题目给出的循环条件:
for i = 0 to n-1
print A[i mod m]
A[i mod m] = (X * A[i mod m] + Y * (i + 1)) mod Z
求出一个长度为n的序列A,然后求数列A的严格递增的子序列的个数
例如第一组样例,按照循环条件求出的序列为 1,2,1,2,3(不要怀疑,这就是按照循环来求出来的)
递增子序列为:
{1},{2},{1},{2},{3},
{1,2},{1,2},{1,3},{2,3},{1,2},
{1,3},{2,3},{1,2,3},{1,2,3},{1,2,3}. 初步思路:树状数组求递增子序列
*/ #include<bits/stdc++.h>
#define N 500010
#define mod 1000000007
#define lowbit(x) x&(-x)
using namespace std;
struct node
{
int id;
long long w;
bool operator< (const node& b)const{
return w<b.w;
} }s[N];
long long n,m,x,y,z;
long long t;
long long A[N];
long long mapn[N];///用于映射数组,标记元素的id
long long c[N];
int len =;///用于标记去重后的序列长度
long long res=;
void update(int x,int val){
while(x<N){
c[x]+=val;
c[x]%=mod;
x+=lowbit(x);
}
}
long long getsum(int x){
long long res=;
while(x>){
res+=c[x];
res%=mod;
x-=lowbit(x);
}
return res;
}
void init(){
memset(c,,sizeof c);
res=;
}
int main(){
// freopen("in.txt","r",stdin);
scanf("%d",&t);
for(int ca=;ca<=t;ca++){
printf("Case #%d: ",ca);
init();
scanf("%lld%lld%lld%lld%lld",&n,&m,&x,&y,&z);
for(int i=;i<m;i++){
scanf("%lld",&A[i]);
}
for(int i=;i<n;i++){///因为树状数组0这位是处理不到的所以坐标整个向右平移以为
s[i+].w=A[i%m]+;
s[i+].id=i+;
A[i%m]=(x*A[i%m]+y*(i+))%z;
} // for(int i=1;i<=n;i++){
// cout<<s[i].w<<" ";
// }cout<<endl; sort(s+,s+n+);///排好序然后用树状数组进行求最长上升子序列
int cur=;
for(int i=;i<=n;i++){
if(s[i].w==s[i-].w)
mapn[s[i].id]=cur;
else
mapn[s[i].id]=++cur;
} // for(int i=1;i<=n;i++){
// cout<<mapn[s[i]]<<" ";
// }cout<<endl; long long ans=;
for(int i=;i<=n;i++){
update(mapn[i],getsum(mapn[i]-)+);
}
printf("%d\n",getsum(n));
}
return ;
}
Increasing Speed Limits的更多相关文章
- hdu 3030 Increasing Speed Limits (离散化+树状数组+DP思想)
Increasing Speed Limits Time Limit: 2000/10000 MS (Java/Others) Memory Limit: 32768/32768 K (Java ...
- HDU 3030 - Increasing Speed Limits
Problem Description You were driving along a highway when you got caught by the road police for spee ...
- HDU题解索引
HDU 1000 A + B Problem I/O HDU 1001 Sum Problem 数学 HDU 1002 A + B Problem II 高精度加法 HDU 1003 Maxsu ...
- poj 2501 Average Speed
Average Speed Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 4842 Accepted: 2168 Des ...
- 使用OpenMP加快OpenCV图像处理性能 | speed up opencv image processing with openmp
本文首发于个人博客https://kezunlin.me/post/7a6ba82e/,欢迎阅读! speed up opencv image processing with openmp Serie ...
- poj3311 Hie with the Pie (状态压缩dp,旅行商)
Hie with the Pie Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3160 Accepted: 1613 ...
- 2014-2015 ACM-ICPC, NEERC, Moscow Subregional Contest C. CIA Datacenter
C. CIA Datacenter time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- 状态压缩 DP
D - Hie with the Pie Crawling in process... Crawling failed Time Limit:2000MS Memory Limit:65536 ...
- 专题:mdadm Raid & LVM
>FOR FREEDOM!< {A} Introduction Here's a short description of what is supported in the Linux R ...
随机推荐
- Thinkphp5.0 在自己定义一个公共方法的控制器并且继承了Controller类的时候报错
在建立网站的时候,你通常想着把一些共有的方法提取出来,放入一个控制器内,如果你是将业务逻辑写入了构造函数里面,那么就得注意了. 在thinkphp5.0当中,有一个初始化的方法,类似于构造函数,那就是 ...
- vue 父组件向子组件传递事件/调用事件
方法一:子组件监听父组件发送的方法 方法二:父组件调用子组件方法 子组件: export default { mounted: function () { this.$nextTick(functio ...
- vue-ajax小封装
1. js 文件: /** ajax封装:* 1. 引入文件* 2. new Vue().ajax.get(url,data,fn,ojson), 或 new Vue().ajax.post(url, ...
- Hbase 技术细节笔记(上)
欢迎大家前往腾讯云技术社区,获取更多腾讯海量技术实践干货哦~ 作者:张秀云 前言 最近在跟进Hbase的相关工作,由于之前对Hbase并不怎么了解,因此系统地学习了下Hbase,为了加深对Hbase的 ...
- leetCode没那么难啦 in Java (二)
介绍 本篇介绍的是标记元素的使用,很多需要找到正确元素都可以将正确元素应该插入的位置单独放置一个标记来记录,这样可以达到原地排序的效果. Start 27.RemoveElement 删除指定元 ...
- day01:study HTTP协议
总结: 1.对web客户端和web服务器之间的通讯有了基本原理有了简单理解. 2.对http协议有了相关概念的建立 3.B/S C/S 两种形式 4.搭建tomcat服务器的环境,相关配置(虚拟目录 ...
- docker镜像文件导入与导出
工作中经常需要拉取一些国外的镜像,但是网络限制等原因在公司拉取很慢,所以我习惯用亚马逊服务器拉取镜像,导出后下载到本地再导入开发环境 1. 查看镜像id sudo docker images REPO ...
- vue2购物车ch4-(筛选v-for 点击的那个设置样式 设为默认地址其他 联动 非循环的列表选中和非选中 删除当前选中的列表)
1 address.html <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- js系列教程1-数组操作全解
全栈工程师开发手册 (作者:栾鹏) 快捷链接: js系列教程1-数组操作全解 js系列教程2-对象和属性全解 js系列教程3-字符串和正则全解 js系列教程4-函数与参数全解 js系列教程5-容器和算 ...
- jquery基本选择器:id选择器、class选择器、标签选择器、通配符选择器
全栈工程师开发手册 (作者:栾鹏) jquery系列教程1-选择器全解 jquery基本选择器 jquery基本选择器,包括id选择器.class选择器.标签选择器.通配符选择器,同时配合选择器的空格 ...