题干:
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=⌈log2K⌉ 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⌉k=⌈log2K⌉ is the smallest integer such that K≤2kK≤2k. In particular, if K=1K=1, then k=0k=0.
Input
The first line contains two integers nn and II (1≤n≤4⋅1051≤n≤4⋅105, 1≤I≤1081≤I≤108) — the length of the array and the size of the disk in bytes, respectively.
The next line contains nn integers aiai (0≤ai≤1090≤ai≤109) — 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.
题目大意:
解题报告:
根据给定的I可以求出来可以保留的不同数字的个数,然后枚举的同时记录最小值就行了。注意首先要保证算的logg不能爆longlong,还有一点就是判断logg和LEN的长度关系,因为否则的话下面遍历的时候就炸了。
AC代码:
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<string>
#include<cmath>
#include<cstring>
#define F first
#define S second
#define ll long long
#define pb push_back
#define pm make_pair
using namespace std;
typedef pair<int,int> PII;
const int MAX = 5e5 + 5;
ll a[MAX],I,b[MAX];
int sum[MAX];
ll logg;
int n;
int LEN;
int get(ll x) {
return lower_bound(b+1,b+LEN+1,x) - b;
}
ll qpow(ll a,ll b) {
ll res = 1;
while(b) {
if(b&1) res = res*a;
b>>=1;a=a*a;
}
return res;
}
int main()
{
cin>>n>>I;
I*=8;
ll logg = min(I/n,31*1LL);
logg = qpow(2,logg);
for(int i = 1; i<=n; i++) scanf("%lld",a+i);
sort(a+1,a+n+1);
for(int i = 1; i<=n; i++) b[i] = a[i];
LEN = unique(b+1,b+n+1) - b - 1;
for(int i = 1; i<=n; i++) sum[get(a[i])]++;
for(int i = 1; i<=LEN; i++) {
sum[i] += sum[i-1];
}
if(logg >= LEN) {
printf("0\n");return 0;
}
int out = 0x3f3f3f3f;
for(int i = 1; i<=LEN; i++) {
int l = i;
int ans = i + logg-1;
out = min(out,n - (sum[ans] - sum[i-1]));
}
printf("%d\n",out);
return 0;
}