感觉就按照题目的要求一步一步走就行,也没用什么数据结构 import sys [n,m,q] = list(map(int, sys.stdin.readline().strip().split())) tmp = list(sys.stdin.readline().strip().split()) path = [] for i in tmp:     if i.isdigit():         path.append(int(i))     else:         path.append(i) for _ in range(q):     # 读取每一行     line = sys.stdin.readline().strip()     # 把每一行的数字分隔后转化成int列表     [l, r] = list(map(int, line.split()))     valid = path[l-1: r]     curr = 0     mark = 0     # 1: left, 0: right     orient = 1     # 上一个是'<'或'>'     flag = 0     while curr >= 0 and curr < len(valid):         if valid[curr] == '>':             if flag:                 valid.pop(curr)                 if orient:                     curr = curr                 else:                     curr -= 1             else:                 orient = 1                 curr += 1                 flag = 1         elif valid[curr] == '<':             if flag:                 valid.pop(curr)                 if orient:                     curr = curr                 else:                     curr -= 1             else:                 orient = 0                 curr -= 1                 flag = 1         elif valid[curr] == 0:             valid.pop(curr)             if orient:                 curr = curr             else:                 curr -= 1         else:             mark += valid[curr]             valid[curr] -= 1             flag = 0             if orient:                 curr += 1             else:                 curr -= 1     print(mark)
点赞 1

相关推荐

无情咸鱼王的秋招日记之薛定谔的Offer:好拒信,偷了,希望有机会用到
点赞 评论 收藏
分享
牛客网
牛客企业服务