forked from encrypted-def/basic-algo-lecture
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path13144.cpp
More file actions
30 lines (27 loc) · 677 Bytes
/
13144.cpp
File metadata and controls
30 lines (27 loc) · 677 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
// Authored by : heheHwang
// Co-authored by : BaaaaaaaaaaarkingDog
// http://boj.kr/20b3510ea5384c78a6e1c34aae40b267
#include <bits/stdc++.h>
using namespace std;
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
cin >> n;
vector<int> arr(n);
vector<bool> chk(100'002);
for (int i = 0; i < n; i++) cin >> arr[i];
long long ans = 0;
chk[arr[0]] = 1;
int en = 0;
for(int st = 0; st < n; st++){
// en에는 arr[st] to arr[en]에 같은 수가 등장하지 않는 가장 큰 값이 저장됨
while (en < n-1 && !chk[arr[en+1]]){
en++;
chk[arr[en]] = 1;
}
ans += (en-st+1);
chk[arr[st]] = 0;
}
cout << ans;
}