当前位置:网站首页>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)
总结
排列 + 排序 + 区间内外模拟
通过排除一些情况从而猜测合理的情况
边栏推荐
- Go learning --- read INI file
- 如何制作自己的機器人
- Room cannot create an SQLite connection to verify the queries
- Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
- Notepad++ regular expression replacement string
- Promise
- MySQL存储引擎
- Multithreading and high concurrency (8) -- summarize AQS shared lock from countdownlatch (punch in for the third anniversary)
- Intensive learning weekly, issue 52: depth cuprl, distspectrl & double deep q-network
- LeetCode 斐波那契序列
猜你喜欢
Common API classes and exception systems
Go learning - dependency injection
Arduino六足机器人
如何制作自己的機器人
Model analysis of establishment time and holding time
Extracting profile data from profile measurement
KDD 2022 | EEG AI helps diagnose epilepsy
[groovy] XML serialization (use markupbuilder to generate XML data | set XML tag content | set XML tag attributes)
How to use the flutter framework to develop and run small programs
LeetCode 1598. Folder operation log collector
随机推荐
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
Global and Chinese market of valve institutions 2022-2028: Research Report on technology, participants, trends, market size and share
Curlpost PHP
Model analysis of establishment time and holding time
Global and Chinese markets for pressure and temperature sensors 2022-2028: Research Report on technology, participants, trends, market size and share
MCU通过UART实现OTA在线升级流程
[Chongqing Guangdong education] Chongqing Engineering Vocational and Technical College
常用API类及异常体系
OpenCV经典100题
Introduction of motor
LeetCode 1189. Maximum number of "balloons"
Single source shortest path exercise (I)
State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
Comment faire votre propre robot
Illustrated network: the principle behind TCP three-time handshake, why can't two-time handshake?
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
Spark SQL UDF function
Uniapp development, packaged as H5 and deployed to the server
时间戳的拓展及应用实例
Starting from 1.5, build a micro Service Framework - call chain tracking traceid