跳到正文

题解

[ARC162A] Ekiden Race题解

Sammy_prime约 1 分钟
原文
文章信息与版本

文章信息

发布
2023年10月4日
收录
2026年10月5日
更新
2026年11月14日
篇幅
约 1 分钟
获赞
4

版本

  1. v1当前

AT_arc162_a

思路

根据提供的描述,对于 ii,如果存在某个 i<ji < j,使得 Pi>PjP_i > P_j,那么 jj 在回程途中超过了 ii,因此 ii 肯定不能获得回程将。所以答案就是 PP 的的后缀最小元素的个数。 这种算法的时间复杂度是 O(N)O(N)。

代码

C++
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int t,n,p[N]; 
int main(){
	freopen("race.in","r",stdin);
	freopen("race.out","w",stdout);
	scanf("%d",&t);
	while(t--){
		int ans=0,mn=N;
		scanf("%d",&n);
		for(int i=1;i<=n;++i) scanf("%d",p+i);
		for(int i=n;i>0;--i)
			if(p[i]<mn) ans++,mn=p[i];
		printf("%d\n",ans);
	}
	return 0;
}
原文