아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Unique Values

면접 대비

시간 제한1초메모리 제한1024 MB

요약
주어진 배열에서 같은 값이 두 번 나오지 않는 연속 부분 배열의 개수를 센다.
난이도

보통10점 중 5점

유형
투 포인터, 슬라이딩 윈도우, 해시맵
정답자
아직 제출이 없습니다

문제

Arup has to make many practice questions for his Computer Science 1 students. Since many of the questions deal with arrays, he has to generate arrays for his students. Since he doesn’t want to give them difficult practice problems, he always guarantees that the arrays (given to the students) have unique values. Namely, no value will appear twice in any of his arrays.

Unfortunately, Arup is too lazy to generate arrays! About 20 years ago when he started teaching Computer Science 1, he made one really long array to reuse but this long array may have duplicate values. When he makes problems, he simply grabs a contiguous subsequence of this long array to be the array to be used for a problem but he needs to make sure the contiguous subsequence does not contain duplicates. If the long array has terms a[0], a[1], …, a[n-1], a contiguous subsequence of the long array is any sequence of j – i + 1 terms a[i], a[i+1], …, a[j] where 0 ≤ i ≤ j ≤ n – 1.

Given an array of n integers, determine how many contiguous subsequences of the array do not contain any repeated values. Note that two subsequences with the same contents are considered different (i.e., both counted in the total) if they start at different locations of the original long array.

입력

The first input line contains a single positive integer, n (1 ≤ n ≤ 105), representing the size of the input array. The following line contains n space separated integers, representing the values of the input array, in the order they appear in the array. Each of the array values will be an integer between 1 and 109, inclusive.

출력

On a line by itself, output the total number of contiguous subsequences of the input array that do not contain any repeated values.

예제2

  1. 예제 1

    입력
    5
    1 1 2 1 5
    
    예상 출력
    9
    
  2. 예제 2

    입력
    8
    2 12 3 12 3 2 6 9
    
    예상 출력
    22