Submission #678200

# Submission time Handle Problem Language Result Execution time Memory
678200 2023-01-05T09:49:42 Z stanislavpolyn Diversity (CEOI21_diversity) C++17
64 / 100
82 ms 11788 KB
#include <bits/stdc++.h>

#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define all(x) (x).begin(), (x).end()
#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()

using namespace std;

mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

//mt19937_64 rng(228);

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

template <typename T>
bool umn(T& a, T b) {
    return a > b ? a = b, 1 : 0;
}
template <typename T>
bool umx(T& a, T b) {
    return a < b ? a = b, 1 : 0;
}

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;

int calc(ve<int> a) {
    int ans = 0;
    fr (i, 0, sz(a) - 1) {
        set<int> s;
        fr (j, i, sz(a) - 1) {
            s.insert(a[j]);
            ans += sz(s);
        }
    }
    return ans;
}


ll calc2(ve<int> a) {
    int total = 0;
    fe (x, a) total += x;
    ll ans = 0;
    int toLeft = 0;
    fr (i, 0, sz(a) - 1) {
        int toRight = total - toLeft - a[i];
        ans += 1LL * total * (total + 1) / 2;
        ans -= 1LL * toLeft * (toLeft + 1) / 2;
        ans -= 1LL * toRight * (toRight + 1) / 2;
        toLeft += a[i];
    }
    return ans;
}

const int N = 3e5 + 5;

int n, q;
int a[N];

int cnt[N];

int rnd(int l, int r) {
    return rng() % (r - l + 1) + l;
}

ll solve(ve<int> a) {
    fe (x, a) cnt[x] = 0;

    fe (x, a) cnt[x]++;

    ve<pii> order;
    fe (x, a) {
        if (cnt[x]) {
            order.pb({cnt[x], x});
            cnt[x] = 0;
        }
    }
    sort(all(order));
    reverse(all(order));

    deque<int> d;
    bool who = 0;
    fe (cur, order) {
        if (who == 0) d.push_front(cur.fi);
        else d.pb(cur.fi);
        who ^= 1;
    }
    ve<int> v;
    int now = 1;
    fe (x, d) {
        v.pb(x);
    }
    return calc2(v);
}



int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif

    cin >> n >> q;

    ve<int> v;
    fr (i, 1, n) {
        cin >> a[i];
        v.pb(a[i]);
    }

    sort(all(v));

    cout << solve(v) << "\n";


//    int mn = 1e9;
//    do {
//        umn(mn, calc(v));
//    } while (next_permutation(all(v)));
//
//    cout << solve(v) << " " << mn << "\n";
//
//    do {
//        if (calc(v) == mn) {
//            cout << "v: ";
//            fe (x, v) cout << x << " ";
//            cout << "\n";
//        }
//    } while (next_permutation(all(v)));


    return 0;
}

Compilation message

diversity.cpp: In function 'll solve(ve<int>)':
diversity.cpp:108:9: warning: unused variable 'now' [-Wunused-variable]
  108 |     int now = 1;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 8 ms 1620 KB Output is correct
