当前位置:网站首页>C. The third problem
C. The third problem
2022-07-06 04:15:00 【Harris-H】
C. The Third Problem( Looking for a regular )
You can find 0 , 1 0,1 0,1 The position of the cannot be changed .
And then there's watching 2 2 2.
Might as well set p 0 < p 1 p_0<p_1 p0<p1
if p 2 < p 0 p_2<p_0 p2<p0 or p 2 > p 1 p_2>p_1 p2>p1 , be p 2 p_2 p2 Position cannot be changed .
because [ p 2 , p 1 ] [p_2,p_1] [p2,p1] or [ p 0 , p 2 ] [p_0,p_2] [p0,p2] Will receive p 2 p_2 p2 Location affects .
So only p 0 < p 2 < p 1 p_0<p_2<p_1 p0<p2<p1 Satisfy .
p 2 p_2 p2 The optional cases are : p 1 − p 0 + 1 − 2 p_1-p_0+1-2 p1−p0+1−2
about p 3 p_3 p3 If it is not within the range of these three numbers, it is also fixed .
Otherwise, it can be any one in the range r − l + 1 − 3 r-l+1-3 r−l+1−3
Therefore, direct simulation is sufficient .
#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;
}
边栏推荐
- Python book learning notes - Chapter 09 section 01 create and use classes
- 2/13 review Backpack + monotonic queue variant
- Basic use of MySQL (it is recommended to read and recite the content)
- Solve the compilation problem of "c2001: line breaks in constants"
- MySql數據庫root賬戶無法遠程登陸解决辦法
- P3500 [POI2010]TES-Intelligence Test(二分&离线)
- 【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
- MySQL master-slave replication
- [adjustable delay network] development of FPGA based adjustable delay network system Verilog
- MySql数据库root账户无法远程登陆解决办法
猜你喜欢
![[tomato assistant installation]](/img/06/672a616d4fc2a43b83054eb1057628.jpg)
[tomato assistant installation]

C (XXIX) C listbox CheckedListBox Imagelist

During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input

Web components series (VII) -- life cycle of custom components

Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution

About some basic DP -- those things about coins (the basic introduction of DP)

Lombok principle and the pit of ⽤ @data and @builder at the same time

Record an excel xxE vulnerability

Ipv4中的A 、B、C类网络及子网掩码

IDEA编译JSP页面生成的class文件路径
随机推荐
Hashcode and equals
Ipv4中的A 、B、C类网络及子网掩码
Database, relational database and NoSQL non relational database
Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
DM8 archive log file manual switching
2/11 matrix fast power +dp+ bisection
查询mysql数据库中各表记录数大小
Leetcode32 longest valid bracket (dynamic programming difficult problem)
About some basic DP -- those things about coins (the basic introduction of DP)
Comprehensive ability evaluation system
Interface idempotency
[Key shake elimination] development of key shake elimination module based on FPGA
What is the difference between gateway address and IP address in tcp/ip protocol?
[FPGA tutorial case 11] design and implementation of divider based on vivado core
HotSpot VM
About some basic DP -- those things about coins (the basic introduction of DP)
《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
Class A, B, C networks and subnet masks in IPv4
In depth MySQL transactions, stored procedures and triggers
Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share