yicongli

Gym 313459C

Jan 24th, 2021
489
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define gc c=getchar()
  6. #define r(x) read(x)
  7. #define ll long long
  8.  
  9. template<typename T>
  10. inline void read(T&x){
  11.     x=0;T k=1;char gc;
  12.     while(!isdigit(c)){if(c=='-')k=-1;gc;}
  13.     while(isdigit(c)){x=x*10+c-'0';gc;}x*=k;
  14. }
  15.  
  16. const int N=1e5+7;
  17.  
  18. int a[N];
  19. set<int>S;
  20.  
  21. int main(){
  22.     // freopen(".in","r",stdin);
  23.     // freopen(".out","w",stdout);
  24.     int n;r(n);
  25.     for(int i=0;i<n;++i)r(a[i]);
  26.     ll ans=0;
  27.     for(int l=0,r=0;r<n;++r){
  28.         while(S.find(a[r])!=S.end())S.erase(a[l++]);
  29.         S.insert(a[r]);
  30.         ans+=r-l+1;
  31.     }
  32.     printf("%lld\n",ans);
  33.     return 0;
  34. }
RAW Paste Data