Codeforces - 1199C - MP3 - 尺取
https://codeforc.es/contest/1199/problem/C
擦,最后移位运算符溢出了,真的蠢。
肯定是选中间的连续的某段是最优的,维护这个段的长度和其中的元素种类就可以了。小心x可能很大导致溢出。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read() {
int x = 0;
int f = 0;
char c;
do {
c = getchar();
if(c == '-')
f = 1;
} while(c < '0' || c > '9');
do {
x = (x << 3) + (x << 1) + c - '0';
c = getchar();
} while(c >= '0' && c <= '9');
return f ? -x : x;
}
inline void _write(int x) {
if(x > 9)
_write(x / 10);
putchar(x % 10 + '0');
}
inline void write(int x) {
if(x < 0) {
putchar('-');
x = -x;
}
_write(x);
putchar('\n');
}
int n, I, x, len;
int a[400005];
map<int, int> m;
int main() {
#ifdef Yinku
freopen("Yinku.in", "r", stdin);
#endif // Yinku
n = read(), I = read();
x = (8 * I) / n;
if(x >= 30)
x = 30;
len = (1 << x);
for(int i = 1; i <= n; ++i)
a[i] = read();
sort(a + 1, a + 1 + n);
int l = 1, r = 1;
m[a[1]]++;
int cnt1 = 1, cnt2 = 1, ans = n - 1;
while(r < n) {
r++;
int t = m[a[r]]++;
cnt2++;
if(t == 0)
cnt1++;
while(cnt1 > len) {
int tmp = m[a[l]]--;
if(tmp == 1)
cnt1--;
l++;
cnt2--;
}
ans = min(ans, n - cnt2);
}
printf("%d\n", ans);
}
Codeforces - 1199C - MP3 - 尺取的更多相关文章
- [Codeforces 1199C]MP3(离散化+二分答案)
[Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...
- Codeforces - 6E - Exposition - 尺取
https://codeforc.es/problemset/problem/6/E 既然可以多个log,那就直接map伺候.尺取之后要查询区间里面的最大值和最小值的差.众所周知尺取的时候要是不是有序 ...
- Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)
题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...
- Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot 【二分 + 尺取】
任意门:http://codeforces.com/contest/1073/problem/C C. Vasya and Robot time limit per test 1 second mem ...
- 【尺取或dp】codeforces C. An impassioned circulation of affection
http://codeforces.com/contest/814/problem/C [题意] 给定一个长度为n的字符串s,一共有q个查询,每个查询给出一个数字m和一个字符ch,你的操作是可以改变字 ...
- Codeforces 939E Maximize! (三分 || 尺取)
<题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...
- B. Complete the Word(Codeforces Round #372 (Div. 2)) 尺取大法
B. Complete the Word time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Educational Codeforces Round 53 (Rated for Div. 2) C. Vasya and Robot(二分或者尺取)
题目哦 题意:给出一个序列,序列有四个字母组成,U:y+1,D:y-1 , L:x-1 , R:x+1; 这是规则 . 给出(x,y) 问可不可以经过最小的变化这个序列可以由(0,0) 变到(x, ...
- Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)
排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...
随机推荐
- Python内置函数之filter map reduce
Python内置函数之filter map reduce 2013-06-04 Posted by yeho Python内置了一些非常有趣.有用的函数,如:filter.map.reduce,都是对 ...
- MAN RPM
RPM(8) Red Hat Linux RPM(8) NAME/名称 rpm - RPM Package Manager/RPM-RPM包管理器SYNOPSIS/简介 QUER ...
- vueroute的router.addRoutes
router.addRoutes(routes: Array<RouteConfig>)动态添加更多路由到路由器.参数必须是使用与routes构造函数选项相同的路径配置格式的Array .
- 关于Vuex的actions传入多个参数的方法:
1.在state中: state={ obj:{ name:'state中的数据' } } 2.在actions定义的方法中: ...
- 理解厂商前缀 -webkit- / -moz- / -ms- / -o-
CSS3规范如果想要达到W3C的推荐标准状态还需要不断改进.浏览器则通常在W3C开发标准的过程中就会体现这些特性.这样,标准在最终敲定之前就能知道哪些地方还能进一步改进. 在包含某个特性的的初始阶段, ...
- KNN算法之KD树
KD树算法是先对数据集进行建模,然后搜索最近邻,最后一步是预测. KD树中的K指的是样本特征的维数. 一.KD树的建立 m个样本n维特征,计算n个特征的方差,取方差最大的第k维特征作为根节点.选择第k ...
- 嵌入QQ聊天
<a href="http://wpa.qq.com/msgrd?V=1&Uin=1178321443&Site=http://www.nanfangjiadian.c ...
- VMware 15 搭建MacOS 10.14教程
写于2018.12.23 教程原文链接:https://pan.baidu.com/s/1wvNYg_MQH_lwewKbpCQ5_Q ———————————————————————————————— ...
- spring- junit测试事务回滚
http://blog.csdn.net/molingduzun123/article/details/49383235
- Spring Data JPA开发中遇到的问题1:org.hibernate.hql.internal.ast.QuerySyntaxException: DispatchShift is not mapped
org.hibernate.hql.internal.ast.QuerySyntaxException: T_D_SHIFT_DISPATCH is not mapped 错误原因: 没有映射到表,经 ...