Codeforces may be unavailable from November 14, 19:35 (UTC) to November 15, 00:35 (UTC) due to technical maintenance. ×

 
 
 
 
General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
232780368 Practice:
arpitkus
1883F - 10 GNU C++20 (64) Accepted 249 ms 8272 KB 2023-11-14 19:39:28 2023-11-14 19:39:28
→ Source
/*Faith Works
    Effort Wins
*/
#include <bits/stdc++.h>
#ifndef ONLINE_JUDGE
    #include "bug.h"
#else
#define bug(x)
#endif
using namespace std;
#define int long long
const int N = 1e5+10;
const int mod = 998244353;
#define MAX 30
int inv(int i) {if (i == 1) return 1; return (mod - ((mod / i) * inv(mod % i)) % mod) % mod;}
int mod_mul(int a, int b) {a = a % mod; b = b % mod; return (((a * b) % mod) + mod) % mod;}
/*  relax !! Exploit ALL YOUR THOUGHTS.(Don't Give Up early)
what  makes it solvable ?
*/
/*Discipline*/
void solve(){
    int n ;cin>> n;
    vector<int> v(n+1);
    for(int i = 1 ; i <= n ; i++){
        cin>>v[i];
    }
    int ans = 0;
    map<int,int> m;
    vector<int> uni(n+1);
    for(int i = n ; i>= 1 ; i--){
        m[v[i]]++;
        uni[i-1] = uni[i] + (m[v[i]] == 1);
    }
    bug(uni)
    // individual subsets
    for(auto&it:m){
        if(it.second == 1){
            ans++;
        }
    }
    // let's say i^th element be the ending point of the subsets.
    for(int i = 1 ; i<= n ; i++){
        m[v[i]]--;
        if(!m[v[i]]){
            ans+=(i-1);
        }
    }
    m.clear();
    // let's say i^th element be the starting point of the subsets.
    for(int i = 1 ; i<= n ; i++){
        if(m[v[i]]){
            ans-=(uni[i]);
        }
        m[v[i]]++;
    }
    cout << ans << '\n';
}
signed main(){
#ifndef ONLINE_JUDGE
    freopen("input1.text" , "r" , stdin);
    freopen("output1.text" , "w" , stdout);
#endif
#ifndef ONLINE_JUDGE
    freopen("debug.text" , "w" , stderr);
#endif
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t ;
    t = 1;
    cin>>t;
    for(int i = 1; i <= t ; i++){
        // cerr << "test case : " << i << '\n';
        solve();
    }
}
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details