From 0ec24478f108dd02e09cada99cdc29ab77270f59 Mon Sep 17 00:00:00 2001 From: sangge-rockpi <2251250136@qq.com> Date: Sun, 14 Jan 2024 02:35:28 +0800 Subject: [PATCH] maybe has method 2? --- luogu/P2866.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/luogu/P2866.py b/luogu/P2866.py index 0c501f4..0f81b6b 100644 --- a/luogu/P2866.py +++ b/luogu/P2866.py @@ -1,6 +1,11 @@ N = int(input()) length = [int(input()) for i in range(N)] +# N <= 8 * 10**4, length <= 10**9 + +# method 1, has some time exceeded + +""" sum = 0 for i in range(N): @@ -9,6 +14,17 @@ for i in range(N): sum += 1 elif length[i] <= length[j]: break +""" +# method 2 + +sum = 0 +i = 0 +while i < N: + for j in range(i + 1, N): + if length[i] > length[j]: + sum += 1 + elif length[i] <= length[j]: + # maybe something here? + break print(sum) -