当前位置:网站首页>Cf:c. the third problem
Cf:c. the third problem
2022-07-06 00:44:00 【White speed Dragon King's review】


analysis
This is a permutation problem
It looks fancy
Speaking of arrangement , We are going to find this arrangement 0 To n Corresponding subscript position
We have MET The definition is the smallest number except string , All strings must meet the same minimum number
therefore , We followed “ Minimum ”, From the smallest 0 Start to find the corresponding indexes one by one
First 0 I'm sure I can't change my position , secondly 1 Can't change ( Otherwise, we can always find an interval to make MET Unequal )
And then look 2 The number behind , use lr Maintain the left and right of the current index interval , And then if 2 stay lr In the words of , It has r - l + 1 - 2 A choice
If it is in the index range lr Outside , Then there must be a choice of interval that makes MET Unequal , For a better image , for instance :
+++2+++1+++0+(1)
++2++++1+++0+(2)
----+++++++++++
If we choose a line + The range of , That's obvious MET(1) > 2 and MET(2) = 2
So when we choose number k When we count , the previous lr The length of the index interval is r - l + 1
We have to id[i] It can be similar only in the index interval , At this time, the number of positions it can choose is r - l + 1 - i
use ans Just ride in tandem
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)
summary
array + Sort + Internal and external simulation
Guess a reasonable situation by excluding some situations
边栏推荐
- FPGA内部硬件结构与代码的关系
- How to use the flutter framework to develop and run small programs
- FFmpeg抓取RTSP图像进行图像分析
- notepad++正则表达式替换字符串
- [groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte
- 可恢复保险丝特性测试
- 多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
- 图解网络:TCP三次握手背后的原理,为啥两次握手不可以?
- Dynamic programming -- linear DP
- 时间戳的拓展及应用实例
猜你喜欢

猿桌派第三季开播在即,打开出海浪潮下的开发者新视野

如何制作自己的機器人

cf:H. Maximal AND【位运算练习 + k次操作 + 最大And】
![Atcoder beginer contest 258 [competition record]](/img/e4/1d34410f79851a7a81dd8f4a0b54bf.gif)
Atcoder beginer contest 258 [competition record]

State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.

How to use the flutter framework to develop and run small programs

notepad++正则表达式替换字符串
![[groovy] JSON serialization (convert class objects to JSON strings | convert using jsonbuilder | convert using jsonoutput | format JSON strings for output)](/img/52/021931181ad3f4bef271b4e98105c2.jpg)
[groovy] JSON serialization (convert class objects to JSON strings | convert using jsonbuilder | convert using jsonoutput | format JSON strings for output)

如何利用Flutter框架开发运行小程序

如何制作自己的机器人
随机推荐
【线上小工具】开发过程中会用到的线上小工具合集
The third season of ape table school is about to launch, opening a new vision for developers under the wave of going to sea
State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
MySQL storage engine
Arduino hexapod robot
DD's command
Room cannot create an SQLite connection to verify the queries
Spark DF增加一列
The relationship between FPGA internal hardware structure and code
Natural language processing (NLP) - third party Library (Toolkit):allenlp [library for building various NLP models; based on pytorch]
从 1.5 开始搭建一个微服务框架——调用链追踪 traceId
Starting from 1.5, build a micro Service Framework - call chain tracking traceid
[groovy] compile time meta programming (compile time method interception | method interception in myasttransformation visit method)
[groovy] compile time metaprogramming (compile time method interception | find the method to be intercepted in the myasttransformation visit method)
golang mqtt/stomp/nats/amqp
多线程与高并发(8)—— 从CountDownLatch总结AQS共享锁(三周年打卡)
Notepad++ regular expression replacement string
The value of applet containers
Folding and sinking sand -- weekly record of ETF
Uniapp development, packaged as H5 and deployed to the server