当前位置:网站首页>C. Inversion Graph
C. Inversion Graph
2022-06-26 15:58:00 【Honestbutter-】
C. Inversion Graph
Law 1: Monotonic stack
#include<iostream>
using namespace std;
const int N=2e5+100;
int stk[N],tt,x,top;
int main()
{
int t;
cin>>t;
while(t--)
{
tt=0;
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>x;
if(tt==0||x>stk[tt])
{
stk[++tt]=x;
}
else
{
int top=stk[tt--];
while(tt&&stk[tt]>x) tt--;
stk[++tt]=top;
}
}
cout<<tt<<endl;
}
return 0;
}
Law 2:
When traversal to a [ i ] a[i] a[i], If m a x [ 1 , i ] < m i n [ i + 1 , n ] , a n s + + max[1,i]<min[i+1,n],ans++ max[1,i]<min[i+1,n],ans++
( Like a separator , Because the front part and the back part will not be merged )
#include<iostream>
using namespace std;
const int N=2e5+100;
int a[N],lmax[N],rmin[N];
int main()
{
int t;
cin>>t;
while(t--)
{
int n; cin>>n;
int maxn=0,minn=0x3f3f3f3f;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(a[i]>maxn) maxn=a[i];
lmax[i]=maxn;
}
for(int i=n;i>=1;i--)
{
rmin[i]=minn;
if(a[i]<minn) minn=a[i];
}
int ans=0;
for(int i=1;i<=n;i++)
if(lmax[i]<rmin[i]) ans++;
cout<<ans<<endl;
}
return 0;
}
边栏推荐
- Interview pit summary I
- Svg savage animation code
- 01 backpack DP
- NFT transaction principle analysis (1)
- Stepn débutant et avancé
- Svg canvas canvas drag
- Nanopi duo2 connection WiFi
- 【leetcode】48. Rotate image
- Solana capacity expansion mechanism analysis (1): an extreme attempt to sacrifice availability for efficiency | catchervc research
- 5000 word analysis: the way of container security attack and defense in actual combat scenarios
猜你喜欢
[problem solving] the loading / downloading time of the new version of webots texture and other resource files is too long
[CEPH] Introduction to cephfs caps
Panoramic analysis of upstream, middle and downstream industrial chain of "dry goods" NFT
NFT交易原理分析(2)
A blog to thoroughly master the theory and practice of particle filter (PF) (matlab version)
11 cnn简介
Summary of data interface API used in word search and translation applications
JS creative icon navigation menu switch background color
Solana扩容机制分析(1):牺牲可用性换取高效率的极端尝试 | CatcherVC Research
反射修改final
随机推荐
Particle filter PF - 3D CV target tracking with uniform motion (particle filter vs extended Kalman filter)
Development, deployment and online process of NFT project (2)
Interview pit summary I
【leetcode】112. Path sum - 113 Path sum II
查词翻译类应用使用数据接口api总结
Unable to download Plug-in after idea local agent
NFT交易原理分析(2)
Comprehensive analysis of discord security issues
Swiftui retrieves the missing list view animation
如何辨别合约问题
NFT 项目的开发、部署、上线的流程(1)
C语言读取数据
golang 临时对象池优化
Auto Sharding Policy will apply Data Sharding policy as it failed to apply file Sharding Policy
A blog to thoroughly master the theory and practice of particle filter (PF) (matlab version)
[CEPH] Introduction to cephfs caps
现在券商的优惠开户政策是什么?现在在线开户安全么?
为什么图像分割任务中经常用到编码器和解码器结构?
AbortController的使用
手机上怎么开户?在线开户安全么?