Codeforces J. Monotonic Renumeration(组合)
题目描述:
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,j≤n, 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(组合)的更多相关文章
- 补题Codeforces 1102E. Monotonic Renumeration
这个题还是不太懂,下面附上的是大佬的题解(https://zhanghuimeng.github.io/post/codeforces-1102e-monotonic-renumeration/) E ...
- 【Codeforces 1102E】Monotonic Renumeration
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 会发现如果a[i]=a[j] 那么b[i]~b[j]都是相同的,等于b[i] 而b[i]等于b[i-1]+1或者b[i] 有两种可能 所以对于 ...
- 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 ...
- Codeforces 140E(排列组合、dp)
要点 主要学到的东西:一个序列染色,相邻不染同色,恰用\(j\)种颜色的1.模式数.2.方案数.3.具体染色数. 从大的思路上来讲:先dp预处理出每一层的模式数:\(f[i][j]\)表示\(i\)个 ...
- CodeForces 131C C (组合)
There are n boys and m girls attending a theatre club. To set a play "The Big Bang Theory" ...
- Codeforces 15E Triangles 【组合计数】
Codeforces 15E Triangles Last summer Peter was at his granny's in the country, when a wolf attacked ...
- Codeforces J. Sagheer and Nubian Market(二分枚举)
题目描述: Sagheer and Nubian Market time limit per test 2 seconds memory limit per test 256 megabytes in ...
- Codeforces J. Soldier and Number Game(素数筛)
题目描述: Soldier and Number Game time limit per test 3 seconds memory limit per test 256 megabytes inpu ...
- Codeforces J. A Simple Task(多棵线段树)
题目描述: Description This task is very simple. Given a string S of length n and q queries each query is ...
随机推荐
- PHP对二维数组进行排序
/** * 获取最近的店铺 * @param $lng * @param $lat * @return array */ protected function getClosestShop($lng, ...
- 以Unicode(UTF-16 LE)编码保存文本
1. 以二进制方式打开文件,写入BOM头 FILE* pFile = nullptr; _wfopen_s(&pFile, szLogFilePath, L"wb"); / ...
- sql语句修改数据库字段的长度
修改字段的长度 alter table [OtpimizeRoute_Test].[dbo].[T_QueueFile] alter column ListFileName nvarchar()
- 嵌入式02 STM32 实验11 NVIC和中断总结
一.基础知识 1.cortex-m3支持256个中断,其中包含了16个内核中断,240个外部中断 2.STM32只有84个中断,包括16个内核中断和68个可屏蔽中断 3.STM32F103上只有60个 ...
- ubuntu Docker安装部署Rancher
一.Rancher简介 Rancher是一个开源的企业级容器管理平台.通过Rancher,企业再也不必自己使用一系列的开源软件去从头搭建容器服务平台.Rancher提供了在生产环境中使用的管理Dock ...
- Js的iframe相关问题,如何判断当前是否在iframe中,iframe和它的父窗口如何通信
一.前言: 在web中,为了丰富我们的内容,往往需要引用其它HTML文件,这时候就需要用到 iframe 标签,本文就主要记录一下使用iframe所需要注意的问题 iframe 所使用的环境(笔者所遇 ...
- 转:使用Goproxy解决golang.org模块无法下载的问题
原文https://studygolang.com/articles/22277?fr=sidebar 简介 Goproxy 中国完全实现了 Go 的模块代理协议.并且它是一个由中国备受信赖的云服务提 ...
- .net Dapper 实践系列(3) ---数据显示(Layui+Ajax+Dapper+MySQL)
目录 写在前面 产生问题 解决方案 写在前面 上一小节,我们使用Dapper 里事务实现了一对多关系的添加.这一小节,主要记录如何使用Dapper 实现多表的查询显示. 产生问题 在mvc控制器中查询 ...
- 自学Python编程的第九天(希望有大牛帮我看看我第一个代码是否有弊端,感谢您们)----------来自苦逼的转行人
2019-09-19-22:11:33 今天是自学Python的第九天 学的内容是有关文件操作的,如:r.w.a.rb.wb.ab.r+.w+.a+等 有大牛帮我看一下我的代码第一个有没有什么弊端吗? ...
- 图解HTTP(二)
第四章 返回结果的HTTP状体码 1.状态码告知从服务器返回的结果 类别 原因短语 1XX Infomational信息性状态码 接收的请求正在处理中 2XX Success成功状态码 请求正常处 ...