日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 1199C】MP3(思维,离散化)

發布時間:2023/12/10 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 1199C】MP3(思维,离散化) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

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?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; }

?

總結

以上是生活随笔為你收集整理的【CodeForces - 1199C】MP3(思维,离散化)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。