U4858 sum

题目提供者666sb666

最新讨论

题目背景

定义一个序列的价值为序列中相邻元素差的绝对值之和。

如序列{2,1,3}的价值为|2-1|+|1-3|=3,而序列{4}的价值为0。

题目描述

现对于一给定序列,求价值最大的子序列的数量。

保证原序列中相邻的两个数不同。

注意:子序列不用连续

输入输出格式

输入格式:

第一行一个正整数n,表示序列中元素的个数。

接下来n行,每行一个数表示序列中的一个元素。

输出格式:

一个数表示数量。答案对1000000007取模。

输入输出样例

输入样例#1:

3

1

2

3

输出样例#1:

2

说明

样例解释:

40%:n<=1000

100%:n<=100000

数组中的元素的范围在int内

/*
恩想到正解了.
恩想的太多+码力太差.
W到挺.
*/
#include<iostream>
#include<cstdio>
#define MAXN 100001
#define mod 1000000007
#define LL long long
using namespace std;
LL s[MAXN],n,tot,a[MAXN],ans=1,t;
LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
return x*f;
}
LL ab(int x,int y)
{
if(x-y<=0) return y-x;
return x-y;
}
LL mi(LL a,LL b)
{
LL tot=1;
while(b)
{
if(b&1) tot=(tot*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return tot;
}
int main()
{
n=read();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=2;i<=n;i++)
{
if(a[i]<a[i-1]) t++;
else if(t>1) ans=(ans*mi(2,t-1))%mod,t=0;
}
if(t>1) ans=(ans*mi(2,t-1))%mod,t=0;
for(int i=2;i<=n;i++)
{
if(a[i]>a[i-1]) t++;
else if(t>1) ans=(ans*mi(2,t-1))%mod,t=0;
}
if(t>1) ans=(ans*mi(2,t-1))%mod;
cout<<ans;
return 0;
}
/*
正解还是比较好想的.
观察一下有的数是没有贡献的.
比如
1 2 3 4 5 4 3 2 1.
ans就是|5-1|+|1-5|.
那么中间的数可选可不选.
用乘法原理就可以了.
*/
#include<iostream>
#include<cstdio>
#define MAXN 100001
#define mod 1000000007
#define LL long long
using namespace std;
LL s[MAXN],n,tot,a[MAXN],ans=1,t;
LL read()
{
LL x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') x=x*10+ch-48,ch=getchar();
return x*f;
}
LL ab(int x,int y)
{
if(x-y<=0) return y-x;
return x-y;
}
LL mi(LL a,LL b)
{
LL tot=1;
while(b)
{
if(b&1) tot=(tot*a)%mod;
a=(a*a)%mod;
b>>=1;
}
return tot;
}
int main()
{
n=read();
for(int i=1;i<=n;i++) a[i]=read();
for(int i=2;i<=n;i++)
{
if(a[i]<a[i-1]) t++;
else if(t>1) ans=(ans*mi(2,t-1))%mod,t=0;
}
if(t>1) ans=(ans*mi(2,t-1))%mod,t=0;
for(int i=2;i<=n;i++)
{
if(a[i]>a[i-1]) t++;
else if(t>1) ans=(ans*mi(2,t-1))%mod,t=0;
}
if(t>1) ans=(ans*mi(2,t-1))%mod;
cout<<ans;
return 0;
}

洛谷比赛 U4858 sum的更多相关文章

  1. 洛谷比赛 「EZEC」 Round 4

    洛谷比赛 「EZEC」 Round 4 T1 zrmpaul Loves Array 题目描述 小 Z 有一个下标从 \(1\) 开始并且长度为 \(n\) 的序列,初始时下标为 \(i\) 位置的数 ...

  2. 洛谷P2398 GCD SUM (数学)

    洛谷P2398 GCD SUM 题目描述 for i=1 to n for j=1 to n sum+=gcd(i,j) 给出n求sum. gcd(x,y)表示x,y的最大公约数. 输入输出格式 输入 ...

  3. 洛谷比赛 U5442 买(最长链)

    U5442 买 题目提供者bqsgwys 标签 树形结构 树的遍历 洛谷原创 题目背景 小E是个可爱的电路编码员. 题目描述 一天小E又要准备做电路了,他准备了一个电路板,上面有很多个电路元器件要安装 ...

  4. 洛谷比赛 Joe的数

    /* 开始暴力+滚动数组70 后来发现不用循环很多 找p的倍数 找%p意义下为0的就好了 */ #include<iostream> #include<cstdio> #inc ...

  5. 洛谷P2398 GCD SUM [数论,欧拉筛]

    题目传送门 GCD SUM 题目描述 for i=1 to n for j=1 to n sum+=gcd(i,j) 给出n求sum. gcd(x,y)表示x,y的最大公约数. 输入输出格式 输入格式 ...

  6. 洛谷P2398 GCD SUM

    题目描述 for i=1 to n for j=1 to n sum+=gcd(i,j) 给出n求sum. gcd(x,y)表示x,y的最大公约数. 输入输出格式 输入格式: n 输出格式: sum ...

  7. 洛谷 P2398 GCD SUM || uva11417,uva11426,uva11424,洛谷P1390,洛谷P2257,洛谷P2568

    https://www.luogu.org/problemnew/show/P2398 $原式=\sum_{k=1}^n(k\sum_{i=1}^n\sum_{j=1}^n[(i,j)=k])$ 方法 ...

  8. 洛谷比赛 堕落的Joe

    /*暴力50*/ #include<iostream> #include<cstdio> #include<cstring> #define maxn 100010 ...

  9. 【洛谷比赛】[LnOI2019]长脖子鹿省选模拟赛 T1 题解

    今天是[LnOI2019]长脖子鹿省选模拟赛的时间,小编表示考的不怎么样,改了半天也只会改第一题,那也先呈上题解吧. T1:P5248 [LnOI2019SP]快速多项式变换(FPT) 一看这题就很手 ...

随机推荐

  1. iptables笔记

    一.内核转发 *永久开启转发 sysctl -w net.ipv4.ip_forward=1 *查看当前 cat /proc/sys/net/ipv4/ip_forward * 暂时开启 echo 1 ...

  2. Elastic Search对Document的搜索

    在ES中使用的重点.ES中存储的数据.核心就是为了提供全文搜索能力的.搜索功能非常重要.多练. 1 query string searchsearch的参数都是类似http请求头中的字符串参数提供搜索 ...

  3. 最全最新java面试题系列全家桶(带答案)

    最全最新java面试题系列全家桶(带答案) 置顶 2019年04月06日 22:40:28 青春季风暴 阅读数 14082 文章标签: java面试题技术栈 更多 分类专栏: 面试   版权声明:本文 ...

  4. word、ppt转换为pdf

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  5. ModbusTCP报文详解【二】

    [1]功能码05H [2]功能码06H [3]功能码0FH [4]功能码10H

  6. gflags 编译动态库

    gflags 编译动态库 这里涉及到gflags的安装,原来使用 sudo apt-get install libgflags-dev 但是后面有人在环境中下载安装了libgflags的安装包,解压后 ...

  7. MVC4学习要点记三

    一.数据迁移用来解决code first情况下当增加.删除.改变实体类,或改变DbContext类后,相应地更新数据库结构而不会对现有数据产生影响. 1.启用迁移指令:enable-migration ...

  8. java实现spark常用算子之Union

    import org.apache.spark.SparkConf;import org.apache.spark.api.java.JavaRDD;import org.apache.spark.a ...

  9. 微信小程序下拉刷新

    <config> { enablePullDownRefresh: true, navigationBarTitleText: "消息中心", } </confi ...

  10. ASP.NET中TextBox控件设立ReadOnly="true"后台取不到值

    SP.NET中TextBox控件设置ReadOnly="true"H或Enabled=false后台取不到值 当TextBox设置了ReadOnly="true" ...