当前位置:网站首页>cf:C. The Third Problem【关于排列这件事】
cf:C. The Third Problem【关于排列这件事】
2022-07-06 00:38:00 【白速龙王的回眸】


分析
这是一道排列的题
看起来花里胡哨的
说到排列,我们就要找到这个排列0到n对应的下标位置
我们这里的MET定义是除字串外最小的数,所有的字串都要满足这个最小的数相同
于是,我们遵循“最小”,从最小的0开始一个个找对应的索引
首先0的位置肯定变不了,其次1也变不了(否则总能找到一个区间使得MET不等)
然后看2后面的数,用lr维护当前索引区间的左右,然后如果2在lr中的话,它就有r - l + 1 - 2种选择
如果它在索引区间lr外,那么必定有一种区间的选择使得MET不等,为了更形象,举个例子:
+++2+++1+++0+(1)
++2++++1+++0+(2)
----+++++++++++
如果我们选上一行+的区间,那显然MET(1) > 2而 MET(2) = 2
因此当我们选第k个数的时候,上一个lr索引区间长度是r - l + 1
我们只有当id[i]在索引区间内才可以相似,这时候它能选的位置个数共有r - l + 1 - i
用ans 连乘就可以了
ac code
import sys
input = sys.stdin.readline
MOD = 10 ** 9 + 7
for _ in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
id = [0] * n
for i, v in enumerate(a):
id[v] = i
# we judge from v = 0,1,...
ans = 1
l = r = id[0]
for i in range(1, n):
# if id[i] outside [l, r], no other choice
# cause there must be a choice MET not equal
if id[i] < l or id[i] > r:
l, r = min(id[i], l), max(id[i], r)
else:
ans = ans * (r - l + 1 - i) % MOD
print(ans)
总结
排列 + 排序 + 区间内外模拟
通过排除一些情况从而猜测合理的情况
边栏推荐
- LeetCode 6006. Take out the least number of magic beans
- 图解网络:TCP三次握手背后的原理,为啥两次握手不可以?
- 新手入门深度学习 | 3-6:优化器optimizers
- OS i/o devices and device controllers
- I'm interested in watching Tiktok live beyond concert
- AtCoder Beginner Contest 254【VP记录】
- 猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
- XML配置文件
- Codeforces gr19 D (think more about why the first-hand value range is 100, JLS yyds)
- Opencv classic 100 questions
猜你喜欢
![Atcoder beginer contest 258 [competition record]](/img/e4/1d34410f79851a7a81dd8f4a0b54bf.gif)
Atcoder beginer contest 258 [competition record]
![[EI conference sharing] the Third International Conference on intelligent manufacturing and automation frontier in 2022 (cfima 2022)](/img/39/9d189a18f3f75110b400506e274391.png)
[EI conference sharing] the Third International Conference on intelligent manufacturing and automation frontier in 2022 (cfima 2022)

小程序技术优势与产业互联网相结合的分析

Spark AQE

esxi的安装和使用
![[designmode] Decorator Pattern](/img/65/457e0287383d0ca9a28703a63b4e1a.png)
[designmode] Decorator Pattern

XML配置文件

LeetCode 1598. Folder operation log collector

免费的聊天机器人API

LeetCode 1189. Maximum number of "balloons"
随机推荐
Codeforces round 804 (Div. 2) [competition record]
Introduction of motor
MySQL storage engine
《强化学习周刊》第52期:Depth-CUPRL、DistSPECTRL & Double Deep Q-Network
PHP determines whether an array contains the value of another array
2022-02-13 work record -- PHP parsing rich text
电机的简介
Common API classes and exception systems
Browser local storage
如何制作自己的機器人
Pointer - character pointer
Spark AQE
Yolov5, pychar, Anaconda environment installation
[Chongqing Guangdong education] reference materials for Zhengzhou Vocational College of finance, taxation and finance to play around the E-era
Promise
Spark-SQL UDF函数
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
Global and Chinese markets of POM plastic gears 2022-2028: Research Report on technology, participants, trends, market size and share
Anconda download + add Tsinghua +tensorflow installation +no module named 'tensorflow' +kernelrestart: restart failed, kernel restart failed
OpenCV经典100题