当前位置:网站首页>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;
}
边栏推荐
- [adjustable delay network] development of FPGA based adjustable delay network system Verilog
- Interface idempotency
- asp. Core is compatible with both JWT authentication and cookies authentication
- PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
- Thread sleep, thread sleep application scenarios
- Query the number and size of records in each table in MySQL database
- About some basic DP -- those things about coins (the basic introduction of DP)
- How can programmers resist the "three poisons" of "greed, anger and ignorance"?
- P2102 地砖铺设(dfs&贪心)
- Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
猜你喜欢
Lombok principle and the pit of ⽤ @data and @builder at the same time
C (XXIX) C listbox CheckedListBox Imagelist
[FPGA tutorial case 11] design and implementation of divider based on vivado core
math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
Mysql数据库慢sql抓取与分析
Execution order of scripts bound to game objects
ESP32_ FreeRTOS_ Arduino_ 1_ Create task
绑定在游戏对象上的脚本的执行顺序
Solution to the problem that the root account of MySQL database cannot be logged in remotely
Figure application details
随机推荐
判断当天是当月的第几周
10個 Istio 流量管理 最常用的例子,你知道幾個?
Interface idempotency
SSTI template injection explanation and real problem practice
【按鍵消抖】基於FPGA的按鍵消抖模塊開發
Database, relational database and NoSQL non relational database
绑定在游戏对象上的脚本的执行顺序
Solve the compilation problem of "c2001: line breaks in constants"
Detailed explanation of serialization and deserialization
2328. 网格图中递增路径的数目(记忆化搜索)
[Key shake elimination] development of key shake elimination module based on FPGA
Basic use of MySQL (it is recommended to read and recite the content)
Viewing and verifying backup sets using dmrman
[FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
How to execute an SQL statement in MySQL
Mlapi series - 04 - network variables and network serialization [network synchronization]
Determine which week of the month the day is
Script lifecycle
C (XXIX) C listbox CheckedListBox Imagelist
Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share