Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2) G1. Into Blocks (easy version)
题目: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)的更多相关文章
- 状压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)列的矩阵,每一列都可以上下循环移动(类似密码锁). 问你移 ...
- 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个人,每个人都有喜欢的两个点心,现在给他们排个队,一个一个吃,每个人只要有自己喜欢的点心就会 ...
- Codeforces Round #584 - Dasha Code Championship - Elimination Round (rated, open for everyone, Div. 1 + Div. 2)
怎么老是垫底啊. 不高兴. 似乎 A 掉一道题总比别人慢一些. A. Paint the Numbers 贪心,从小到大枚举,如果没有被涂色,就新增一个颜色把自己和倍数都涂上. #include< ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 二分 Intel Code Challenge Elimination Round (Div.1 + Div.2, combined) D
http://codeforces.com/contest/722/problem/D 题目大意:给你一个没有重复元素的Y集合,再给你一个没有重复元素X集合,X集合有如下操作 ①挑选某个元素*2 ②某 ...
随机推荐
- [NAIPC2016]Jewel Thief(决策单调性+分治)
[NAIPC2016]Jewel Thief(决策单调性+分治) 题面 原题提交地址(题目编号H) 原题面下载地址 有\(n\)个物品,每个物品有一个体积\(w_i\)和价值\(v_i\),现在要求对 ...
- 多进程-Pool进程池
from multiprocessing import Pool import os,time def Foo(i): time.sleep(2) print("in process&quo ...
- Springboot提示数据库连接问题Connection is not available
2019-05-29 11:19:51.824 WARN 854 --- [io-8080-exec-10] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL ...
- 三维数点的CDQ分治板子
int n, k, tot; struct _ {int x,r,f;} a[N]; struct __ { int type; ll x,y; bool operator < (const _ ...
- 17、RAID和LVM
一.RAID 1.什么是raid 磁盘阵列(Redundant Arrays of Independent Drives,RAID),有"独立磁盘构成的具有冗余能力的阵列"之意. ...
- table 边框问题
对table设置css样式边框,分为几种情况:1.只对table设置边框2.对td设置边框3.对table和td技巧性设置表格边框4.对table和td设置背景,实现完美表格边框 以下DIVCSS5对 ...
- No training required: Exploring random encoders for sentence classification(解析)
原文链接:https://arxiv.org/abs/1901.10444 发表在:ICLR 2019 ------------------------------------------------ ...
- Linux基本命令之Vim
在vim,vi,gedit编辑器中显示行号: 在命令模式下:set nu 取消行号:set nonu 参照博客:https://www.cnblogs.com/Mr0wang/p/728 ...
- springboot+elasticsearch 报错
错误1: .d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsear ...
- Kattis - itsamodmodmodmodworld It's a Mod, Mod, Mod, Mod World (类欧几里得)
题意:计算$\sum\limits_{i=1}^n[(p{\cdot }i)\bmod{q}]$ 类欧模板题,首先作转化$\sum\limits_{i=1}^n[(p{\cdot}i)\bmod{q} ...