https://codeforces.com/contest/1102/problem/E

C++版本一

题解:二分

先从前往后找到每个数最先出现的位置,然后从后往前找到最后出现的位置

然后从头开始遍历,如果出现没有访问过的区间,就遍历这个区间,然后这个区间里的每个数也是会有个区间的,而且新出现的这个数的区间只可能是往后重叠,即不存在minn比当前区间的minn的小

只能往后重叠,然后正好是for循环,他的下界会一直向后扩,扩不下去了就cnt++,成为一整个区间

#include<stdio.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<queue>
#define ll long long
#define pb push_back
#define test printf("here!!!")
using namespace std;
const int mx=2e5+10;
const int mod=998244353;
int a[mx];
int b[mx];
int vis[mx];
struct Node
{int minn;int maxn;
}num[mx];
int main()
{ll res=1;int ans=0;int n;scanf("%d",&n);for (int i=1;i<=n;++i){scanf("%d",&a[i]);b[i]=a[i];}sort(b+1,b+n+1);int cnt=unique(b+1,b+n+1)-b-1;for (int i=1;i<=n;++i){int p=lower_bound(b+1,b+cnt+1,a[i])-b;if (num[p].minn==0){num[p].minn=i;}}for (int i=n;i>=1;--i){int p=lower_bound(b+1,b+cnt+1,a[i])-b;if (num[p].maxn==0){num[p].maxn=i;}}for (int i=1;i<=n;++i){int p=lower_bound(b+1,b+cnt+1,a[i])-b;if (!vis[p]){vis[p]=1;for (int j=num[p].minn+1;j<num[p].maxn;++j){int k=lower_bound(b+1,b+cnt+1,a[j])-b;vis[k]=1;num[p].maxn=max(num[p].maxn,num[k].maxn);}ans++;}}for (int i=2;i<=ans;++i){res=res*2%mod;}printf("%I64d\n",res);
}

C++版本二

题解:记录每个元素的最大下标。

如果最大下标等于i那么cnt++;

每个元素的最小下标和最大下标之间必须一样所以,取前缀最大值

/*
*@Author:   STZG
*@Language: C++
*/
#include <bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<list>
#include<map>
#include<set>
//#define DEBUG
#define RI register int
using namespace std;
typedef long long ll;
//typedef __int128 lll;
const int N=200000+10;
const int MOD=998244353;
const double PI = acos(-1.0);
const double EXP = 1E-8;
const int INF = 0x3f3f3f3f;
int t,n,m,k,q;
int ans,cnt,flag,temp;
int a[N];
int b[N];
char str;
map<int,int>p;
ll poww(ll a, ll b) {ll ans = 1, base = a;while (b) {if (b & 1)ans = ans*base%MOD;base = base*base%MOD;b >>= 1;}return ans;
}
int main()
{
#ifdef DEBUGfreopen("input.in", "r", stdin);//freopen("output.out", "w", stdout);
#endifscanf("%d",&n);//scanf("%d",&t);//while(t--){}for(int i=1;i<=n;i++){scanf("%d",&a[i]);p[a[i]]=i;}int pos=1;int cnt=0;for(int i=1;i<=n;i++){pos=max(pos,p[a[i]]);if(pos==i)cnt++;}//ans=max(cnt,ans);cout << poww(2,cnt-1) << endl;//cout << "Hello world!" << endl;return 0;
}

