답안 #914423

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
914423 2024-01-22T05:49:31 Z vjudge1 Diversity (CEOI21_diversity) C++17
64 / 100
74 ms 25700 KB
#include "bits/stdc++.h"
using namespace std;       

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using ll = long long;
using ld = long double;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
void IOIGold2024_InshAllah() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
ll binmul(ll a, ll b, ll c) { ll res = 0; while(b) { if(b&1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; }
ll binpow(ll a, ll b, ll c) { ll res = 1; while(b) { if(b&1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; }
template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ld rnd() { return rng()%INT_MAX*1.0/INT_MAX; }

const ll inf = 1e18+7, MX = LLONG_MAX, MN = LLONG_MIN;
const ll mod = 1e9+7, N = 3e5+5;
ll a[N], cnt[N], pr[N], ans[N];

void kigash() {
    ll n, q;
    cin>>n>>q;
    vector<ll> v;
    for(ll i=1; i<=n; i++) {
        cin>>a[i];
        v.pb(a[i]);
        cnt[a[i]]++;
    }
    ll tmpl, tmpr;
    cin>>tmpl>>tmpr;
    sort(all(v));
    v.erase(unique(all(v)), v.end());
    vector<pair<ll, ll>> b;
    for(ll i=0; i<sz(v); i++) b.pb({cnt[v[i]], v[i]});
    sort(rall(b));
    ll l = (sz(b)+1)/2-1, r = (sz(b)+1)/2, t = 0;
    for(ll i=0; i<sz(b); i++) {
        if(!t) ans[l--] = b[i].ss;
        else ans[r++] = b[i].ss;
        t ^= 1;
    }
    vector<ll> x;
    x.pb(0);
    for(ll i=0; i<sz(b); i++) {
        for(ll j=1; j<=cnt[ans[i]]; j++) {
            x.pb(ans[i]);
        }
    }
    ll sum = 0, res = 0;
    for(ll i=1; i<=n; i++) {
        if(x[i]!=x[i-1]) sum++;
        pr[i] = pr[i-1]+sum;
    }
    for(ll i=1; i<=n; i++) {
        res += pr[n]-pr[i-1]-(n-i+1)*(pr[i]-pr[i-1]-1);
    }
    cout<<res<<"\n";
    return;
}

signed main(/*Kigash Amir*/) {
    // freopen("");
    IOIGold2024_InshAllah();
    ll tt = 1;
    // cin>>tt;
    for(ll i=1; i<=tt; i++) {
        kigash();
    }
}

Compilation message

diversity.cpp: In function 'void freopen(std::string)':
diversity.cpp:17:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diversity.cpp:17:73: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4508 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 8 ms 7004 KB Output is correct
5 Correct 18 ms 9940 KB Output is correct
6 Correct 26 ms 14788 KB Output is correct
7 Correct 25 ms 14800 KB Output is correct
8 Correct 26 ms 15052 KB Output is correct
9 Correct 25 ms 14792 KB Output is correct
10 Correct 26 ms 16840 KB Output is correct
11 Correct 25 ms 14788 KB Output is correct
12 Correct 27 ms 16328 KB Output is correct
13 Correct 26 ms 15864 KB Output is correct
14 Correct 26 ms 15312 KB Output is correct
15 Correct 27 ms 16936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 8 ms 7004 KB Output is correct
5 Correct 18 ms 9940 KB Output is correct
6 Correct 26 ms 14788 KB Output is correct
7 Correct 25 ms 14800 KB Output is correct
8 Correct 26 ms 15052 KB Output is correct
9 Correct 25 ms 14792 KB Output is correct
10 Correct 26 ms 16840 KB Output is correct
11 Correct 25 ms 14788 KB Output is correct
12 Correct 27 ms 16328 KB Output is correct
13 Correct 26 ms 15864 KB Output is correct
14 Correct 26 ms 15312 KB Output is correct
15 Correct 27 ms 16936 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 2 ms 5172 KB Output is correct
19 Correct 10 ms 7256 KB Output is correct
20 Correct 19 ms 10064 KB Output is correct
21 Correct 29 ms 18376 KB Output is correct
22 Correct 29 ms 16580 KB Output is correct
23 Correct 29 ms 18628 KB Output is correct
24 Correct 29 ms 17096 KB Output is correct
25 Correct 28 ms 17348 KB Output is correct
26 Correct 28 ms 15812 KB Output is correct
27 Correct 29 ms 17348 KB Output is correct
28 Correct 27 ms 15308 KB Output is correct
29 Correct 28 ms 15132 KB Output is correct
30 Correct 29 ms 16828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 2 ms 4956 KB Output is correct
4 Correct 8 ms 7004 KB Output is correct
5 Correct 18 ms 9940 KB Output is correct
6 Correct 26 ms 14788 KB Output is correct
7 Correct 25 ms 14800 KB Output is correct
8 Correct 26 ms 15052 KB Output is correct
9 Correct 25 ms 14792 KB Output is correct
10 Correct 26 ms 16840 KB Output is correct
11 Correct 25 ms 14788 KB Output is correct
12 Correct 27 ms 16328 KB Output is correct
13 Correct 26 ms 15864 KB Output is correct
14 Correct 26 ms 15312 KB Output is correct
15 Correct 27 ms 16936 KB Output is correct
16 Correct 1 ms 4440 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 2 ms 5172 KB Output is correct
19 Correct 10 ms 7256 KB Output is correct
20 Correct 19 ms 10064 KB Output is correct
21 Correct 29 ms 18376 KB Output is correct
22 Correct 29 ms 16580 KB Output is correct
23 Correct 29 ms 18628 KB Output is correct
24 Correct 29 ms 17096 KB Output is correct
25 Correct 28 ms 17348 KB Output is correct
26 Correct 28 ms 15812 KB Output is correct
27 Correct 29 ms 17348 KB Output is correct
28 Correct 27 ms 15308 KB Output is correct
29 Correct 28 ms 15132 KB Output is correct
30 Correct 29 ms 16828 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 2 ms 4956 KB Output is correct
35 Correct 2 ms 4956 KB Output is correct
36 Correct 2 ms 4956 KB Output is correct
37 Correct 6 ms 6040 KB Output is correct
38 Correct 7 ms 5996 KB Output is correct
39 Correct 12 ms 7296 KB Output is correct
40 Correct 23 ms 10340 KB Output is correct
41 Correct 35 ms 17096 KB Output is correct
42 Correct 34 ms 15304 KB Output is correct
43 Correct 38 ms 15808 KB Output is correct
44 Correct 33 ms 15552 KB Output is correct
45 Correct 34 ms 16584 KB Output is correct
46 Correct 35 ms 18552 KB Output is correct
47 Correct 33 ms 16840 KB Output is correct
48 Correct 36 ms 17864 KB Output is correct
49 Correct 34 ms 15800 KB Output is correct
50 Correct 40 ms 17352 KB Output is correct
51 Correct 34 ms 15936 KB Output is correct
52 Correct 35 ms 17360 KB Output is correct
53 Correct 35 ms 18368 KB Output is correct
54 Correct 37 ms 16832 KB Output is correct
55 Correct 35 ms 15304 KB Output is correct
56 Correct 36 ms 18840 KB Output is correct
57 Correct 38 ms 16832 KB Output is correct
58 Correct 35 ms 16832 KB Output is correct
59 Correct 36 ms 17360 KB Output is correct
60 Correct 35 ms 18284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4508 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 8 ms 7004 KB Output is correct
15 Correct 18 ms 9940 KB Output is correct
16 Correct 26 ms 14788 KB Output is correct
17 Correct 25 ms 14800 KB Output is correct
18 Correct 26 ms 15052 KB Output is correct
19 Correct 25 ms 14792 KB Output is correct
20 Correct 26 ms 16840 KB Output is correct
21 Correct 25 ms 14788 KB Output is correct
22 Correct 27 ms 16328 KB Output is correct
23 Correct 26 ms 15864 KB Output is correct
24 Correct 26 ms 15312 KB Output is correct
25 Correct 27 ms 16936 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 2 ms 5172 KB Output is correct
29 Correct 10 ms 7256 KB Output is correct
30 Correct 19 ms 10064 KB Output is correct
31 Correct 29 ms 18376 KB Output is correct
32 Correct 29 ms 16580 KB Output is correct
33 Correct 29 ms 18628 KB Output is correct
34 Correct 29 ms 17096 KB Output is correct
35 Correct 28 ms 17348 KB Output is correct
36 Correct 28 ms 15812 KB Output is correct
37 Correct 29 ms 17348 KB Output is correct
38 Correct 27 ms 15308 KB Output is correct
39 Correct 28 ms 15132 KB Output is correct
40 Correct 29 ms 16828 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 6 ms 6040 KB Output is correct
48 Correct 7 ms 5996 KB Output is correct
49 Correct 12 ms 7296 KB Output is correct
50 Correct 23 ms 10340 KB Output is correct
51 Correct 35 ms 17096 KB Output is correct
52 Correct 34 ms 15304 KB Output is correct
53 Correct 38 ms 15808 KB Output is correct
54 Correct 33 ms 15552 KB Output is correct
55 Correct 34 ms 16584 KB Output is correct
56 Correct 35 ms 18552 KB Output is correct
57 Correct 33 ms 16840 KB Output is correct
58 Correct 36 ms 17864 KB Output is correct
59 Correct 34 ms 15800 KB Output is correct
60 Correct 40 ms 17352 KB Output is correct
61 Correct 34 ms 15936 KB Output is correct
62 Correct 35 ms 17360 KB Output is correct
63 Correct 35 ms 18368 KB Output is correct
64 Correct 37 ms 16832 KB Output is correct
65 Correct 35 ms 15304 KB Output is correct
66 Correct 36 ms 18840 KB Output is correct
67 Correct 38 ms 16832 KB Output is correct
68 Correct 35 ms 16832 KB Output is correct
69 Correct 36 ms 17360 KB Output is correct
70 Correct 35 ms 18284 KB Output is correct
71 Correct 7 ms 6008 KB Output is correct
72 Correct 7 ms 6012 KB Output is correct
73 Correct 7 ms 6012 KB Output is correct
74 Correct 7 ms 5992 KB Output is correct
75 Correct 7 ms 6008 KB Output is correct
76 Correct 14 ms 8408 KB Output is correct
77 Correct 14 ms 8544 KB Output is correct
78 Correct 14 ms 8408 KB Output is correct
79 Correct 14 ms 8408 KB Output is correct
80 Correct 14 ms 8528 KB Output is correct
81 Correct 28 ms 12676 KB Output is correct
82 Correct 28 ms 12580 KB Output is correct
83 Correct 27 ms 12756 KB Output is correct
84 Correct 28 ms 12488 KB Output is correct
85 Correct 28 ms 12748 KB Output is correct
86 Correct 31 ms 12944 KB Output is correct
87 Correct 30 ms 13000 KB Output is correct
88 Correct 30 ms 13000 KB Output is correct
89 Correct 31 ms 13004 KB Output is correct
90 Correct 30 ms 12864 KB Output is correct
91 Correct 60 ms 22208 KB Output is correct
92 Correct 55 ms 25028 KB Output is correct
93 Correct 55 ms 22464 KB Output is correct
94 Correct 56 ms 23328 KB Output is correct
95 Correct 56 ms 23996 KB Output is correct
96 Correct 65 ms 22996 KB Output is correct
97 Correct 65 ms 22336 KB Output is correct
98 Correct 65 ms 22336 KB Output is correct
99 Correct 67 ms 25412 KB Output is correct
100 Correct 69 ms 22172 KB Output is correct
101 Correct 74 ms 25700 KB Output is correct
102 Correct 67 ms 23104 KB Output is correct
103 Correct 67 ms 21828 KB Output is correct
104 Correct 65 ms 23084 KB Output is correct
105 Correct 66 ms 21348 KB Output is correct
106 Correct 69 ms 25144 KB Output is correct
107 Correct 64 ms 22404 KB Output is correct
108 Correct 63 ms 22440 KB Output is correct
109 Correct 69 ms 24900 KB Output is correct
110 Correct 64 ms 22488 KB Output is correct
111 Correct 66 ms 22392 KB Output is correct
112 Correct 70 ms 23624 KB Output is correct
113 Correct 72 ms 25544 KB Output is correct
114 Correct 63 ms 22420 KB Output is correct
115 Correct 69 ms 25508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4440 KB Output is correct
2 Correct 1 ms 4440 KB Output is correct
3 Correct 1 ms 4440 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4508 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4440 KB Output is correct
11 Correct 1 ms 4444 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 2 ms 4956 KB Output is correct
14 Correct 8 ms 7004 KB Output is correct
15 Correct 18 ms 9940 KB Output is correct
16 Correct 26 ms 14788 KB Output is correct
17 Correct 25 ms 14800 KB Output is correct
18 Correct 26 ms 15052 KB Output is correct
19 Correct 25 ms 14792 KB Output is correct
20 Correct 26 ms 16840 KB Output is correct
21 Correct 25 ms 14788 KB Output is correct
22 Correct 27 ms 16328 KB Output is correct
23 Correct 26 ms 15864 KB Output is correct
24 Correct 26 ms 15312 KB Output is correct
25 Correct 27 ms 16936 KB Output is correct
26 Correct 1 ms 4440 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 2 ms 5172 KB Output is correct
29 Correct 10 ms 7256 KB Output is correct
30 Correct 19 ms 10064 KB Output is correct
31 Correct 29 ms 18376 KB Output is correct
32 Correct 29 ms 16580 KB Output is correct
33 Correct 29 ms 18628 KB Output is correct
34 Correct 29 ms 17096 KB Output is correct
35 Correct 28 ms 17348 KB Output is correct
36 Correct 28 ms 15812 KB Output is correct
37 Correct 29 ms 17348 KB Output is correct
38 Correct 27 ms 15308 KB Output is correct
39 Correct 28 ms 15132 KB Output is correct
40 Correct 29 ms 16828 KB Output is correct
41 Correct 1 ms 4444 KB Output is correct
42 Correct 1 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 2 ms 4956 KB Output is correct
45 Correct 2 ms 4956 KB Output is correct
46 Correct 2 ms 4956 KB Output is correct
47 Correct 6 ms 6040 KB Output is correct
48 Correct 7 ms 5996 KB Output is correct
49 Correct 12 ms 7296 KB Output is correct
50 Correct 23 ms 10340 KB Output is correct
51 Correct 35 ms 17096 KB Output is correct
52 Correct 34 ms 15304 KB Output is correct
53 Correct 38 ms 15808 KB Output is correct
54 Correct 33 ms 15552 KB Output is correct
55 Correct 34 ms 16584 KB Output is correct
56 Correct 35 ms 18552 KB Output is correct
57 Correct 33 ms 16840 KB Output is correct
58 Correct 36 ms 17864 KB Output is correct
59 Correct 34 ms 15800 KB Output is correct
60 Correct 40 ms 17352 KB Output is correct
61 Correct 34 ms 15936 KB Output is correct
62 Correct 35 ms 17360 KB Output is correct
63 Correct 35 ms 18368 KB Output is correct
64 Correct 37 ms 16832 KB Output is correct
65 Correct 35 ms 15304 KB Output is correct
66 Correct 36 ms 18840 KB Output is correct
67 Correct 38 ms 16832 KB Output is correct
68 Correct 35 ms 16832 KB Output is correct
69 Correct 36 ms 17360 KB Output is correct
70 Correct 35 ms 18284 KB Output is correct
71 Correct 7 ms 6008 KB Output is correct
72 Correct 7 ms 6012 KB Output is correct
73 Correct 7 ms 6012 KB Output is correct
74 Correct 7 ms 5992 KB Output is correct
75 Correct 7 ms 6008 KB Output is correct
76 Correct 14 ms 8408 KB Output is correct
77 Correct 14 ms 8544 KB Output is correct
78 Correct 14 ms 8408 KB Output is correct
79 Correct 14 ms 8408 KB Output is correct
80 Correct 14 ms 8528 KB Output is correct
81 Correct 28 ms 12676 KB Output is correct
82 Correct 28 ms 12580 KB Output is correct
83 Correct 27 ms 12756 KB Output is correct
84 Correct 28 ms 12488 KB Output is correct
85 Correct 28 ms 12748 KB Output is correct
86 Correct 31 ms 12944 KB Output is correct
87 Correct 30 ms 13000 KB Output is correct
88 Correct 30 ms 13000 KB Output is correct
89 Correct 31 ms 13004 KB Output is correct
90 Correct 30 ms 12864 KB Output is correct
91 Correct 60 ms 22208 KB Output is correct
92 Correct 55 ms 25028 KB Output is correct
93 Correct 55 ms 22464 KB Output is correct
94 Correct 56 ms 23328 KB Output is correct
95 Correct 56 ms 23996 KB Output is correct
96 Correct 65 ms 22996 KB Output is correct
97 Correct 65 ms 22336 KB Output is correct
98 Correct 65 ms 22336 KB Output is correct
99 Correct 67 ms 25412 KB Output is correct
100 Correct 69 ms 22172 KB Output is correct
101 Correct 74 ms 25700 KB Output is correct
102 Correct 67 ms 23104 KB Output is correct
103 Correct 67 ms 21828 KB Output is correct
104 Correct 65 ms 23084 KB Output is correct
105 Correct 66 ms 21348 KB Output is correct
106 Correct 69 ms 25144 KB Output is correct
107 Correct 64 ms 22404 KB Output is correct
108 Correct 63 ms 22440 KB Output is correct
109 Correct 69 ms 24900 KB Output is correct
110 Correct 64 ms 22488 KB Output is correct
111 Correct 66 ms 22392 KB Output is correct
112 Correct 70 ms 23624 KB Output is correct
113 Correct 72 ms 25544 KB Output is correct
114 Correct 63 ms 22420 KB Output is correct
115 Correct 69 ms 25508 KB Output is correct
116 Incorrect 2 ms 5212 KB Output isn't correct
117 Halted 0 ms 0 KB -