Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define ll long long
- #define _test int _TEST; cin>>_TEST; while(_TEST--)
- int main()
- {
- _test
- {
- int n;
- cin>>n;
- vector<int> a(n);
- for(auto &e: a) cin>>e;
- vector<int> f(n), l(n);
- map<int, int> mp;
- for(int i=0; i<n; i++)
- {
- if(!mp[a[i]])
- f[i] = 1;
- mp[a[i]] = 1;
- }
- mp.clear();
- for(int i=n-1; i>=0; i--)
- {
- if(!mp[a[i]])
- l[i] = 1;
- mp[a[i]] = 1;
- }
- ll int cnt = 0;
- ll int ans = 0;
- for(int i=0; i<n; i++)
- {
- cnt += f[i];
- ans += l[i]*1ll*cnt;
- }
- cout<<ans<<"\n";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment