QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#121436 | #5642. DA-Sort | kaitlinz | 100 ✓ | 17ms | 8216kb | Python3 | 736b | 2023-07-08 06:41:34 | 2023-07-08 06:41:36 |
Judging History
answer
def ceiling_division(n, d):
q, r = divmod(n, d)
return q + bool(r)
def solve(arr):
stack = []
minNotInStack = float("inf");
for i in arr:
if(i > minNotInStack):
continue
while(len(stack) > 0 and stack[-1] > i ):
minNotInStack = min(minNotInStack, stack.pop())
stack.append(i)
#print(stack)
return len(arr) - len(stack)
setNum = int(input())
for i in range(setNum):
probNum, elems = [int(x) for x in input().split()]
arr = []
for j in range(ceiling_division(elems, 10)):
arr += [int(x) for x in input().split()]
#print(sorted(arr))
#print(arr)
print(probNum, solve(arr))
详细
Test #1:
score: 100
Accepted
time: 17ms
memory: 8216kb
input:
50 1 3 1 3 2 2 6 1 5 2 4 3 6 3 23 67890 56312 999999999 12345 23456 38927 45632 100345 98765 23456 87654 43278 23456 117654 321899 25432 54326 217435 26845 31782 33456 41234 56213 4 1000 18780 15256 15263 15268 15269 15274 15279 15279 15283 15290 15292 15292 15295 15298 15302 15305 15305 15311 15316...
output:
1 1 2 3 3 15 4 1 5 0 6 0 7 0 8 0 9 999 10 1 11 500 12 2 13 299 14 159 15 36 16 564 17 94 18 0 19 140 20 438 21 182 22 364 23 364 24 45 25 147 26 16 27 66 28 85 29 406 30 325 31 564 32 268 33 9 34 248 35 524 36 335 37 498 38 43 39 392 40 589 41 157 42 148 43 41 44 576 45 177 46 332 47 187 48 22 49 99...
result:
ok 50 lines