当前位置:   article > 正文

线段覆盖问题_ai 线段被覆盖了

ai 线段被覆盖了

E. Monotonic Renumeration

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

You are given an array aa consisting of nn integers. Let's denote monotonic renumeration of array aa as an array bb consisting of nn integers such that all of the following conditions are met:

  • b1=0b1=0;
  • for every pair of indices ii and jj such that 1≤i,j≤n1≤i,j≤n, if ai=ajai=aj, then bi=bjbi=bj (note that if ai≠ajai≠aj, it is still possible that bi=bjbi=bj);
  • for every index i∈[1,n−1]i∈[1,n−1] either bi=bi+1bi=bi+1 or bi+1=bi+1bi+1=bi+1.

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

Your task is to calculate the number of different monotonic renumerations of aa. The answer may be large, so print it modulo 998244353998244353.

Input

The first line contains one integer nn (2≤n≤2⋅1052≤n≤2⋅105) — the number of elements in aa.

The second line contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109).

Output

Print one integer — the number of different monotonic renumerations of aa, taken modulo 998244353998244353.

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

大致题意:

     当i = j,a[i] = a[j]时,i---j之间的数相同,若a[i] != a[j],a[j] = a[i] 或 a[j] = a[i] + 1

    例如 1 2 1 2 3   则 b 可能为 0 0 0 0 0,或 0 0 0 0 1

    1 100 b可能为  0 0 或 0 1

求的是b的方案数

  1. //此题意是统计方案数
  2. // 由于当a出现间断点时,b要么不变要么+1
  3. // 所以每当出现间断点总数就要*2
  4. # include <iostream>
  5. # include <algorithm>
  6. # include <cstring>
  7. # include <math.h>
  8. # include <stdio.h>
  9. # include <vector>
  10. # include <map>
  11. using namespace std;
  12. const int mod = 998244353;
  13. map<int,int> mmp;//映射
  14. int main(){
  15. int n;
  16. cin >> n;
  17. int num[200100];
  18. int f = 0;
  19. for(int i = 1; i <= n; i++){
  20. cin >> num[i];
  21. mmp[num[i]] = i;//统计这个数最后出现的位置
  22. }
  23. int flag = 1; //flag 用来统计是否交叉
  24. int tot = 1; //tot 用来统计总方案数
  25. for(int i = 1; i <= n; i++){
  26. if(flag >= i){//出现中断
  27. flag = max(flag , mmp[num[i]]);//flag推到这个点的最后出现位置
  28. }
  29. //因为a[1] 规定为 0,所以它不在间断点
  30. else{//不在间断点
  31. tot = tot * 2 % mod;//统计方案数
  32. flag = max(flag , mmp[num[i]]); // 同理
  33. }
  34. }
  35. cout << tot << endl;
  36. return 0;
  37. }

 

 

 

本文内容由网友自发贡献,转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/745309
推荐阅读
相关标签
  

闽ICP备14008679号