当前位置:网站首页>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;
}
边栏推荐
- Execution order of scripts bound to game objects
- IDEA编译JSP页面生成的class文件路径
- E. Best Pair
- BOM - location, history, pop-up box, timing
- Scalpel like analysis of JVM -- this article takes you to peek into the secrets of JVM
- Security xxE vulnerability recurrence (XXe Lab)
- Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
- Global and Chinese markets for MRI safe implants 2022-2028: technology, participants, trends, market size and share Research Report
- 【按鍵消抖】基於FPGA的按鍵消抖模塊開發
- Query the number and size of records in each table in MySQL database
猜你喜欢

SSTI template injection explanation and real problem practice

Thread sleep, thread sleep application scenarios

Data processing methods - smote series and adasyn

电脑钉钉怎么调整声音
![[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos](/img/41/27ce3741ef29e87c0f3b954fdef87a.png)
[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos

Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
![[tomato assistant installation]](/img/06/672a616d4fc2a43b83054eb1057628.jpg)
[tomato assistant installation]

1291_ Add timestamp function in xshell log

Chinese brand hybrid technology: there is no best technical route, only better products
![[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)](/img/8a/068faf3e8de642c9e3c4118e6084aa.jpg)
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
随机推荐
Solve the compilation problem of "c2001: line breaks in constants"
Web components series (VII) -- life cycle of custom components
How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
1291_Xshell日志中增加时间戳的功能
2/13 review Backpack + monotonic queue variant
POI add border
ESP32_ FreeRTOS_ Arduino_ 1_ Create task
Mixed development of QML and QWidget (preliminary exploration)
图应用详解
2/11 matrix fast power +dp+ bisection
Chinese brand hybrid technology: there is no best technical route, only better products
Custom event of C (31)
2/13 qaq~~ greed + binary prefix sum + number theory (find the greatest common factor of multiple numbers)
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
Overturn your cognition? The nature of get and post requests
深入浅出node模板解析错误escape is not a function
TCP/IP协议里面的网关地址和ip地址有什么区别?
hashlimit速率控制
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
One question per day (Mathematics)