当前位置:网站首页>C. The Third Problem(找规律)
C. The Third Problem(找规律)
2022-07-06 04:11:00 【Harris-H】
C. The Third Problem(找规律)
可以发现 0 , 1 0,1 0,1的位置不能变。
然后是看 2 2 2。
不妨设 p 0 < p 1 p_0<p_1 p0<p1
若 p 2 < p 0 p_2<p_0 p2<p0 或 p 2 > p 1 p_2>p_1 p2>p1 ,则 p 2 p_2 p2位置不能变。
因为 [ p 2 , p 1 ] [p_2,p_1] [p2,p1]或 [ p 0 , p 2 ] [p_0,p_2] [p0,p2] 会受 p 2 p_2 p2位置影响。
因此只有 p 0 < p 2 < p 1 p_0<p_2<p_1 p0<p2<p1 满足。
p 2 p_2 p2可选的情况有: p 1 − p 0 + 1 − 2 p_1-p_0+1-2 p1−p0+1−2
对于 p 3 p_3 p3 如果不在这三个数组成的范围之内的话也是固定的。
否则可以范围内的任意一个 r − l + 1 − 3 r-l+1-3 r−l+1−3
因此直接模拟即可。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll NMAX=1e5+5,MOD=1e9+7;
ll v[NMAX],pos[NMAX];
void tc(){
ll n,l,r,ans=1;
cin>>n;
for(ll i=0;i<n;i++){
cin>>v[i];
pos[v[i]]=i;
}
l = r = pos[0];
for(ll i=1;i<n;i++){
if(pos[i]<l) l = pos[i];
else if(pos[i]>r) r = pos[i];
else ans=ans*(r-l+1-i)%MOD;
}
cout<<ans<<'\n';
}
int main()
{
ios_base::sync_with_stdio(false); cin.tie(0);
ll t;
cin>>t;
while(t--)
tc();
return 0;
}
边栏推荐
- 10 exemples les plus courants de gestion du trafic istio, que savez - vous?
- 【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
- Stack and queue
- Custom event of C (31)
- Web components series (VII) -- life cycle of custom components
- Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
- Use js to complete an LRU cache
- 51nod 1130 n factorial length V2 (Stirling approximation)
- 2/12 didn't learn anything
- MySql数据库root账户无法远程登陆解决办法
猜你喜欢

综合能力测评系统

In Net 6 CS more concise method

Simple blog system
![Mlapi series - 04 - network variables and network serialization [network synchronization]](/img/fc/aebbad5295481788de5c1fdb432a77.jpg)
Mlapi series - 04 - network variables and network serialization [network synchronization]

Lombok原理和同时使⽤@Data和@Builder 的坑

TCP/IP协议里面的网关地址和ip地址有什么区别?

《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动

Fundamentals of SQL database operation
![P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]](/img/b1/dbfc42d66548476300501dd839abef.jpg)
P7735-[noi2021] heavy and heavy edges [tree chain dissection, line segment tree]

Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
随机推荐
Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
How can programmers resist the "three poisons" of "greed, anger and ignorance"?
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
QML和QWidget混合开发(初探)
Ybtoj coloring plan [tree chain dissection, segment tree, tarjan]
IDEA编译JSP页面生成的class文件路径
[disassembly] a visual air fryer. By the way, analyze the internal circuit
Basic knowledge of binary tree, BFC, DFS
Execution order of scripts bound to game objects
How to modify field constraints (type, default, null, etc.) in a table
Mlapi series - 04 - network variables and network serialization [network synchronization]
Stable Huawei micro certification, stable Huawei cloud database service practice
Use js to complete an LRU cache
SSTI template injection explanation and real problem practice
20、 EEPROM memory (AT24C02) (similar to AD)
Stable Huawei micro certification, stable Huawei cloud database service practice
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
Viewing and verifying backup sets using dmrman