-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest.cpp
46 lines (43 loc) · 844 Bytes
/
Test.cpp
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include<bits/stdc++.h>
using namespace std;
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define ull unsigned long long
ull solve (){
ull n;
cin >> n;
ull a[n];
ull suf[n];
set <ull> s;
forn(i, n){
cin >> a[i];
}
ull count = 0;
forn(i, n){
if(s.find(a[n-1-i]) == s.end()){
s.insert(a[n-1-i]);
++count;
}
suf[n-1-i]=count;
}
s.clear();
ull result = 0;
forn(i, n){
if(s.find(a[i]) == s.end()){
s.insert(a[i]);
result += suf[i];
}
}
return result;
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
ull t, n;
cin >> t;
while(t--) {
cout << solve() << "\n";
}
return 0;
}