当前位置:网站首页>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
边栏推荐
- 新手入门深度学习 | 3-6:优化器optimizers
- Getting started with devkit
- NLP generation model 2017: Why are those in transformer
- How to make your own robot
- FPGA内部硬件结构与代码的关系
- uniapp开发,打包成H5部署到服务器
- Codeforces round 804 (Div. 2) [competition record]
- An understanding of & array names
- 小程序技术优势与产业互联网相结合的分析
- cf:D. Insert a Progression【关于数组中的插入 + 绝对值的性质 + 贪心一头一尾最值】
猜你喜欢

Browser reflow and redraw

Classic CTF topic about FTP protocol
![[groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte](/img/61/73becfc3b46669d31b0cf334aa54f2.jpg)
[groovy] compile time meta programming (AST syntax tree conversion with annotations | define annotations and use groovyasttransformationclass to indicate ast conversion interface | ast conversion inte

Common API classes and exception systems
![Go learning --- structure to map[string]interface{}](/img/e3/59caa3f2ba5bd3647bdbba075ee60d.jpg)
Go learning --- structure to map[string]interface{}

Location based mobile terminal network video exploration app system documents + foreign language translation and original text + guidance records (8 weeks) + PPT + review + project source code

MIT doctoral thesis | robust and reliable intelligent system using neural symbol learning

Free chat robot API

LeetCode 1189. Maximum number of "balloons"

MYSQL GROUP_ The concat function realizes the content merging of the same ID
随机推荐
Ffmpeg captures RTSP images for image analysis
【文件IO的简单实现】
Power query data format conversion, Split Merge extraction, delete duplicates, delete errors, transpose and reverse, perspective and reverse perspective
Basic introduction and source code analysis of webrtc threads
【EI会议分享】2022年第三届智能制造与自动化前沿国际会议(CFIMA 2022)
Classical concurrency problem: the dining problem of philosophers
Anconda download + add Tsinghua +tensorflow installation +no module named 'tensorflow' +kernelrestart: restart failed, kernel restart failed
几百行代码实现一个 JSON 解析器
Beginner redis
数据分析思维分析方法和业务知识——分析方法(二)
Idea远程提交spark任务到yarn集群
Cannot resolve symbol error
DD's command
An understanding of & array names
如何利用Flutter框架开发运行小程序
How spark gets columns in dataframe --column, $, column, apply
anconda下载+添加清华+tensorflow 安装+No module named ‘tensorflow‘+KernelRestarter: restart failed,内核重启失败
Spark SQL null value, Nan judgment and processing
notepad++正則錶達式替換字符串
Pointer pointer array, array pointer