Submission #70429392


Source Code Expand

#include <bits/stdc++.h>
using namespace std;

// // Optional: Policy-based DS (comment to disable)
// #include <ext/pb_ds/assoc_container.hpp>
// using namespace __gnu_pbds;
// template<typename T>
// using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;


// // Optional: File I/O
// ifstream input_file("input.txt");
// ofstream output_file("output.txt");
// #define cin input_file
// #define cout output_file

// -------------------- Type Aliases --------------------
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

// -------------------- Macros --------------------
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define pb push_back
#define eb emplace_back
#define ff first
#define ss second
#define endl '\n'
#define SUM(v) accumulate(all(v), 0LL)
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))

// -------------------- Constants --------------------
constexpr ll INF = 1e18;
constexpr ll MOD = 1e9 + 7;
constexpr int MAXN = 2e5 + 5;

// -------------------- Overloads --------------------
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (const auto& x : v) os << x << ' ';
    return os;
}

template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& x : v) is >> x;
    return is;
}

template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    return os << '(' << p.ff << ", " << p.ss << ')';
}

template<typename T>
ostream& operator<<(ostream& os, const set<T>& s) {
    for (auto& x : s) os << x << ' ';
    return os;
}

template<typename K, typename V>
ostream& operator<<(ostream& os, const map<K, V>& m) {
    for (auto& [k, v] : m) os << '{' << k << ": " << v << "} ";
    return os;
}

template<typename T>
ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
    for (const auto& row : v) {
        for (const auto& val : row) os << val << ' ';
        os << '\n';
    }
    return os;
}

template<typename T>
istream& operator>>(istream& is, vector<vector<T>>& v) {
    for (auto& row : v)
        for (auto& val : row)
            is >> val;
    return is;
}


// -------------------- Debug (Optional) --------------------
/*
#define dbg(x) cerr << #x << " = " << x << endl;
*/

// -------------------- Math Utilities --------------------
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll mod_add(ll a, ll b, ll m = MOD) { return (a + b) % m; }
ll mod_sub(ll a, ll b, ll m = MOD) { return (a - b + m) % m; }
ll mod_mul(ll a, ll b, ll m = MOD) { return (a * b) % m; }

ll mod_pow(ll base, ll exp, ll m = MOD) {
    ll res = 1;
    base %= m;
    while (exp > 0) {
        if (exp & 1) res = mod_mul(res, base, m);
        base = mod_mul(base, base, m);
        exp >>= 1;
    }
    return res;
}

ll mod_inv(ll a, ll m = MOD) {
    return mod_pow(a, m - 2, m); // Fermat (MOD must be prime)
}

// -------------------- Grid Directions --------------------
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
// or use: {{0,1},{1,0},{0,-1},{-1,0}} for 2D

// -------------------- Comparators --------------------
auto desc = [](auto a, auto b) { return a > b; };

// -------------------- Solver --------------------
void solve() {
    ll n; cin>>n;
    unordered_map<ll,ll> mp;
    for(ll i=0; i<n; ++i) {
        ll x; cin>>x;
        mp[x]++;
    }
    ll ans = 0;
    for(auto& [x,y] : mp) {
        if(y >= 2) {
            ans += (((y*(y-1)) / 2) * (n - y));
        }
    }
    cout<<ans<<endl;
}

// -------------------- Main --------------------
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;
    for (int tc = 1; tc <= t; ++tc) {
        // cout << "Case #" << tc << ": ";
        solve();
    }

    return 0;
}

Submission Info

Submission Time
Task C - Odd One Subsequence
User yalrnr
Language C++ 20 (gcc 12.2)
Score 300
Code Size 4137 Byte
Status AC
Exec Time 31 ms
Memory 12572 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 2
AC × 28
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3552 KiB
example_01.txt AC 1 ms 3420 KiB
hand_00.txt AC 31 ms 12572 KiB
hand_01.txt AC 9 ms 3488 KiB
hand_02.txt AC 8 ms 3532 KiB
hand_03.txt AC 1 ms 3484 KiB
hand_04.txt AC 1 ms 3500 KiB
hand_05.txt AC 10 ms 3500 KiB
random_00.txt AC 28 ms 8304 KiB
random_01.txt AC 29 ms 8312 KiB
random_02.txt AC 29 ms 8264 KiB
random_03.txt AC 30 ms 8252 KiB
random_04.txt AC 29 ms 8256 KiB
random_05.txt AC 13 ms 4132 KiB
random_06.txt AC 13 ms 4072 KiB
random_07.txt AC 13 ms 4028 KiB
random_08.txt AC 12 ms 4136 KiB
random_09.txt AC 13 ms 4120 KiB
random_10.txt AC 8 ms 3464 KiB
random_11.txt AC 8 ms 3512 KiB
random_12.txt AC 9 ms 3644 KiB
random_13.txt AC 8 ms 3512 KiB
random_14.txt AC 8 ms 3448 KiB
random_15.txt AC 7 ms 3500 KiB
random_16.txt AC 7 ms 3624 KiB
random_17.txt AC 7 ms 3436 KiB
random_18.txt AC 7 ms 3432 KiB
random_19.txt AC 7 ms 3556 KiB