5 Correct 19 ms 3192 KB Output is correct
6 Correct 28 ms 4584 KB Output is correct
7 Correct 24 ms 4552 KB Output is correct
8 Correct 26 ms 4600 KB Output is correct
9 Correct 25 ms 4584 KB Output is correct
10 Correct 26 ms 4548 KB Output is correct
11 Correct 26 ms 4572 KB Output is correct
12 Correct 28 ms 4672 KB Output is correct
13 Correct 27 ms 4568 KB Output is correct
14 Correct 30 ms 4640 KB Output is correct
15 Correct 27 ms 4568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 8 ms 1620 KB Output is correct
5 Correct 19 ms 3192 KB Output is correct
6 Correct 28 ms 4584 KB Output is correct
7 Correct 24 ms 4552 KB Output is correct
8 Correct 26 ms 4600 KB Output is correct
9 Correct 25 ms 4584 KB Output is correct
10 Correct 26 ms 4548 KB Output is correct
11 Correct 26 ms 4572 KB Output is correct
12 Correct 28 ms 4672 KB Output is correct
13 Correct 27 ms 4568 KB Output is correct
14 Correct 30 ms 4640 KB Output is correct
15 Correct 27 ms 4568 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 13 ms 1876 KB Output is correct
20 Correct 19 ms 3240 KB Output is correct
21 Correct 27 ms 4724 KB Output is correct
22 Correct 30 ms 4808 KB Output is correct
23 Correct 31 ms 4784 KB Output is correct
24 Correct 28 ms 4748 KB Output is correct
25 Correct 32 ms 4784 KB Output is correct
26 Correct 37 ms 4728 KB Output is correct
27 Correct 28 ms 4736 KB Output is correct
28 Correct 28 ms 4708 KB Output is correct
29 Correct 31 ms 4716 KB Output is correct
30 Correct 28 ms 4676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 8 ms 1620 KB Output is correct
5 Correct 19 ms 3192 KB Output is correct
6 Correct 28 ms 4584 KB Output is correct
7 Correct 24 ms 4552 KB Output is correct
8 Correct 26 ms 4600 KB Output is correct
9 Correct 25 ms 4584 KB Output is correct
10 Correct 26 ms 4548 KB Output is correct
11 Correct 26 ms 4572 KB Output is correct
12 Correct 28 ms 4672 KB Output is correct
13 Correct 27 ms 4568 KB Output is correct
14 Correct 30 ms 4640 KB Output is correct
15 Correct 27 ms 4568 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 328 KB Output is correct
18 Correct 2 ms 468 KB Output is correct
19 Correct 13 ms 1876 KB Output is correct
20 Correct 19 ms 3240 KB Output is correct
21 Correct 27 ms 4724 KB Output is correct
22 Correct 30 ms 4808 KB Output is correct
23 Correct 31 ms 4784 KB Output is correct
24 Correct 28 ms 4748 KB Output is correct
25 Correct 32 ms 4784 KB Output is correct
26 Correct 37 ms 4728 KB Output is correct
27 Correct 28 ms 4736 KB Output is correct
28 Correct 28 ms 4708 KB Output is correct
29 Correct 31 ms 4716 KB Output is correct
30 Correct 28 ms 4676 KB Output is correct
31 Correct 1 ms 336 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 2 ms 416 KB Output is correct
35 Correct 2 ms 472 KB Output is correct
36 Correct 2 ms 420 KB Output is correct
37 Correct 9 ms 1240 KB Output is correct
38 Correct 7 ms 1240 KB Output is correct
39 Correct 12 ms 2004 KB Output is correct
40 Correct 24 ms 3528 KB Output is correct
41 Correct 35 ms 5012 KB Output is correct
42 Correct 36 ms 5112 KB Output is correct
43 Correct 35 ms 5060 KB Output is correct
44 Correct 34 ms 5080 KB Output is correct
45 Correct 39 ms 5060 KB Output is correct
46 Correct 39 ms 5080 KB Output is correct
47 Correct 39 ms 5084 KB Output is correct
48 Correct 36 ms 5072 KB Output is correct
49 Correct 36 ms 5156 KB Output is correct
50 Correct 35 ms 5060 KB Output is correct
51 Correct 36 ms 5112 KB Output is correct
52 Correct 39 ms 5056 KB Output is correct
53 Correct 36 ms 5140 KB Output is correct
54 Correct 37 ms 5096 KB Output is correct
55 Correct 36 ms 5028 KB Output is correct
56 Correct 35 ms 5116 KB Output is correct
57 Correct 34 ms 5108 KB Output is correct
58 Correct 35 ms 5056 KB Output is correct
59 Correct 37 ms 5080 KB Output is correct
60 Correct 41 ms 5036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 8 ms 1620 KB Output is correct
15 Correct 19 ms 3192 KB Output is correct
16 Correct 28 ms 4584 KB Output is correct
17 Correct 24 ms 4552 KB Output is correct
18 Correct 26 ms 4600 KB Output is correct
19 Correct 25 ms 4584 KB Output is correct
20 Correct 26 ms 4548 KB Output is correct
21 Correct 26 ms 4572 KB Output is correct
22 Correct 28 ms 4672 KB Output is correct
23 Correct 27 ms 4568 KB Output is correct
24 Correct 30 ms 4640 KB Output is correct
25 Correct 27 ms 4568 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 13 ms 1876 KB Output is correct
30 Correct 19 ms 3240 KB Output is correct
31 Correct 27 ms 4724 KB Output is correct
32 Correct 30 ms 4808 KB Output is correct
33 Correct 31 ms 4784 KB Output is correct
34 Correct 28 ms 4748 KB Output is correct
35 Correct 32 ms 4784 KB Output is correct
36 Correct 37 ms 4728 KB Output is correct
37 Correct 28 ms 4736 KB Output is correct
38 Correct 28 ms 4708 KB Output is correct
39 Correct 31 ms 4716 KB Output is correct
40 Correct 28 ms 4676 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 416 KB Output is correct
45 Correct 2 ms 472 KB Output is correct
46 Correct 2 ms 420 KB Output is correct
47 Correct 9 ms 1240 KB Output is correct
48 Correct 7 ms 1240 KB Output is correct
49 Correct 12 ms 2004 KB Output is correct
50 Correct 24 ms 3528 KB Output is correct
51 Correct 35 ms 5012 KB Output is correct
52 Correct 36 ms 5112 KB Output is correct
53 Correct 35 ms 5060 KB Output is correct
54 Correct 34 ms 5080 KB Output is correct
55 Correct 39 ms 5060 KB Output is correct
56 Correct 39 ms 5080 KB Output is correct
57 Correct 39 ms 5084 KB Output is correct
58 Correct 36 ms 5072 KB Output is correct
59 Correct 36 ms 5156 KB Output is correct
60 Correct 35 ms 5060 KB Output is correct
61 Correct 36 ms 5112 KB Output is correct
62 Correct 39 ms 5056 KB Output is correct
63 Correct 36 ms 5140 KB Output is correct
64 Correct 37 ms 5096 KB Output is correct
65 Correct 36 ms 5028 KB Output is correct
66 Correct 35 ms 5116 KB Output is correct
67 Correct 34 ms 5108 KB Output is correct
68 Correct 35 ms 5056 KB Output is correct
69 Correct 37 ms 5080 KB Output is correct
70 Correct 41 ms 5036 KB Output is correct
71 Correct 7 ms 1260 KB Output is correct
72 Correct 8 ms 1248 KB Output is correct
73 Correct 7 ms 1244 KB Output is correct
74 Correct 7 ms 1240 KB Output is correct
75 Correct 7 ms 1240 KB Output is correct
76 Correct 14 ms 2128 KB Output is correct
77 Correct 15 ms 2132 KB Output is correct
78 Correct 15 ms 2132 KB Output is correct
79 Correct 15 ms 2092 KB Output is correct
80 Correct 16 ms 2132 KB Output is correct
81 Correct 37 ms 3908 KB Output is correct
82 Correct 31 ms 3912 KB Output is correct
83 Correct 28 ms 3856 KB Output is correct
84 Correct 31 ms 3820 KB Output is correct
85 Correct 29 ms 3844 KB Output is correct
86 Correct 34 ms 4320 KB Output is correct
87 Correct 32 ms 4244 KB Output is correct
88 Correct 32 ms 4268 KB Output is correct
89 Correct 42 ms 4296 KB Output is correct
90 Correct 33 ms 4292 KB Output is correct
91 Correct 70 ms 8100 KB Output is correct
92 Correct 59 ms 8076 KB Output is correct
93 Correct 57 ms 8088 KB Output is correct
94 Correct 66 ms 8068 KB Output is correct
95 Correct 58 ms 8128 KB Output is correct
96 Correct 75 ms 10664 KB Output is correct
97 Correct 66 ms 10716 KB Output is correct
98 Correct 69 ms 10708 KB Output is correct
99 Correct 71 ms 10664 KB Output is correct
100 Correct 67 ms 10624 KB Output is correct
101 Correct 71 ms 10720 KB Output is correct
102 Correct 66 ms 10672 KB Output is correct
103 Correct 72 ms 10692 KB Output is correct
104 Correct 82 ms 10660 KB Output is correct
105 Correct 68 ms 10716 KB Output is correct
106 Correct 73 ms 11724 KB Output is correct
107 Correct 68 ms 11788 KB Output is correct
108 Correct 69 ms 11788 KB Output is correct
109 Correct 68 ms 11656 KB Output is correct
110 Correct 75 ms 11728 KB Output is correct
111 Correct 72 ms 11716 KB Output is correct
112 Correct 68 ms 11656 KB Output is correct
113 Correct 68 ms 11656 KB Output is correct
114 Correct 67 ms 11720 KB Output is correct
115 Correct 72 ms 11704 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 468 KB Output is correct
14 Correct 8 ms 1620 KB Output is correct
15 Correct 19 ms 3192 KB Output is correct
16 Correct 28 ms 4584 KB Output is correct
17 Correct 24 ms 4552 KB Output is correct
18 Correct 26 ms 4600 KB Output is correct
19 Correct 25 ms 4584 KB Output is correct
20 Correct 26 ms 4548 KB Output is correct
21 Correct 26 ms 4572 KB Output is correct
22 Correct 28 ms 4672 KB Output is correct
23 Correct 27 ms 4568 KB Output is correct
24 Correct 30 ms 4640 KB Output is correct
25 Correct 27 ms 4568 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 328 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 13 ms 1876 KB Output is correct
30 Correct 19 ms 3240 KB Output is correct
31 Correct 27 ms 4724 KB Output is correct
32 Correct 30 ms 4808 KB Output is correct
33 Correct 31 ms 4784 KB Output is correct
34 Correct 28 ms 4748 KB Output is correct
35 Correct 32 ms 4784 KB Output is correct
36 Correct 37 ms 4728 KB Output is correct
37 Correct 28 ms 4736 KB Output is correct
38 Correct 28 ms 4708 KB Output is correct
39 Correct 31 ms 4716 KB Output is correct
40 Correct 28 ms 4676 KB Output is correct
41 Correct 1 ms 336 KB Output is correct
42 Correct 1 ms 332 KB Output is correct
43 Correct 1 ms 340 KB Output is correct
44 Correct 2 ms 416 KB Output is correct
45 Correct 2 ms 472 KB Output is correct
46 Correct 2 ms 420 KB Output is correct
47 Correct 9 ms 1240 KB Output is correct
48 Correct 7 ms 1240 KB Output is correct
49 Correct 12 ms 2004 KB Output is correct
50 Correct 24 ms 3528 KB Output is correct
51 Correct 35 ms 5012 KB Output is correct
52 Correct 36 ms 5112 KB Output is correct
53 Correct 35 ms 5060 KB Output is correct
54 Correct 34 ms 5080 KB Output is correct
55 Correct 39 ms 5060 KB Output is correct
56 Correct 39 ms 5080 KB Output is correct
57 Correct 39 ms 5084 KB Output is correct
58 Correct 36 ms 5072 KB Output is correct
59 Correct 36 ms 5156 KB Output is correct
60 Correct 35 ms 5060 KB Output is correct
61 Correct 36 ms 5112 KB Output is correct
62 Correct 39 ms 5056 KB Output is correct
63 Correct 36 ms 5140 KB Output is correct
64 Correct 37 ms 5096 KB Output is correct
65 Correct 36 ms 5028 KB Output is correct
66 Correct 35 ms 5116 KB Output is correct
67 Correct 34 ms 5108 KB Output is correct
68 Correct 35 ms 5056 KB Output is correct
69 Correct 37 ms 5080 KB Output is correct
70 Correct 41 ms 5036 KB Output is correct
71 Correct 7 ms 1260 KB Output is correct
72 Correct 8 ms 1248 KB Output is correct
73 Correct 7 ms 1244 KB Output is correct
74 Correct 7 ms 1240 KB Output is correct
75 Correct 7 ms 1240 KB Output is correct
76 Correct 14 ms 2128 KB Output is correct
77 Correct 15 ms 2132 KB Output is correct
78 Correct 15 ms 2132 KB Output is correct
79 Correct 15 ms 2092 KB Output is correct
80 Correct 16 ms 2132 KB Output is correct
81 Correct 37 ms 3908 KB Output is correct
82 Correct 31 ms 3912 KB Output is correct
83 Correct 28 ms 3856 KB Output is correct
84 Correct 31 ms 3820 KB Output is correct
85 Correct 29 ms 3844 KB Output is correct
86 Correct 34 ms 4320 KB Output is correct
87 Correct 32 ms 4244 KB Output is correct
88 Correct 32 ms 4268 KB Output is correct
89 Correct 42 ms 4296 KB Output is correct
90 Correct 33 ms 4292 KB Output is correct
91 Correct 70 ms 8100 KB Output is correct
92 Correct 59 ms 8076 KB Output is correct
93 Correct 57 ms 8088 KB Output is correct
94 Correct 66 ms 8068 KB Output is correct
95 Correct 58 ms 8128 KB Output is correct
96 Correct 75 ms 10664 KB Output is correct
97 Correct 66 ms 10716 KB Output is correct
98 Correct 69 ms 10708 KB Output is correct
99 Correct 71 ms 10664 KB Output is correct
100 Correct 67 ms 10624 KB Output is correct
101 Correct 71 ms 10720 KB Output is correct
102 Correct 66 ms 10672 KB Output is correct
103 Correct 72 ms 10692 KB Output is correct
104 Correct 82 ms 10660 KB Output is correct
105 Correct 68 ms 10716 KB Output is correct
106 Correct 73 ms 11724 KB Output is correct
107 Correct 68 ms 11788 KB Output is correct
108 Correct 69 ms 11788 KB Output is correct
109 Correct 68 ms 11656 KB Output is correct
110 Correct 75 ms 11728 KB Output is correct
111 Correct 72 ms 11716 KB Output is correct
112 Correct 68 ms 11656 KB Output is correct
113 Correct 68 ms 11656 KB Output is correct
114 Correct 67 ms 11720 KB Output is correct
115 Correct 72 ms 11704 KB Output is correct
116 Incorrect 2 ms 596 KB Output isn't correct
117 Halted 0 ms 0 KB -