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 ...
随机推荐
- 【leetcode】1144. Decrease Elements To Make Array Zigzag
题目如下: Given an array nums of integers, a move consists of choosing any element and decreasing it by ...
- 【leetcode】Smallest Rotation with Highest Score
题目如下: Given an array A, we may rotate it by a non-negative integer K so that the array becomes A[K], ...
- 对npm的认识
npm由三个不同的组件组成:1,网站 2.命令行界面(CLI)3.注册表 需要在网站注册 命令行界面用来进行交互 注册表来进行保存 安装本地软件包 npm install 包名 更新本地软件包 npm ...
- SQL server 统计分组经计
SUM(A.AREA) OVER ( PARTITION BY A.ItemNo, A.PARTS ,A.WIDTH,A.HEIGHT) allotQty, SUM(A.SL) OVER ( PART ...
- 51Nod 1277 字符串中的最大值 ( KMP && DP )
题意 : 一个字符串的前缀是指包含该字符第一个字母的连续子串,例如:abcd的所有前缀为a, ab, abc, abcd.给出一个字符串S,求其所有前缀中,字符长度与出现次数的乘积的最大值.例如:S ...
- Error:MySQLAdministrator无法连接到实例
Q:利用MySQLAdministrator登录时显示could not connect to the specific instance,使用ping指令后可以ping通,如下所示: A:这里能够p ...
- Java——this
[this] 在没有new一个对象前,this不知道指的是什么:当new出一个对象时,this指的是当前对象的引用.
- 进阶1:Linux 环境准备_ 设置网络IP_安装火狐浏览器
VM 已安装 centos6.5 Final 已安装 配置好了Linux IP ,并能ping 通 ,例如 : ping www.baidu.com 设置LINUX 网络IP: https://j ...
- Oracle Where子句
Oracle Where子句 作者:初生不惑 Oracle基础 评论:0 条 Oracle技术QQ群:175248146 在本教程中,将学习如何使用Oracle WHERE子句来指定过滤的条件返回符合 ...
- Collections 索引
About Me NOIp 数据结构专题总结 NOIp 图论算法专题总结 NOIp 基础数论知识点总结 NOIp 数学知识点总结 搜索算法总结 (不包含朴素 DFS, BFS) 位运算 字符串算法总结 ...