목차

List of Unique Numbers

ps
링크acmicpc.net/…
출처BOJ
문제 번호13144
문제명List of Unique Numbers
레벨골드 3
분류

투 포인터

시간복잡도O(n)
인풋사이즈n<=100000
사용한 언어Python
제출기록41744KB / 136ms
최고기록136ms
해결날짜2021/12/07

풀이

코드

"""Solution code for "BOJ 13144. List of Unique Numbers".

- Problem link: https://www.acmicpc.net/problem/13144
- Solution link: http://www.teferi.net/ps/problems/boj/13144

Tags: [Two Pointer]
"""


def main():
    N = int(input())  # pylint: disable=unused-variable
    nums = [int(x) for x in input().split()]

    l_iter, r_iter = iter(nums), iter(nums)
    left, right = next(l_iter), next(r_iter)
    subarr = set()
    answer = 0
    while right is not None:
        if right in subarr:
            subarr.remove(left)
            left = next(l_iter)
        else:
            subarr.add(right)
            answer += len(subarr)
            right = next(r_iter, None)

    print(answer)


if __name__ == '__main__':
    main()