题目:https://codeforc.es/contest/1209/problem/G1

题意:给你一个序列,要你进行一些操作后把他变成一个好序列,好序列的定义是,两个相同的数中间的数都要与他相同,可以把某一种数统一变成另一个数,问最少变得个数

思路:我们可以考虑贪心,对于一个互相牵扯的区间,我肯定是用总长减掉里面出现次数最多的元素才是最划得来的,我们直接求出这些牵扯区间的长度即可,方法就是我用数组记录每个元素出现最右的位置,然后从左到右遍历,我保留当前区间往右延伸的最长位置,然后减去出现最多即可,累加所有这种联通块

#include<bits/stdc++.h>
#define maxn 200005
#define mod 1000000007
using namespace std;
typedef long long ll;
ll n,q,a[maxn];
ll num[maxn],dex[maxn];
int main(){
cin>>n>>q;
for(int i=;i<=n;i++){
cin>>a[i];
num[a[i]]++;
dex[a[i]]=i;
}
ll l=;
ll ans=,mx=,r=;
for(int i=;i<=n;i++){
r=max(r,dex[a[i]]);
mx=max(mx,num[a[i]]);
if(i==r){
ans+=r-l+-mx;
mx=;l=r+;
r=;
}
}
cout<<ans;
}

Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2) G1. Into Blocks (easy version)的更多相关文章

  1. 状压DP--Rotate Columns (hard version)-- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    题意:https://codeforc.es/problemset/problem/1209/E2 给你一个n(1-12)行m(1-2000)列的矩阵,每一列都可以上下循环移动(类似密码锁). 问你移 ...

  2. Cow and Snacks(吃点心--图论转换) Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    题意:https://codeforc.es/contest/1209/problem/D 有n个点心,有k个人,每个人都有喜欢的两个点心,现在给他们排个队,一个一个吃,每个人只要有自己喜欢的点心就会 ...

  3. Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)

    怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...

  4. Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)C

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;string s;pair<int,in ...

  5. codeforces(Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) )(C,D)

    C. Destroying Array time limit per test 1 second memory limit per test 256 megabytes input standard ...

  6. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) B. Verse Pattern 水题

    B. Verse Pattern 题目连接: http://codeforces.com/contest/722/problem/B Description You are given a text ...

  7. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined)(set容器里count函数以及加强for循环)

    题目链接:http://codeforces.com/contest/722/problem/D 1 #include <bits/stdc++.h> #include <iostr ...

  8. Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) A B C D 水 模拟 并查集 优先队列

    A. Broken Clock time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  9. 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D

    http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ...

随机推荐

  1. mysql索引失效的情况

    1.WHERE字句的查询条件里有不等于号(如:WHERE column!=...),MYSQL将无法使用索引: 2.WHERE字句的查询条件里使用了函数的列(如:WHERE DAY(column)=. ...

  2. 安装PIG

    下载Pig 能够执行在Hadoop 0.20.* http://mirror.bit.edu.cn/apache/pig/pig-0.11.1/pig-0.11.1.tar.gz 也能够依据你的Had ...

  3. Linux shellcode sample

    Linux shellcode sample HelloWorld.nasm ;HelloWorld.asm ;Author: Kul Subedi global _start section .te ...

  4. Gsview裁剪EPS文件

    (1)菜单栏  “options--show bounding boxs”  选中. (2)打开eps图,然后File->PS TO EPS,不选择Automatically calculate ...

  5. yii自定义验证

    自定义验证类 class BaseModel extends Model { public function rules() { return [ ['obj', ContentSecurityVal ...

  6. Echarts常见问题汇总

    关于echarts使用的常见问题总结  来源:李文杨 关于echarts使用的问题总结1.legend图例不显示的问题:在legend中的data为一个数组项,数组项通常为一个字符串,每一项需要对应一 ...

  7. 创建全文索引----SQLserver

    1.启动 Microsoft Search 服务 开始菜单-->SQL程序组-->服务管理器-->下拉筐-->Microsoft Search 服务-->启动它. 2. ...

  8. Chrome中的插件运用

    1. Postman Java后台开发RPC,还没有没有开始和前端联调,只是想自测下这个RPC,但是有时候RPC的访问入参数据量很大,远远超过get方式访问2k(大多数浏览器通常都会限制url长度在2 ...

  9. Delphi 程序调试

  10. 韦东山嵌入式Linux学习笔记07--Nandflash

    常用的flash有两种, Norflash和Nandflash, 前几年市场上的产品比较常见的方案时Norflash和Nandflash搭配使用, 因为norflash比较昂贵,相同的容量norfla ...