#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. 把旧系统迁移到.Net Core 2.0 日记(11) -- Authentication 认证 claimsIdentity 对比 之前的FormAuthentication

    实现最简单的认证,类似之前的FormAuthentication 在 Startup 的 ConfigureServices() 方法中添加 Authentication 的配置: 这个CookieA ...

  2. day03 is 与== 常量

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

  3. Resharper插件安装和破解

    1.首先在最下面的地址,下载Resharper安装包,进行解压安装,安装界面如下: a 2.安装后 解压下载好的 文件 会得到如下: 3.打开序列号 会看到如下所示: 4.然后  复制 %LocalA ...

  4. 51nod1339飞行任务

    首先按照收获从大到小排序. 然后01背包取或者不取即可. 至于为什么这样对的其实我也不知道.... 代码: #include<bits/stdc++.h> using namespace ...

  5. String常用方法

    1. String StringBuffer StringBuilder的区别: 001.在执行速度方法 StringBuilder > StringBuffer > String 002 ...

  6. tomcat 服务器线程问题

    http://blog.csdn.net/wtopps/article/details/71339295 http://blog.csdn.net/wtopps/article/details/713 ...

  7. Web API之路由浅谈

    Web API的路由,是指明接口地址的方向,是照亮获取数据路上的灯塔,其重要性不言而喻. 本篇文章以vs2015为例,一步步说明路由的创建及使用,其中包括默认路由.自定义路由和特性路由. 一.默认路由 ...

  8. zabbix安装部署(server部分)

    Linux下常用的系统监控软件有Nagios.Cacti.Zabbix.Monit等,这些开源的软件,可以帮助我们更好的管理机器,在第一时间内发现,并警告系统维护人员. 今天开始研究下Zabbix,使 ...

  9. DevExpress ASP.NET Core Controls v18.2新功能详解

    行业领先的.NET界面控件2018年第二次重大更新——DevExpress v18.2日前正式发布,本站将以连载的形式为大家介绍新版本新功能.本文将介绍了DevExpress ASP.NET Core ...

  10. L256 翻译

    Should work be placed among the causes of happiness or be regarded as a burden? Much work isexceedin ...