当前位置:网站首页>Codeforces Round #804 C The Third Problem
Codeforces Round #804 C The Third Problem
2022-07-18 09:24:00 【Chasing the beacon】
https://codeforces.com/contest/1699/problem/C
label
Array operation
The question
Given 0 To n-1 Permutation a.
Definition MEX( a[l -> r] ) Why not a[l -> r] The smallest nonnegative integer that appears in .
If to any 1 <= l <= r <=n, MEX( a[l -> r] ) = MEX( b[l -> r] ) Hang up , said a And b be similar .
Find out how many different permutations there are b And a be similar . The answer is right 1e9 + 7 modulus .
Ideas
First 0 The position cannot be changed , Because of this position mex by 1. Then consider 1 The location of , be in 1 Those numbers in the middle have certain freedom , and 1 It's fixed .
We reached enumeration from childhood to maintain an interval [l,r], If a number is not in the interval , It means that the position of this number cannot be changed , We extend the interval to the position of this number as the boundary . If a number is in an interval , It shows that it can be placed at any free position in the interval . Let's record how many free positions there are in the interval , Each time you encounter such a number, multiply the answer by the number of free positions .
Code

#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
using namespace std;
#define ll long long
const int N = 1e5+7;
const ll p = 1e9+7;
int f[N],g[N];//g yes f The inverse function of
signed main(){
cin.tie(0)->sync_with_stdio(0);
int T;cin>>T;
while(T--){
int n;cin>>n;
FOR(i,0,n-1) {
cin>>f[i];g[f[i]]=i;}
ll l,r,ans=1;
l=r=g[0];
FOR(i,0,n-1){
if(g[i]<l) l=g[i];
if(r<g[i]) r=g[i];
if(l<g[i] and g[i]<r) ans=ans*(r-l+1-i)%p;
cout<<l<<" "<<r<<endl;
}
cout<<ans<<endl;
}
return 0;
}
边栏推荐
- Codeforces Round #804 B Almost Ternary Matrix
- apache配置
- VS2019+CUDA11.1新建项目里没有CUDA选项
- 迪赛智慧数——折(渐变堆叠图):全国居民人均可支配收入
- go环境安装
- Codeforces Round #804 A The Third Three Number Problem
- 【开源可信隐私计算框架 “隐语”】蚂蚁宣布面向全球开发者正式开源
- Unity Shader——CGInclude文件cginc
- Codeforces Round #802 B. Palindromic Numbers
- Win11系统保护怎么关闭?Win11系统保护关闭方法
猜你喜欢

AIRIOT答疑第4期|如何使用数据分析引擎?

电商爬虫API全面详解

成长一夏 挑战赛|跟大佬学习 / 创作,得CSDN大礼包、专属荣誉证书、纪念T恤和勋章!

KingbaseES V8R6 ksql 关闭自动提交

安装CUDA失败的情况nsight visual studio edition失败

设计稳定的微服务系统时不得不考虑的场景

卸载CUDA11.1

Codeforces Round #802 C. Helping the Nature

CVPR 2022 | 提高小数据集利用效率,复旦等提出分层级联ViT网络

Massive remote sensing data processing and the practical application of GEE cloud computing technology
随机推荐
Codeforces Round #803 (Div. 2) C. 3SUM Closure
华泰证券开户,真的安全吗?
Airiot q.4 | Comment utiliser le moteur d'analyse des données?
华泰证券网上开户安全吗?资金有保障吗?
Win11系统.NET Framework 3.5怎么启用?
小目标检测1_Focal loss
Codeforces Round #805 A - G
信息检索顶会SIGIR2022最佳论文奖出炉,墨尔本理工大学最佳论文,UMass大学等最佳短论文
Research on Key Technologies of asset detection in Cyberspace
Codeforces Round #806 (Div. 4) A - G
exness:原油止跌反弹,晚间关注美国恐怖数据表现
华为云Stack南向开放框架,帮助生态伙伴高效入云
增额终身寿险收益怎么样?可以当养老理财产品吗?
腾势全新豪华中大型MPV曝光,安全、舒适一个不落
ACL 2022 | 基于阅读理解的论点对抽取
推荐系统究竟是什么?
【MT2126】 数字游戏
Creativity of project-based learning in children's programming
浅析电子签章应用安全与技术
Realize effective robot education and training management mode