当前位置:网站首页>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;
}
边栏推荐
- Use js to complete an LRU cache
- Mixed development of QML and QWidget (preliminary exploration)
- Redis (replicate dictionary server) cache
- [introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
- ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
- POI add border
- [disassembly] a visual air fryer. By the way, analyze the internal circuit
- IDEA编译JSP页面生成的class文件路径
- Unity中几个重要类
- Viewing and verifying backup sets using dmrman
猜你喜欢
20、 EEPROM memory (AT24C02) (similar to AD)
ESP32(基于Arduino)连接EMQX的Mqtt服务器上传信息与命令控制
【leetcode】1189. Maximum number of "balloons"
About some basic DP -- those things about coins (the basic introduction of DP)
Redis (replicate dictionary server) cache
Ipv4中的A 、B、C类网络及子网掩码
lora网关以太网传输
Proof of Stirling formula
Solution of storage bar code management system in food industry
关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
随机推荐
Recommendation system (IX) PNN model (product based neural networks)
《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
C (XXIX) C listbox CheckedListBox Imagelist
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
PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
Mlapi series - 04 - network variables and network serialization [network synchronization]
How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
MySQL master-slave replication
2328. 网格图中递增路径的数目(记忆化搜索)
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
Explain in simple terms node template parsing error escape is not a function
Determine which week of the month the day is
Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
Slow SQL fetching and analysis of MySQL database
Chinese brand hybrid technology: there is no best technical route, only better products
One question per day (Mathematics)
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
Thread sleep, thread sleep application scenarios
关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解