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=⌈log2K⌉k=⌈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 l≤rl≤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种数的个数

 #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int amn=4e5+,inf=0x3f3f3f3f;
int a[amn],b[amn],c[amn];
map<int,int> mp;
ll qp(ll in){ ///快速幂
ll ans=,t=;
while(in){
if(in&)ans*=t;
in>>=;
t*=t;
}
return ans;
}
int main(){
int n,I,tp=;
cin>>n>>I;
ll rg=*I/n; ///k=log2(K),n*k<=8*I,k<=8*I/n
if(rg>32)rg=32;/// K<=4e5 -> ->K在int范围内 -> K<=2^(32)-1 rg<=32,不限制这个的话快速幂那会爆long long
for(int i=1;i<=n;i++){
cin>>a[i];
if(!mp[a[i]]) ///如果a[i]没被统计过
b[++tp]=a[i]; ///统计数有多少种
mp[a[i]]++; ///统计数的个数
}
ll need=qp(rg); ///快速幂计算最后要剩多少个,K<=2^(k)<=2^(8*I/n)
if(tp<=need)printf("0\n");
else{
sort(b+,b++tp); ///区间中从小到大
c[]=;
for(int i=;i<=tp;i++){
c[i]=c[i-]+mp[b[i]]; ///数的个数作前缀和
}
ll ans=inf;
for(int i=;i<=tp-need;i++){
ans=min(ans,(ll)n-(c[i+need]-c[i])); ///要删去最少的数目,而用总数减去剩下的就是要删掉的,剩下的个数的种类是need,可用前缀和求出各种情况下need种数的个数
}
printf("%lld\n",ans);
}
}

[快速幂]Codeforces Round #576 (Div. 2)-C. MP3的更多相关文章

  1. 线段树+矩阵快速幂 Codeforces Round #373 (Div. 2) E

    http://codeforces.com/contest/719/problem/E 题目大意:给你一串数组a,a[i]表示第i个斐波那契数列,有如下操作 ①对[l,r]区间+一个val ②求出[l ...

  2. Codeforces Round #576 (Div. 2) D. Welfare State

    http://codeforces.com/contest/1199/problem/D Examples input1 output1 input2 output2 Note In the firs ...

  3. Codeforces Round #576 (Div. 1)

    Preface 闲来无事打打CF,就近找了场Div1打打 这场感觉偏简单,比赛时艹穿的人都不少,也没有3000+的题 两三个小时就搞完了吧(F用随机水过去了) A. MP3 题意不好理解,没用翻译看了 ...

  4. Codeforces Round #576 (div.1 + div.2)

    Div2 A 长度为\(n(n≤10^5)\)的数组,每个元素不同,求有多少个位置\(d\)满足\(d - x \le j < d \And d < j \le d + y a_d< ...

  5. Codeforces Round #576 (Div. 1) 简要题解 (CDEF)

    1198 C Matching vs Independent Set 大意: 给定$3n$个点的无向图, 求构造$n$条边的匹配, 或$n$个点的独立集. 假设已经构造出$x$条边的匹配, 那么剩余$ ...

  6. Codeforces Round #576 (Div. 2) 题解

    比赛链接:https://codeforc.es/contest/1199 A. City Day 题意:给出一个数列,和俩个整数\(x,y\),要求找到序号最靠前的数字\(d\),使得\(d\)满足 ...

  7. Codeforces Round #383 (Div. 2) 题解【ABCDE】

    Codeforces Round #383 (Div. 2) A. Arpa's hard exam and Mehrdad's naive cheat 题意 求1378^n mod 10 题解 直接 ...

  8. Codeforces Round #113 (Div. 2)

    Codeforces Round #113 (Div. 2) B. Polygons 题意 给一个\(N(N \le 10^5)\)个点的凸包 \(M(M \le 2 \cdot 10^4)\)次询问 ...

  9. Codeforces Round #373 (Div. 1)

    Codeforces Round #373 (Div. 1) A. Efim and Strange Grade 题意 给一个长为\(n(n \le 2 \times 10^5)\)的小数,每次可以选 ...

随机推荐

  1. swoole I/O 模型

    I/O即Input/Output,输入和输出的意思.在计算机的世界里,涉及到数据交换的地方,比如磁盘.网络等,就需要I/O接口. 通常,I/O是相对的.比如说你打开浏览器,通过网络I/O获取我们网站的 ...

  2. C++扬帆远航——14(求两个数的最大公约数)

    /* * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:gongyueshu.cpp * 作者:常轩 * 微信公众号:W ...

  3. 关于C++类中的三兄弟(pretect、private、public)

    1.public修饰的成员变量 在程序的任何地方都可以被访问,就是公共变量的意思,不需要通过成员函数就可以由类的实例直接访问 2.private修饰的成员变量 只有类内可直接访问,私有的,类的实例要通 ...

  4. AI:拿来主义——预训练网络(一)

    我们已经训练过几个神经网络了,识别手写数字,房价预测或者是区分猫和狗,那随之而来就有一个问题,这些训练出的网络怎么用,每个问题我都需要重新去训练网络吗?因为程序员都不太喜欢做重复的事情,因此答案肯定是 ...

  5. Java2变量和运算符

    课后作业:[必做题] 1√AB互换 已知a,b均是整型变量,写出将a,b两个变量中的值互换的程序.(知识点:变量和运算符综合应用) [必做题] package com.two; public clas ...

  6. 使用web写UI, 使用js对接C++项目, 提高开发效率

    ppt资源下载地址https://www.slidestalk.com/s/webui_nodejs_cmdlrx

  7. http相关知识点回顾

    一.概述 1.什么是HTTP HTTP是一种可以获取HTML这样的网络资源的一种通讯协议protocol.是在WEB上进行数据交换的基础,是一种客户端--服务器协议.HTTP是一种可扩展的应用层协议, ...

  8. java 构造器(构造方法)使用详细说明

    知识点 什么是构造器 构造器通常也叫构造方法.构造函数,构造器在每个项目中几乎无处不在.当你new一个对象时,就会调用构造器.构造器格式如下: [修饰符,比如public] 类名 (参数列表,可以没有 ...

  9. 线程(Thread)的四种停止方式

    1.正常的程序启动,停止 2.使用退出标记,一般程序在run()方法后,线程会正常结束.但是有一些伺服线程还在运行,他们运行时间较长,只有当外部条件满足时,他们才会停止.实现如下: public cl ...

  10. Yuchuan_Linux_C编程之五gdb调试

    一.整体大纲 二.gdb调试 1. 启动gdb start -- 只执行一步    n -- next    s -- step(单步) -- 可以进入到函数体内部    c - continue - ...