题目描述:

You are given an array consisting of nmonotonic renumeration as an array b consisting of \(n\)integers such that all of the following conditions are met:

  • b1=0;

  • for every pair of indices iand jsuch that 1≤i,jn, then \(b_i=b_j\), it is still possible that \(b_i=b_j\)

    for every index i∈[1,n−1] either \(b_i=b_{i+1}\) or \(b_{i+1}\)=\(b_i\)+1

For example, if a=[1,2,1,2,3], then two possible monotonic renumerations of are b=[0,0,0,0,0]\(b=[0,0,0,0,1]\).

Your task is to calculate the number of different monotonic renumerations of a. The answer may be large, so print it modulo \(998244353\).

Input

The first line contains one integer n(\(2\leq{n}\leq{2*10^5}\)) — the number of elements in a

The second line contains n

integers (\(1≤a_i≤10^9\))

Output

Print one integer — the number of different monotonic renumerations of a, taken modulo 998244353.

Examples

Input

Copy

5
1 2 1 2 3

Output

Copy

2

Input

Copy

2
100 1

Output

Copy

2

Input

Copy

4
1 3 3 7

Output

Copy

4

思路:

题目的意思是给一个数列a,构造数列b,按照以下规则:如果a中有相同的元素,相同元素的位置对应在b中位置上的元素必须也想同。还有b是非减数列,一次最多增加1.

那么我们可以知道a相同元素的位置对应在b的位置,这个位置之间的所有元素在b中必须相同。因为b中元素要么与前一个一样,要么大一。

题目就变成了,找到重合的区间加起来得到总的重合区间,这个总区间上的元素在b中必须相同。

可以在输入时记录下每个元素的最远相同元素的位置,如果没有相同元素就记录本身位置。然后遍历一遍数组,记录当前重合区间的右端点。如果元素位置在当前重合区间右端点内,元素必须相同,没得选,就不断更新重合区间右端点;直到元素位置大于区间右端点,说明已经不在重合区间内,可以选择元素大小了,有两种选法,总结果就乘上2,然后把区间右端点更新为当前位置,继续遍历。注意这个不在区间内本身就可能是新的重合区间,而不只是不在重合区间内的一个点。按照算法乘以二更新右端点后就可以正确继续执行。

代码:

#include <iostream>
#include <map>
#define maxn 200005
#define mod 998244353
using namespace std;
int n;
int a[maxn];
map<int,int> mp;
int main()
{
cin >> n;
for(int i = 0;i<n;i++)
{
cin >> a[i];
mp[a[i]] = i;
}
int right = 0;//当前区间右端点
long long ans = 1;
for(int i = 0;i<n;i++)
{
if(i<=right)
{
right = max(right,mp[a[i]]);
}
else
{
ans = (ans*2)%mod;
right = mp[a[i]];
}
}
cout << ans << endl;
return 0;
}

Codeforces J. Monotonic Renumeration(组合)的更多相关文章

  1. 补题Codeforces 1102E. Monotonic Renumeration

    这个题还是不太懂,下面附上的是大佬的题解(https://zhanghuimeng.github.io/post/codeforces-1102e-monotonic-renumeration/) E ...

  2. 【Codeforces 1102E】Monotonic Renumeration

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 会发现如果a[i]=a[j] 那么b[i]~b[j]都是相同的,等于b[i] 而b[i]等于b[i-1]+1或者b[i] 有两种可能 所以对于 ...

  3. Codeforces Round #531 (Div. 3) E. Monotonic Renumeration (构造)

    题意:给出一个长度为\(n\)的序列\(a\),根据\(a\)构造一个序列\(b\),要求: ​ 1.\(b_{1}=0\) ​ 2.对于\(i,j(i\le i,j \le n)\),若\(a_{i ...

  4. Codeforces 140E(排列组合、dp)

    要点 主要学到的东西:一个序列染色,相邻不染同色,恰用\(j\)种颜色的1.模式数.2.方案数.3.具体染色数. 从大的思路上来讲:先dp预处理出每一层的模式数:\(f[i][j]\)表示\(i\)个 ...

  5. CodeForces 131C C (组合)

    There are n boys and m girls attending a theatre club. To set a play "The Big Bang Theory" ...

  6. Codeforces 15E Triangles 【组合计数】

    Codeforces 15E Triangles Last summer Peter was at his granny's in the country, when a wolf attacked ...

  7. Codeforces J. Sagheer and Nubian Market(二分枚举)

    题目描述: Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes in ...

  8. Codeforces J. Soldier and Number Game(素数筛)

    题目描述: Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes inpu ...

  9. Codeforces J. A Simple Task(多棵线段树)

    题目描述: Description This task is very simple. Given a string S of length n and q queries each query is ...

随机推荐

  1. go 单元测试框架介绍

    最近项目在补充单元测试,这里介绍以下几个go里流行的单元测试框架. gomock gostub monkey Convey 下面介绍下各个框架的主要用途 convey 主要用途是用来组织测试用例的 g ...

  2. 使用ReadtheDocs托管技术文档

    ReadtheDocs Read the Docs非常适合写软件文档以及编写一些教程.电子书之类.对于一些一两篇文章就能写清楚的可以记笔记或写博客, 但是如果要写成一个系列的,不如写成一本书的形式,更 ...

  3. Spring计时器StopWatch使用

    我们可以利用已有的工具类中的秒表,常见的秒表工具类有org.springframework.util.StopWatch.org.apache.commons.lang.time.StopWatch以 ...

  4. Django-12-auth认证组件

    1. 介绍 我们在开发一个网站的时候,无可避免的需要设计实现网站的用户系统.此时我们需要实现包括用户注册.用户登录.用户认证.注销.修改密码等功能. Django作为一个完美主义者的终极框架,当然也会 ...

  5. Django框架之第六篇(模型层)--单表查询和必知必会13条、单表查询之双下划线、Django ORM常用字段和参数、关系字段

    单表查询 补充一个知识点:在models.py建表是 create_time = models.DateField() 关键字参数: 1.auto_now:每次操作数据,都会自动刷新当前操作的时间 2 ...

  6. 记一次奇怪的python多个变量拼接后的字符串丢失事件

    在一次脚本运行中出现了多个变量拼接后的值出现丢失情况. a = "hello " b = "ketty" c = a + b + "!" 预 ...

  7. Redis 集群:CLUSTERDOWN The cluster is down

    1.错误 (error)CLUSTERDOWN The cluster is down 2.问题表现 Java项目使用redis集群时报错, HTTP Status 500 - Could not g ...

  8. dump net core lldb 分析

    原文https://www.cnblogs.com/calvinK/p/9274239.html centos7 lldb 调试netcore应用的内存泄漏和死循环示例(dump文件调试) 写个dem ...

  9. Java调用Http/Https接口(2)--HttpURLConnection/HttpsURLConnection调用Http/Https接口

    HttpURLConnection是JDK自身提供的网络类,不需要引入额外的jar包.文中所使用到的软件版本:Java 1.8.0_191. 1.服务端 参见Java调用Http接口(1)--编写服务 ...

  10. 2019 多益网络java面试笔试题 (含面试题解析)

      本人5年开发经验.18年年底开始跑路找工作,在互联网寒冬下成功拿到阿里巴巴.今日头条.多益网络等公司offer,岗位是Java后端开发,因为发展原因最终选择去了多益网络,入职一年时间了,也成为了面 ...