当前位置:网站首页>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
边栏推荐
- The detailed page returns to the list and retains the original position of the scroll bar
- Search (DFS and BFS)
- NLP generation model 2017: Why are those in transformer
- Opencv classic 100 questions
- Yolov5、Pycharm、Anaconda环境安装
- Idea remotely submits spark tasks to the yarn cluster
- FPGA内部硬件结构与代码的关系
- Spark SQL null value, Nan judgment and processing
- Common API classes and exception systems
- Spark DF adds a column
猜你喜欢
免费的聊天机器人API
MIT博士论文 | 使用神经符号学习的鲁棒可靠智能系统
XML Configuration File
Keepalive component cache does not take effect
Data analysis thinking analysis methods and business knowledge - analysis methods (III)
Ffmpeg captures RTSP images for image analysis
Study diary: February 13, 2022
Notepad++ regular expression replacement string
常用API类及异常体系
cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】
随机推荐
Cve-2017-11882 reappearance
STM32 key chattering elimination - entry state machine thinking
从 1.5 开始搭建一个微服务框架——调用链追踪 traceId
Solve the problem of reading Chinese garbled code in sqlserver connection database
Notepad + + regular expression replace String
看抖音直播Beyond演唱会有感
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
Keepalive component cache does not take effect
Starting from 1.5, build a micro Service Framework - call chain tracking traceid
《编程之美》读书笔记
Leetcode Fibonacci sequence
State mode design procedure: Heroes in the game can rest, defend, attack normally and attack skills according to different physical strength values.
Promise
[Online gadgets] a collection of online gadgets that will be used in the development process
Meta AI西雅图研究负责人Luke Zettlemoyer | 万亿参数后,大模型会持续增长吗?
[groovy] JSON serialization (jsonbuilder builder | generates JSON string with root node name | generates JSON string without root node name)
[groovy] JSON string deserialization (use jsonslurper to deserialize JSON strings | construct related classes according to the map set)
For a deadline, the IT fellow graduated from Tsinghua suddenly died on the toilet
MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning
Set data real-time update during MDK debug