Submission #474467

# Submission time Handle Problem Language Result Execution time Memory
474467 2021-09-18T11:17:13 Z lory1608 Diversity (CEOI21_diversity) C++17
64 / 100
23 ms 4560 KB
//#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define PII pair<int,int>
#define ll long long
#define pb push_back
#define sz(x) (int)(x.size())
#define gc getchar()
#define mk make_pair
//#define gc (_p1==_p2&&(_p2=(_p1=_buf)+fread(_buf,1,100000,stdin),_p1==_p2)?EOF:*_p1++)
using namespace std;
char _buf[100000],*_p1=_buf,*_p2=_buf;
inline int gi()
{
	int x=0,f=1;
	char ch=gc;
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=gc;
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<3)+(x<<1)+(ch^48);
		ch=gc;
	}
	return (f==1)?x:-x;
}
const int maxn=3e5+5,M=3e5;
int n,Q,a[maxn],cnt[maxn];
int lp,rp;
inline void input()
{
	n=gi();Q=gi();
	FOR(i,1,n)a[i]=gi(),cnt[a[i]]++;
	sort(cnt+1,cnt+M+1);
}
inline void solve()
{
	ll ans=0;
	FOR(i,1,M)
	{
		if(cnt[i]==0)continue;
		if(lp>rp)swap(lp,rp);
		ans+=1ll*n*(n+1)/2;
		ans-=1ll*lp*(lp+1)/2;
		ans-=1ll*(n-lp-cnt[i])*(n-lp-cnt[i]+1)/2;
		lp+=cnt[i];
	}
	printf("%lld\n",ans);
}
int main()
{
	//freopen("diversity.in","r",stdin);
	//freopen("diversity.out","w",stdout);
	input();
	solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1484 KB Output is correct
2 Correct 6 ms 1424 KB Output is correct
3 Correct 5 ms 1484 KB Output is correct
4 Correct 5 ms 1484 KB Output is correct
5 Correct 5 ms 1484 KB Output is correct
6 Correct 5 ms 1356 KB Output is correct
7 Correct 5 ms 1484 KB Output is correct
8 Correct 6 ms 1484 KB Output is correct
9 Correct 6 ms 1484 KB Output is correct
10 Correct 5 ms 1484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1372 KB Output is correct
2 Correct 6 ms 1484 KB Output is correct
3 Correct 5 ms 1484 KB Output is correct
4 Correct 7 ms 2016 KB Output is correct
5 Correct 8 ms 2636 KB Output is correct
6 Correct 13 ms 3276 KB Output is correct
7 Correct 10 ms 3148 KB Output is correct
8 Correct 11 ms 3260 KB Output is correct
9 Correct 10 ms 3276 KB Output is correct
10 Correct 11 ms 3284 KB Output is correct
11 Correct 10 ms 3276 KB Output is correct
12 Correct 13 ms 3276 KB Output is correct
13 Correct 12 ms 3276 KB Output is correct
14 Correct 10 ms 3276 KB Output is correct
15 Correct 11 ms 3148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1372 KB Output is correct
2 Correct 6 ms 1484 KB Output is correct
3 Correct 5 ms 1484 KB Output is correct
4 Correct 7 ms 2016 KB Output is correct
5 Correct 8 ms 2636 KB Output is correct
6 Correct 13 ms 3276 KB Output is correct
7 Correct 10 ms 3148 KB Output is correct
8 Correct 11 ms 3260 KB Output is correct
9 Correct 10 ms 3276 KB Output is correct
10 Correct 11 ms 3284 KB Output is correct
11 Correct 10 ms 3276 KB Output is correct
12 Correct 13 ms 3276 KB Output is correct
13 Correct 12 ms 3276 KB Output is correct
14 Correct 10 ms 3276 KB Output is correct
15 Correct 11 ms 3148 KB Output is correct
16 Correct 5 ms 1480 KB Output is correct
17 Correct 5 ms 1484 KB Output is correct
18 Correct 6 ms 1484 KB Output is correct
19 Correct 8 ms 2124 KB Output is correct
20 Correct 10 ms 2764 KB Output is correct
21 Correct 11 ms 3404 KB Output is correct
22 Correct 11 ms 3424 KB Output is correct
23 Correct 12 ms 3420 KB Output is correct
24 Correct 13 ms 3420 KB Output is correct
25 Correct 12 ms 3404 KB Output is correct
26 Correct 12 ms 3404 KB Output is correct
27 Correct 12 ms 3404 KB Output is correct
28 Correct 12 ms 3276 KB Output is correct
29 Correct 12 ms 3384 KB Output is correct
30 Correct 11 ms 3448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 1372 KB Output is correct
2 Correct 6 ms 1484 KB Output is correct
3 Correct 5 ms 1484 KB Output is correct
4 Correct 7 ms 2016 KB Output is correct
5 Correct 8 ms 2636 KB Output is correct
6 Correct 13 ms 3276 KB Output is correct
7 Correct 10 ms 3148 KB Output is correct
8 Correct 11 ms 3260 KB Output is correct
9 Correct 10 ms 3276 KB Output is correct
10 Correct 11 ms 3284 KB Output is correct
11 Correct 10 ms 3276 KB Output is correct
12 Correct 13 ms 3276 KB Output is correct
13 Correct 12 ms 3276 KB Output is correct
14 Correct 10 ms 3276 KB Output is correct
15 Correct 11 ms 3148 KB Output is correct
16 Correct 5 ms 1480 KB Output is correct
17 Correct 5 ms 1484 KB Output is correct
18 Correct 6 ms 1484 KB Output is correct
19 Correct 8 ms 2124 KB Output is correct
20 Correct 10 ms 2764 KB Output is correct
21 Correct 11 ms 3404 KB Output is correct
22 Correct 11 ms 3424 KB Output is correct
23 Correct 12 ms 3420 KB Output is correct
24 Correct 13 ms 3420 KB Output is correct
25 Correct 12 ms 3404 KB Output is correct
26 Correct 12 ms 3404 KB Output is correct
27 Correct 12 ms 3404 KB Output is correct
28 Correct 12 ms 3276 KB Output is correct
29 Correct 12 ms 3384 KB Output is correct
30 Correct 11 ms 3448 KB Output is correct
31 Correct 5 ms 1484 KB Output is correct
32 Correct 6 ms 1484 KB Output is correct
33 Correct 5 ms 1484 KB Output is correct
34 Correct 6 ms 1540 KB Output is correct
35 Correct 6 ms 1484 KB Output is correct
36 Correct 6 ms 1484 KB Output is correct
37 Correct 7 ms 1868 KB Output is correct
38 Correct 7 ms 1748 KB Output is correct
39 Correct 8 ms 2124 KB Output is correct
40 Correct 10 ms 3016 KB Output is correct
41 Correct 12 ms 3780 KB Output is correct
42 Correct 12 ms 3788 KB Output is correct
43 Correct 12 ms 3660 KB Output is correct
44 Correct 12 ms 3788 KB Output is correct
45 Correct 12 ms 3660 KB Output is correct
46 Correct 17 ms 3784 KB Output is correct
47 Correct 12 ms 3760 KB Output is correct
48 Correct 12 ms 3780 KB Output is correct
49 Correct 12 ms 3740 KB Output is correct
50 Correct 12 ms 3692 KB Output is correct
51 Correct 12 ms 3792 KB Output is correct
52 Correct 12 ms 3764 KB Output is correct
53 Correct 12 ms 3784 KB Output is correct
54 Correct 12 ms 3772 KB Output is correct
55 Correct 15 ms 3668 KB Output is correct
56 Correct 12 ms 3764 KB Output is correct
57 Correct 12 ms 3700 KB Output is correct
58 Correct 12 ms 3660 KB Output is correct
59 Correct 13 ms 3716 KB Output is correct
60 Correct 12 ms 3780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1484 KB Output is correct
2 Correct 6 ms 1424 KB Output is correct
3 Correct 5 ms 1484 KB Output is correct
4 Correct 5 ms 1484 KB Output is correct
5 Correct 5 ms 1484 KB Output is correct
6 Correct 5 ms 1356 KB Output is correct
7 Correct 5 ms 1484 KB Output is correct
8 Correct 6 ms 1484 KB Output is correct
9 Correct 6 ms 1484 KB Output is correct
10 Correct 5 ms 1484 KB Output is correct
11 Correct 5 ms 1372 KB Output is correct
12 Correct 6 ms 1484 KB Output is correct
13 Correct 5 ms 1484 KB Output is correct
14 Correct 7 ms 2016 KB Output is correct
15 Correct 8 ms 2636 KB Output is correct
16 Correct 13 ms 3276 KB Output is correct
17 Correct 10 ms 3148 KB Output is correct
18 Correct 11 ms 3260 KB Output is correct
19 Correct 10 ms 3276 KB Output is correct
20 Correct 11 ms 3284 KB Output is correct
21 Correct 10 ms 3276 KB Output is correct
22 Correct 13 ms 3276 KB Output is correct
23 Correct 12 ms 3276 KB Output is correct
24 Correct 10 ms 3276 KB Output is correct
25 Correct 11 ms 3148 KB Output is correct
26 Correct 5 ms 1480 KB Output is correct
27 Correct 5 ms 1484 KB Output is correct
28 Correct 6 ms 1484 KB Output is correct
29 Correct 8 ms 2124 KB Output is correct
30 Correct 10 ms 2764 KB Output is correct
31 Correct 11 ms 3404 KB Output is correct
32 Correct 11 ms 3424 KB Output is correct
33 Correct 12 ms 3420 KB Output is correct
34 Correct 13 ms 3420 KB Output is correct
35 Correct 12 ms 3404 KB Output is correct
36 Correct 12 ms 3404 KB Output is correct
37 Correct 12 ms 3404 KB Output is correct
38 Correct 12 ms 3276 KB Output is correct
39 Correct 12 ms 3384 KB Output is correct
40 Correct 11 ms 3448 KB Output is correct
41 Correct 5 ms 1484 KB Output is correct
42 Correct 6 ms 1484 KB Output is correct
43 Correct 5 ms 1484 KB Output is correct
44 Correct 6 ms 1540 KB Output is correct
45 Correct 6 ms 1484 KB Output is correct
46 Correct 6 ms 1484 KB Output is correct
47 Correct 7 ms 1868 KB Output is correct
48 Correct 7 ms 1748 KB Output is correct
49 Correct 8 ms 2124 KB Output is correct
50 Correct 10 ms 3016 KB Output is correct
51 Correct 12 ms 3780 KB Output is correct
52 Correct 12 ms 3788 KB Output is correct
53 Correct 12 ms 3660 KB Output is correct
54 Correct 12 ms 3788 KB Output is correct
55 Correct 12 ms 3660 KB Output is correct
56 Correct 17 ms 3784 KB Output is correct
57 Correct 12 ms 3760 KB Output is correct
58 Correct 12 ms 3780 KB Output is correct
59 Correct 12 ms 3740 KB Output is correct
60 Correct 12 ms 3692 KB Output is correct
61 Correct 12 ms 3792 KB Output is correct
62 Correct 12 ms 3764 KB Output is correct
63 Correct 12 ms 3784 KB Output is correct
64 Correct 12 ms 3772 KB Output is correct
65 Correct 15 ms 3668 KB Output is correct
66 Correct 12 ms 3764 KB Output is correct
67 Correct 12 ms 3700 KB Output is correct
68 Correct 12 ms 3660 KB Output is correct
69 Correct 13 ms 3716 KB Output is correct
70 Correct 12 ms 3780 KB Output is correct
71 Correct 7 ms 1868 KB Output is correct
72 Correct 7 ms 1884 KB Output is correct
73 Correct 7 ms 1888 KB Output is correct
74 Correct 7 ms 1776 KB Output is correct
75 Correct 7 ms 1868 KB Output is correct
76 Correct 8 ms 2332 KB Output is correct
77 Correct 8 ms 2332 KB Output is correct
78 Correct 8 ms 2328 KB Output is correct
79 Correct 8 ms 2252 KB Output is correct
80 Correct 8 ms 2332 KB Output is correct
81 Correct 14 ms 3148 KB Output is correct
82 Correct 11 ms 3148 KB Output is correct
83 Correct 14 ms 3124 KB Output is correct
84 Correct 11 ms 3148 KB Output is correct
85 Correct 14 ms 3184 KB Output is correct
86 Correct 13 ms 3200 KB Output is correct
87 Correct 13 ms 3312 KB Output is correct
88 Correct 13 ms 3308 KB Output is correct
89 Correct 13 ms 3260 KB Output is correct
90 Correct 12 ms 3276 KB Output is correct
91 Correct 19 ms 4348 KB Output is correct
92 Correct 18 ms 4300 KB Output is correct
93 Correct 19 ms 4300 KB Output is correct
94 Correct 18 ms 4300 KB Output is correct
95 Correct 21 ms 4244 KB Output is correct
96 Correct 21 ms 4428 KB Output is correct
97 Correct 21 ms 4504 KB Output is correct
98 Correct 20 ms 4528 KB Output is correct
99 Correct 20 ms 4436 KB Output is correct
100 Correct 20 ms 4436 KB Output is correct
101 Correct 20 ms 4420 KB Output is correct
102 Correct 20 ms 4536 KB Output is correct
103 Correct 20 ms 4436 KB Output is correct
104 Correct 22 ms 4428 KB Output is correct
105 Correct 23 ms 4432 KB Output is correct
106 Correct 21 ms 4544 KB Output is correct
107 Correct 20 ms 4460 KB Output is correct
108 Correct 23 ms 4540 KB Output is correct
109 Correct 21 ms 4468 KB Output is correct
110 Correct 21 ms 4556 KB Output is correct
111 Correct 20 ms 4480 KB Output is correct
112 Correct 20 ms 4556 KB Output is correct
113 Correct 20 ms 4480 KB Output is correct
114 Correct 23 ms 4456 KB Output is correct
115 Correct 20 ms 4560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 1484 KB Output is correct
2 Correct 6 ms 1424 KB Output is correct
3 Correct 5 ms 1484 KB Output is correct
4 Correct 5 ms 1484 KB Output is correct
5 Correct 5 ms 1484 KB Output is correct
6 Correct 5 ms 1356 KB Output is correct
7 Correct 5 ms 1484 KB Output is correct
8 Correct 6 ms 1484 KB Output is correct
9 Correct 6 ms 1484 KB Output is correct
10 Correct 5 ms 1484 KB Output is correct
11 Correct 5 ms 1372 KB Output is correct
12 Correct 6 ms 1484 KB Output is correct
13 Correct 5 ms 1484 KB Output is correct
14 Correct 7 ms 2016 KB Output is correct
15 Correct 8 ms 2636 KB Output is correct
16 Correct 13 ms 3276 KB Output is correct
17 Correct 10 ms 3148 KB Output is correct
18 Correct 11 ms 3260 KB Output is correct
19 Correct 10 ms 3276 KB Output is correct
20 Correct 11 ms 3284 KB Output is correct
21 Correct 10 ms 3276 KB Output is correct
22 Correct 13 ms 3276 KB Output is correct
23 Correct 12 ms 3276 KB Output is correct
24 Correct 10 ms 3276 KB Output is correct
25 Correct 11 ms 3148 KB Output is correct
26 Correct 5 ms 1480 KB Output is correct
27 Correct 5 ms 1484 KB Output is correct
28 Correct 6 ms 1484 KB Output is correct
29 Correct 8 ms 2124 KB Output is correct
30 Correct 10 ms 2764 KB Output is correct
31 Correct 11 ms 3404 KB Output is correct
32 Correct 11 ms 3424 KB Output is correct
33 Correct 12 ms 3420 KB Output is correct
34 Correct 13 ms 3420 KB Output is correct
35 Correct 12 ms 3404 KB Output is correct
36 Correct 12 ms 3404 KB Output is correct
37 Correct 12 ms 3404 KB Output is correct
38 Correct 12 ms 3276 KB Output is correct
39 Correct 12 ms 3384 KB Output is correct
40 Correct 11 ms 3448 KB Output is correct
41 Correct 5 ms 1484 KB Output is correct
42 Correct 6 ms 1484 KB Output is correct
43 Correct 5 ms 1484 KB Output is correct
44 Correct 6 ms 1540 KB Output is correct
45 Correct 6 ms 1484 KB Output is correct
46 Correct 6 ms 1484 KB Output is correct
47 Correct 7 ms 1868 KB Output is correct
48 Correct 7 ms 1748 KB Output is correct
49 Correct 8 ms 2124 KB Output is correct
50 Correct 10 ms 3016 KB Output is correct
51 Correct 12 ms 3780 KB Output is correct
52 Correct 12 ms 3788 KB Output is correct
53 Correct 12 ms 3660 KB Output is correct
54 Correct 12 ms 3788 KB Output is correct
55 Correct 12 ms 3660 KB Output is correct
56 Correct 17 ms 3784 KB Output is correct
57 Correct 12 ms 3760 KB Output is correct
58 Correct 12 ms 3780 KB Output is correct
59 Correct 12 ms 3740 KB Output is correct
60 Correct 12 ms 3692 KB Output is correct
61 Correct 12 ms 3792 KB Output is correct
62 Correct 12 ms 3764 KB Output is correct
63 Correct 12 ms 3784 KB Output is correct
64 Correct 12 ms 3772 KB Output is correct
65 Correct 15 ms 3668 KB Output is correct
66 Correct 12 ms 3764 KB Output is correct
67 Correct 12 ms 3700 KB Output is correct
68 Correct 12 ms 3660 KB Output is correct
69 Correct 13 ms 3716 KB Output is correct
70 Correct 12 ms 3780 KB Output is correct
71 Correct 7 ms 1868 KB Output is correct
72 Correct 7 ms 1884 KB Output is correct
73 Correct 7 ms 1888 KB Output is correct
74 Correct 7 ms 1776 KB Output is correct
75 Correct 7 ms 1868 KB Output is correct
76 Correct 8 ms 2332 KB Output is correct
77 Correct 8 ms 2332 KB Output is correct
78 Correct 8 ms 2328 KB Output is correct
79 Correct 8 ms 2252 KB Output is correct
80 Correct 8 ms 2332 KB Output is correct
81 Correct 14 ms 3148 KB Output is correct
82 Correct 11 ms 3148 KB Output is correct
83 Correct 14 ms 3124 KB Output is correct
84 Correct 11 ms 3148 KB Output is correct
85 Correct 14 ms 3184 KB Output is correct
86 Correct 13 ms 3200 KB Output is correct
87 Correct 13 ms 3312 KB Output is correct
88 Correct 13 ms 3308 KB Output is correct
89 Correct 13 ms 3260 KB Output is correct
90 Correct 12 ms 3276 KB Output is correct
91 Correct 19 ms 4348 KB Output is correct
92 Correct 18 ms 4300 KB Output is correct
93 Correct 19 ms 4300 KB Output is correct
94 Correct 18 ms 4300 KB Output is correct
95 Correct 21 ms 4244 KB Output is correct
96 Correct 21 ms 4428 KB Output is correct
97 Correct 21 ms 4504 KB Output is correct
98 Correct 20 ms 4528 KB Output is correct
99 Correct 20 ms 4436 KB Output is correct
100 Correct 20 ms 4436 KB Output is correct
101 Correct 20 ms 4420 KB Output is correct
102 Correct 20 ms 4536 KB Output is correct
103 Correct 20 ms 4436 KB Output is correct
104 Correct 22 ms 4428 KB Output is correct
105 Correct 23 ms 4432 KB Output is correct
106 Correct 21 ms 4544 KB Output is correct
107 Correct 20 ms 4460 KB Output is correct
108 Correct 23 ms 4540 KB Output is correct
109 Correct 21 ms 4468 KB Output is correct
110 Correct 21 ms 4556 KB Output is correct
111 Correct 20 ms 4480 KB Output is correct
112 Correct 20 ms 4556 KB Output is correct
113 Correct 20 ms 4480 KB Output is correct
114 Correct 23 ms 4456 KB Output is correct
115 Correct 20 ms 4560 KB Output is correct
116 Incorrect 6 ms 1612 KB Output isn't correct
117 Halted 0 ms 0 KB -