【Codeforces 1102E】Monotonic Renumeration
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
会发现如果a[i]=a[j]
那么b[i]~b[j]都是相同的,等于b[i]
而b[i]等于b[i-1]+1或者b[i]
有两种可能
所以对于两个相同的a[i]之间的区间。
只要在区间开始的时候乘个2就行。
如果不在任何一起相等的区间里面的话也乘个2就行,因为每个数字都有两种可能。
这道题只要记录下=a[i]的最大下标就好.
这样 在遇到一个a[i]的时候,就获取 =a[i]的最大下标j。
显然i~j是这个区间的最大范围。
只要是这个范围的b[i],显然都是相同的。
看代码可能更容易懂。
【代码】
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5;
const ll MOD = 998244353;
int n;
int a[N+10];
map<int,int> dic;
ll ans = 1;
int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n;
for (int i = 1;i <= n;i++) {
cin >> a[i];
dic[a[i]] = max(dic[a[i]],i);
}
int ma = dic[a[1]];
for (int i = 2;i <= n;i++){
if (i>ma){//不在任何一个a[i]相等的区间(最长)里面
ans = ans*2%MOD;
}
ma = max(ma,dic[a[i]]);
}
cout<<ans<<endl;
return 0;
}
【Codeforces 1102E】Monotonic Renumeration的更多相关文章
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- 【codeforces 707E】Garlands
[题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...
- 【codeforces 707C】Pythagorean Triples
[题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...
- 【codeforces 709D】Recover the String
[题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...
- 【codeforces 709B】Checkpoints
[题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...
- 【codeforces 709C】Letters Cyclic Shift
[题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...
- 【Codeforces 429D】 Tricky Function
[题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...
- 【Codeforces 670C】 Cinema
[题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...
- 【codeforces 515D】Drazil and Tiles
[题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...
随机推荐
- E20171106-hm
pulldown adj. 折叠式的; pulldown menu 下拉菜单
- [App Store Connect帮助]六、测试 Beta 版本(1)TestFlight Beta 版测试概述(iOS、Apple TVOS、watchOS)
TestFlight Beta 版测试让您可以分发您 App 的 Beta 版构建版本给测试员并收集反馈.您可以在您的 App Store Connect 帐户中一次为至多 100 个 App 启用 ...
- PROTEUS快捷键与部分知识点
缩放 有以下几种方法对原理图进行缩放: 移动鼠标需要所放的地方,滚动鼠标滑轮进行缩放. 移动师表需要缩放的地方,按键盘F6放大,F7缩小 按下ShIFT键,鼠标左键拖拽出需要放大的区域,这叫SHIFT ...
- redis在linux环境下的安装与启动
定义 redis是一个key-value存储系统.和Memcached类似,它支持存储的value类型相对更多,包括string(字符串).list(链表).set(集合).zset(sorted s ...
- 300 Longest Increasing Subsequence 最长上升子序列
给出一个无序的整形数组,找到最长上升子序列的长度.例如,给出 [10, 9, 2, 5, 3, 7, 101, 18],最长的上升子序列是 [2, 3, 7, 101],因此它的长度是4.因为可能会有 ...
- Vue组件之间通信的三种方式
最近在看梁颠编著的<Vue.js实战>一书,感觉颇有收获,特此记录一些比价实用的技巧. 组件是MVVM框架的核心设计思想,将各功能点组件化更利于我们在项目中复用,这类似于我们服务端面向对象 ...
- LN : leetcode 217 Contains Duplicate
lc 217 Contains Duplicate 217 Contains Duplicate Given an array of integers, find if the array conta ...
- HTML城市联动
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Android中出现Error:In (declare-styleable) FontFamilyFont, unable to find attribute android:font
Android中出现Error:In (declare-styleable) FontFamilyFont, unable to find attribute android:font 解决办法,今天 ...
- linux下启动、停止tomcat,杀死tomcat进程
1.打开终端 cd /java/tomcat 2.执行 bin/startup.sh #启动tomcat bin/shutdown.sh #停止tomcat tail -f logs/catalina ...