当前位置:网站首页>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;
}
边栏推荐
- Stc8h development (XII): I2C drive AT24C08, at24c32 series EEPROM storage
- 自动化测试的好处
- 记一次excel XXE漏洞
- hashlimit速率控制
- Class A, B, C networks and subnet masks in IPv4
- 《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
- 【按鍵消抖】基於FPGA的按鍵消抖模塊開發
- Leetcode32 longest valid bracket (dynamic programming difficult problem)
- Explain in simple terms node template parsing error escape is not a function
- The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
猜你喜欢
Basic use of MySQL (it is recommended to read and recite the content)
Cf464e the classic problem [shortest path, chairman tree]
Figure application details
记一次excel XXE漏洞
[Zhao Yuqiang] deploy kubernetes cluster with binary package
Lombok原理和同时使⽤@Data和@Builder 的坑
Path of class file generated by idea compiling JSP page
Overturn your cognition? The nature of get and post requests
食品行业仓储条码管理系统解决方案
How many of the 10 most common examples of istio traffic management do you know?
随机推荐
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
MySql數據庫root賬戶無法遠程登陸解决辦法
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
Database, relational database and NoSQL non relational database
Global and Chinese markets for fire resistant conveyor belts 2022-2028: Research Report on technology, participants, trends, market size and share
Overturn your cognition? The nature of get and post requests
C (thirty) C combobox listview TreeView
【按键消抖】基于FPGA的按键消抖模块开发
Lora gateway Ethernet transmission
Custom event of C (31)
DM8 backup set deletion
Hashcode and equals
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
自动化测试的好处
绑定在游戏对象上的脚本的执行顺序
Chinese brand hybrid technology: there is no best technical route, only better products