#include <bits/stdc++.h>
using namespace std;
struct T { // 贪心 优先弹出相邻靠后的材料
int id;
int p;
bool operator < (const T& t) const {
return p < t.p;
}
};
const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
int a[N], sort_a[N], num;
bool isok[N];
int pre[N];
int p[N];
int n, k;
priority_queue<T> q;
inline int f (int x) {
return lower_bound(sort_a + , sort_a + + num, x) - sort_a; // 错误一 离散化后是num
}
int main ()
{
int w; scanf ("%d",&w);
while (w--) {
while (!q.empty()) q.pop();
memset (isok, , sizeof(isok));
scanf ("%d %d",&n,&k);
for (int i = ; i <= n; i++) {
scanf ("%d", &a[i]);
sort_a[i] = a[i];
}
sort (sort_a + , sort_a + + n);
num = ;
for (int i = ; i <= n; i++) {
if (sort_a[i] != sort_a[num])
sort_a[++num] = sort_a[i];
}
int sum = ; int t = ;
for (int i = ; i <= num; i++)
pre[i] = inf;
for (int i = n; i >= ; i--) {
int x = f(a[i]);// pre[i] 元素i最最近出现的位置
p[i] = pre[x];// p[i] a[i] 与a[i]相同元素相邻位置
pre[x] = i;
}
for (int i = ; i <= n; i++) {
int x = f(a[i]);
if (!isok[x]) {
sum++;
if (t < k) {
T temp = {x, p[i]};
q.push(temp); isok[x] = ;
t++;
}
else {
T t1 = q.top(); q.pop(); isok[t1.id] = ;
T temp = {x, p[i]};
q.push(temp); isok[x] = ;
}
}
else {// 错误二: 即使原来在内存中也要去更新它的位置
T temp= {x,p[i]};
q.push(temp);
}
}
printf ("%d\n", sum);
}
return ;
}

链接 : http://codeforces.com/gym/101498/problem/F

codefoce Cooking Time的更多相关文章

  1. cooking构建工具报错MSBUILD :error MSB4132解决办法

    最近学习cooking构建工具的时候,在自己的笔记本上运行的好好的,项目在公司电脑上clone下来的时候,发现构建报错,逐条查错,试了好多方法也不行 最后在github上找到了答案,只是之前一直没找到 ...

  2. CodeForces - 1040B Shashlik Cooking(水题)

    题目: B. Shashlik Cooking time limit per test 1 second memory limit per test 512 megabytes input stand ...

  3. A - Shashlik Cooking CodeForces - 1040B

    http://codeforces.com/problemset/problem/1040/B Long story short, shashlik is Miroslav's favorite fo ...

  4. CodeForces - 1040B Shashlik Cooking

    Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simu ...

  5. 2017浙江省赛 A - Cooking Competition ZOJ - 3958

    地址:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3958 题目: "Miss Kobayashi's Drag ...

  6. Cooking Schedule Problem Code: SCHEDULE(优先队列)

    Cooking Schedule Problem Code: SCHEDULE Chef is a well-known chef, and everyone wishes to taste his ...

  7. Shashlik Cooking

    Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simu ...

  8. selenium+python cooking用法 (转)

    selenium-webdriver(python)--cookie处理 driver.get_cookies() 获得cookie信息 add_cookie(cookie_dict)  向cooki ...

  9. cooking java ——加密解密

    java安全与密码概述 主要分为三部分: 密码学基础,包括:相关术语:分类:常用安全体系. java的安全组成:jdk以及第三方扩展. 相关实现代码,包括:base64.MD5········ 密码学 ...

随机推荐

  1. Linux下使用timedatectl命令时间时区操作详解

    timedatectl命令对于RHEL / CentOS 7和基于Fedora 21+的分布式系统来说,是一个新工具,它作为systemd系统和服务管理器的一部分,代替旧的传统的用在基于Linux分布 ...

  2. sql中,如何获取一个数的整数部分和余数部分

    我们测试一下,我要得到的结果是多少周(整数),多少天(余数) 1.获取指定日期到当前日期之间的天数 首先用DATEDIFF() 函数获取指定日期到当前日期的天数 --获取指定日期到当前日期的天数 se ...

  3. tensorflow之word2vec_basic代码研究

    源代码网址: https://github.com/tensorflow/tensorflow/blob/r1.2/tensorflow/examples/tutorials/word2vec/wor ...

  4. day03 is 与== 常量

    is身份运算:比较的是id是否相等 ==判断值是否相等 ... 值相等id不一定相等 >>>x=1111111111111111111111111111111111111111111 ...

  5. day29 socketsever ftp功能简单讲解

    今日所学 一.ftp上传简单实例 二.socketsever的固定用法 三.验证合法性连接 1.ftp上传实例 这个题目是我们现在网络编程比较基础一点的题目 下面我们只写简单上传的代码 上传服务端的代 ...

  6. tomcat 线程数与 mysql 连接数综合调优

    目前线上系统包含 数据收集+数据分析+中心服务,三个均为 tomcat,共用一个mysql服务. 由于tomcat最大线程数200 *3 =600,最大并发时,会有600个jdbc连接.当然这是极端情 ...

  7. 每天CSS学习之color

    color意为颜色,其作用是设置字体的颜色. 设置颜色的方式有以下几种: 1.使用颜色单词,如:red: 2.使用十六进制,如:#FFFFFF: 3.使用rgb(255,0,0); 让我们来实践一下, ...

  8. swiftlint swift代码规范检查神器

    一大堆的你为什么要用swiftlint,你为什么要codereview,swiftlint到底在做什么,就不多说了,没意义,他就是帮助你写出规范漂亮代码的神器! 安装 官方提供了三种安装的方式 hom ...

  9. json解析写入mysql

    import json,requests,pymysql from pprint import pprint from datetime import datetime dt=datetime.now ...

  10. Activity中通过标签获取当前Fragment

    初始化完成之后才有数据,否则获取不到 String tag = "android:switcher:"+viewPager.getId()+":"+viewPa ...