Monotonic Renumeration相关推荐

  1. 补题Codeforces 1102E. Monotonic Renumeration

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

  2. [转][Timer学习]wall time和monotonic time

    在一些系统调用中需要指定时间是用CLOCK_MONOTONIC还是CLOCK_REALTIME,以前总是搞不太清楚它们之间的差别,现在终于有所理解了. CLOCK_MONOTONIC是monotoni ...

  3. 单调队列 Monotonic Queue / 单调栈 Monotonic Stack

    2018-11-16 22:45:48 一.单调队列 Monotone Queue 239. Sliding Window Maximum 问题描述: 问题求解: 本题是一个经典的可以使用双端队列或者 ...

  4. 2019牛客多校Monotonic Matrix

    Monotonic Matrix 题意: 问有多少个n * m的矩阵A满足一下情况:答案mod 1e9+7 矩阵A的所有元素∈{0,1,2} Ai,j<=Ai+1,jA_{i,j}<=A_ ...

  5. C#LeetCode刷题之#896-单调数列(Monotonic Array)

    问题 该文章的最新版本已迁移至个人博客[比特飞],单击链接 https://www.byteflying.com/archives/3760 访问. 如果数组是单调递增或单调递减的,那么它是单调的. ...

  6. [基础论文阅读]QMIX: Monotonic Value Function Factorization for Deep Multi-agent Reinforcement Learning

    [基础论文阅读]QMIX: Monotonic Value Function Factorization for Deep Multi-agent Reinforcement Learning 题目含 ...

  7. monotonic queue 单调队列

    index > Data Structures > monotonic queue 引子 POJ 2823 - Sliding Window,对一个长度为 n n n的数组,求每个长度为 ...

  8. “蔚来杯“2022牛客暑期多校训练营2 G.[Link with Monotonic Subsequence] 分块构造

    G. Link with Monotonic Subsequence 构造 题目分析 要求构造一个长度为 n n n的序列,使得序列的 max ⁡ ( lis ( p ) , lds ( p ) ) ...

  9. linux 系统时间编程(1) wall time和monotonic time科普

    在一些系统调用中需要指定时间是用CLOCK_MONOTONIC还是CLOCK_REALTIME,以前总是搞不太清楚它们之间的差别,现在终于有所理解了. CLOCK_MONOTONIC是monotoni ...

最新文章

  1. 南大算法设计与分析课程OJ答案代码(5)--割点与桥和任务调度问题
  2. 怎么样MyEclipse配置Tomcat?
  3. python基础知识点整理-Python知识点整理(day1)
  4. 中国水务行业运行状况调研与投资前景规划预测报告2022-2027年新版
  5. vc6.0 matlab混合编程,matlab2010 + vc6.0混合编程实例(调用dll)
  6. svn服务器如何扫描文件,基于文件仓库进行建模协作(EA+SVN)
  7. 乱码 讯飞 语音识别_一段讯飞、百度等语音识别API无法识别的语音最终解决办法...
  8. HDU 6178 Monkeys
  9. stylegan2-pytorch 自己训练的model 出错
  10. auto_ptr个人用
  11. win7系统蓝屏修复工具如何使用
  12. WIFI实践入门--基本命令--iwconfig
  13. html边界填充边框,CSS边界与填充
  14. An unhandled exception occurred: listen EADDRNOTAVAIL: address not available
  15. 支付业务与技术架构学习总结(7)——从金融牌照(三方支付牌照),看互联网巨头的金融布局
  16. matlab simulink入门:搭建一个简单的电路
  17. 思科 mds 虚拟服务器,保护、扩展、简化,思科MDS9000系列交换机,刷新存储网络新标准!...
  18. cortex m3 开源_开源增强现实耳机,Steam的125M有效帐户等
  19. 个人电子邮箱怎么填写?电子邮箱格式怎么写?
  20. 用exec()函数执行新程序

热门文章

  1. esxi 7.0 封装瑞昱网卡驱动_小科普 | 无线网卡怎么选?
  2. Java迭代器中的next()方法
  3. 计算机io工作方式,QEMU/KVM和VirtIO工作模式
  4. pythonqt库_Python QT组件库qtwidgets的使用
  5. 呼和浩特 计算机编程入门先学什么,学好UG编程先学什么?应该先弄懂这些问题...
  6. ddr传输 pl ps_Vitis ZYNQ开发秘籍 PS 端任意控制 VGA 显示画面最终实现
  7. 51 java_51javacms
  8. 无锡锡东2021高考成绩查询,2021年无锡高考成绩查询网址,无锡高考成绩查询系统时间安排...
  9. 【推荐系统】基于用户的协同过滤算法
  10. 五十二、Java连接Mysql数据库