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 - 尺取的更多相关文章

  1. [Codeforces 1199C]MP3(离散化+二分答案)

    [Codeforces 1199C]MP3(离散化+二分答案) 题面 给出一个长度为n的序列\(a_i\)和常数I,定义一次操作[l,r]可以把序列中<l的数全部变成l,>r的数全部变成r ...

  2. Codeforces - 6E - Exposition - 尺取

    https://codeforc.es/problemset/problem/6/E 既然可以多个log,那就直接map伺候.尺取之后要查询区间里面的最大值和最小值的差.众所周知尺取的时候要是不是有序 ...

  3. Codeforces Round #116 (Div. 2, ACM-ICPC Rules) E. Cubes (尺取)

    题目链接:http://codeforces.com/problemset/problem/180/E 给你n个数,每个数代表一种颜色,给你1到m的m种颜色.最多可以删k个数,问你最长连续相同颜色的序 ...

  4. 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 ...

  5. 【尺取或dp】codeforces C. An impassioned circulation of affection

    http://codeforces.com/contest/814/problem/C [题意] 给定一个长度为n的字符串s,一共有q个查询,每个查询给出一个数字m和一个字符ch,你的操作是可以改变字 ...

  6. Codeforces 939E Maximize! (三分 || 尺取)

    <题目链接> 题目大意:给定一段序列,每次进行两次操作,输入1 x代表插入x元素(x元素一定大于等于之前的所有元素),或者输入2,表示输出这个序列的任意子集$s$,使得$max(s)-me ...

  7. 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 ...

  8. 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, ...

  9. Codeforces Round #321 (Div. 2) B. Kefa and Company (尺取)

    排序以后枚举尾部.尺取,头部单调,维护一下就好. 排序O(nlogn),枚举O(n) #include<bits/stdc++.h> using namespace std; typede ...

随机推荐

  1. python+selenium模拟京东登录后台

    python+selenium模拟京东登录后台 import json from time import sleep from selenium import webdriver #from sele ...

  2. vue.js动态表格增删改代码

    新建一个html文件,内容如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8"& ...

  3. POJ 2229 sumset ( 完全背包 || 规律递推DP )

    题意 : 给出一个数 n ,问如果使用 2 的幂的和来组成这个数 n 有多少种不同的方案? 分析 :  完全背包解法 将问题抽象==>有重量分别为 2^0.2^1.2^2…2^k 的物品且每种物 ...

  4. LCA【Tarjan】

    首先,我们先来了解LCA. LCA 是树上两个点最近的公共祖先. 比如说,在如图的树中,3与4的公共祖先有“2”,“1”,但最近的祖先是“2”. 显然,暴力可以做O(n),但是我们希望更快. 现在,有 ...

  5. CodeForces 1197D Yet Another Subarray Problem

    Time limit 2000 ms Memory limit 262144 kB Source Educational Codeforces Round 69 (Rated for Div. 2) ...

  6. 51nod1584加权约数和

    题目大意: 求: \[ \sum_{i-1}^n\sum_{j=1}^nmax(i,j)\sigma(i*j) \] 题解 对于这个\(\max\),套路的把它转化成: \[ 2*\sum_{i=1} ...

  7. vue 通过绑定事件获取当前行的id

    <div @click="router(items.productId)" style="float: left;" :key='items.produc ...

  8. Broken pipe

    出现broken pipe 的一种情况是向socket写数据,但是对端已经关闭socket连接,此时会触发SIGPIPE信号,该信号可以捕获. signal(SIGPIPE, SIG_IGN);

  9. matlab 中 ordfilt2() 函数

    简介: ordfilt2 是一个二维数据过滤器,首先对根据滤窗口中的非零元素对目标矩阵中的元素进行排序,然后用其中第K(通过参数指定)大的元素代替原数据值,并以此过程遍历目标矩阵中的每一个元素. 一. ...

  10. 用Python给头像加上圣诞帽或圣诞老人小图标

    随着圣诞的到来,想给给自己的头像加上一顶圣诞帽.如果不是头像,就加一个圣诞老人陪伴.   用Python给头像加上圣诞帽,看了下大概也都是来自2017年大神的文章:https://zhuanlan.z ...