[快速幂]Codeforces Round #576 (Div. 2)-C. MP3

C. MP3
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output

One common way of digitalizing sound is to record sound intensity at particular time moments. For each time moment intensity is recorded as a non-negative integer. Thus we can represent a sound file as an array of nn non-negative integers.

If there are exactly KK distinct values in the array, then we need k=log2Kk=⌈log2⁡K⌉ bits to store each value. It then takes nknk bits to store the whole file.

To reduce the memory consumption we need to apply some compression. One common way is to reduce the number of possible intensity values. We choose two integers lrl≤r, and after that all intensity values are changed in the following way: if the intensity value is within the range [l;r][l;r], we don't change it. If it is less than ll, we change it to ll; if it is greater than rr, we change it to rr. You can see that we lose some low and some high intensities.

Your task is to apply this compression in such a way that the file fits onto a disk of size II bytes, and the number of changed elements in the array is minimal possible.

We remind you that 11 byte contains 88 bits.

k=⌈log2K⌉ is the smallest integer such that K≤2k. In particular, if K=1, then k=0.

Input

The first line contains two integers nn and II (1≤n≤4e5, 1≤I≤1e8) — the length of the array and the size of the disk in bytes, respectively.

The next line contains nn integers aiai (0≤ai≤1e9) — the array denoting the sound file.

Output

Print a single integer — the minimal possible number of changed elements.

Examples
input
Copy
6 1
2 1 2 3 4 3
output
Copy
2
input
Copy
6 2
2 1 2 3 4 3
output
Copy
0
input
Copy
6 1
1 1 2 2 3 3
output
Copy
2
Note

In the first example we can choose l=2,r=3l=2,r=3. The array becomes 2 2 2 3 3 3, the number of distinct elements is K=2K=2, and the sound file fits onto the disk. Only two values are changed.

In the second example the disk is larger, so the initial file fits it and no changes are required.

In the third example we have to change both 1s or both 3s.

题意:给你n个数,求最少删去多少个数才能满足剩下数的个数的种类小于等于2^(8*I/n),令K是现在数的种类,I是给出的byte,k是由K算出的bit,注意1 byte contains 8 bits,k=log2(K),n*k<=8*I,k<=8*I/n,K<=2^(k)<=2^(8*I/n),所以剩下的数的种类要<=2^(8*I/n)

注意:1 byte contains 8 bits

   K<=4e5 -> ->K在int范围内 -> K<=2^(32)-1 rg<=32,不限制这个的话快速幂那会爆long long

   要删去最少的数目,而用总数减去剩下的就是要删掉的,剩下的个数的种类是need,可用前缀和求出各种情况下need种数的个数

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 const int amn=4e5+5,inf=0x3f3f3f3f;
 5 int a[amn],b[amn],c[amn];
 6 map<int,int> mp;
 7 ll qp(ll in){   ///快速幂
 8     ll ans=1,t=2;
 9     while(in){
10         if(in&1)ans*=t;
11         in>>=1;
12         t*=t;
13     }
14     return ans;
15 }
16 int main(){
17     int n,I,tp=0;
18     cin>>n>>I;
19     ll rg=8*I/n;    ///k=log2(K),n*k<=8*I,k<=8*I/n
20     if(rg>32)rg=32;/// K<=4e5 -> ->K在int范围内 -> K<=2^(32)-1 rg<=32,不限制这个的话快速幂那会爆long long
21     for(int i=1;i<=n;i++){
22         cin>>a[i];
23         if(!mp[a[i]])       ///如果a[i]没被统计过
24             b[++tp]=a[i];   ///统计数有多少种
25         mp[a[i]]++;         ///统计数的个数
26     }
27     ll need=qp(rg);         ///快速幂计算最后要剩多少个,K<=2^(k)<=2^(8*I/n)
28     if(tp<=need)printf("0\n");
29     else{
30         sort(b+1,b+1+tp);   ///区间中从小到大
31         c[0]=0;
32         for(int i=1;i<=tp;i++){
33             c[i]=c[i-1]+mp[b[i]];   ///数的个数作前缀和
34         }
35         ll ans=inf;
36         for(int i=1;i<=tp-need;i++){
37             ans=min(ans,(ll)n-(c[i+need]-c[i]));    ///要删去最少的数目,而用总数减去剩下的就是要删掉的,剩下的个数的种类是need,可用前缀和求出各种情况下need种数的个数
38         }
39         printf("%lld\n",ans);
40     }
41 }

 

全部评论

相关推荐

04-02 10:09
门头沟学院 Java
用微笑面对困难:这里面问题还是很多的,我也不清楚为啥大家会感觉没啥问题。首先就是全栈开发实习9个月的内容都没有java实习生的内容多,1整个技术栈没看出太核心和难点的内容,感觉好像被拉过去打杂了,而且全栈基本上很容易被毙。里面能问的bug是在太多了比如L:继承 BaseMapper 可直接使用内置方法’。请问你的 BaseMapper 是如何扫描实体类注解如果瞬时产生 100 个上传任务,MySQL 的索引设计是否会有瓶颈?你做过分库分表或者索引优化吗?全栈的内容可以针对动态难点去搞,技能特长写在下面吧,你写了这么多技能,项目和实习体现了多少?你可以在项目里多做文章然后把这个放下去,从大致来看实习不算太水,有含金量你也要写上内容针对哨兵里面的节点变化能问出一万个问题,这个很容易就爆了。
提前批简历挂麻了怎么办
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务