【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

尺取法+二分。
类似滑动窗口。
即左端点为l,右端点为r.
维护a[r]-a[l]+1总是小于等于m的就好。
(大于m就右移左端点)
然后看看里面的数字个数是不是小于k;
不是的话让l..r中最右边那个数字删掉就好。
->链表优化一下即可。

【代码】

/*
1.Shoud it use long long ?
2.Have you ever test several sample(at least therr) yourself?
3.Can you promise that the solution is right? At least,the main ideal
4.use the puts("") or putchar() or printf and such things?
5.init the used array or any value?
6.use error MAX_VALUE?
7.use scanf instead of cin/cout?
8.whatch out the detail input require
*/
/*
sort(a+1,a+1+n);
L[i] = i-1;R[i] = i+1;
一开始l = 1,r = 0,now=0;
然后for (int i = 1;i <= n;i++){
r = i;
now++;
while(l <= r && a[r]-a[l]+1>m){
now--;
l=R[l];
}
if(now >=k){
for (int j = i,k = 1;k<=now-k+1;k++,j=L[j]){
delete(j);
ans++;
}
}
now = k-1;
}
*/
#include <bits/stdc++.h>
using namespace std; const int N = 2e5; int n,m,k;
int a[N+10],L[N+10],R[N+10],ans; void Delete(int pos){ } int main(){
#ifdef LOCAL_DEFINE
freopen("rush_in.txt", "r", stdin);
#endif
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> m >> k;
for (int i = 1;i <= n;i++) cin >> a[i];
sort(a+1,a+1+n);
for (int i = 1;i <= n;i++)
L[i] = i-1,R[i] = i+1; R[0] = 1,L[n+1] = n;
int l = 1,r = 0,now = 0; for (int i = 1;i <= n;i++){
r = i;
now++;
while(l <= r && a[r]-a[l]+1>m){
if (a[l]!=0) now--;
l=R[l];
}
if(now >=k){
a[r] = 0;
int ll = L[r],rr = R[r];
R[ll] = rr;
L[rr] = ll;
now--;
ans++;
} }
cout << ans << endl;
return 0;
}

【Codeforces Round #451 (Div. 2) D】Alarm Clock的更多相关文章

  1. 【Codeforces Round #451 (Div. 2) A】Rounding

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 模拟 [代码] /* 1.Shoud it use long long ? 2.Have you ever test several ...

  2. 【Codeforces Round #451 (Div. 2) B】Proper Nutrition

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 可以直接一层循环枚举. 也可以像我这样用一个数组来存y*b有哪些. 当然.感觉这样做写麻烦了.. [代码] /* 1.Shoud i ...

  3. 【Codeforces Round #451 (Div. 2) C】Phone Numbers

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 用map<string,vector > dic;模拟就好. 后缀.翻转一下就变成前缀了. 两重循环剔除这种情况不输出就 ...

  4. 【Codeforces Round #432 (Div. 1) B】Arpa and a list of numbers

    [链接]h在这里写链接 [题意] 定义bad list是一个非空的.最大公约数为1的序列.给定一个序列,有两种操作:花费x将一个元素删除.花费y将一个元素加1,问你将这个序列变为good list所需 ...

  5. 【Codeforces Round #420 (Div. 2) C】Okabe and Boxes

    [题目链接]:http://codeforces.com/contest/821/problem/C [题意] 给你2*n个操作; 包括把1..n中的某一个数压入栈顶,以及把栈顶元素弹出; 保证压入和 ...

  6. 【Codeforces Round #420 (Div. 2) B】Okabe and Banana Trees

    [题目链接]:http://codeforces.com/contest/821/problem/B [题意] 当(x,y)这个坐标中,x和y都为整数的时候; 这个坐标上会有x+y根香蕉; 然后给你一 ...

  7. 【Codeforces Round #420 (Div. 2) A】Okabe and Future Gadget Laboratory

    [题目链接]:http://codeforces.com/contest/821/problem/A [题意] 给你一个n*n的数组; 然后问你,是不是每个位置(x,y); 都能找到一个同一行的元素q ...

  8. 【Codeforces Round #423 (Div. 2) C】String Reconstruction

    [Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i ...

  9. 【Codeforces Round #423 (Div. 2) B】Black Square

    [Link]:http://codeforces.com/contest/828/problem/B [Description] 给你一个n*m的格子; 里面包含B和W两种颜色的格子; 让你在这个格子 ...

随机推荐

  1. thinkphp里面使用原生php

    thinkphp里面使用原生php Php代码可以和标签在模板文件中混合使用,可以在模板文件里面书写任意的PHP语句代码 ,包括下面两种方式: 使用php标签 例如: {php}echo 'Hello ...

  2. Mysql基础部分,针对以后python使用

    #redis 非关系型数据库#mysql 关系型数据库 表与表之间有数据关系 Oracle Mysql SqlServer DB2#多张表组合在一起就是数据库#冗余 存储两倍数据 可以使系统速度更快 ...

  3. 16.C语言可变参数

    //可变参数实现多个参数求和 1 #define _CRT_SECURE_NO_WARNINGS #include <stdlib.h> #include <stdio.h> ...

  4. BZOJ 1082 暴搜

    思路: //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using ...

  5. How Hystrix Works?--官方

    https://github.com/Netflix/Hystrix/wiki/How-it-Works Contents Flow Chart Circuit Breaker Isolation T ...

  6. [Chromium文档转载,第003章]Proposal: Mojo Synchronous Methods

    Proposal: Mojo Synchronous Methods yzshen@chromium.org 02/02/2016 Overview Currently there are quite ...

  7. 两种方法解决 "The License CNEKJPQZEX- has been cancelled..." 问题

    今天在使用 2017 的 IDEA 和 Pycharm 等IDE的时候,提示了如题的问题.之前实在 http://idea.lanyus.com/ 网站点击生成注册码,复制粘贴到 IDEA 中就好了, ...

  8. Java的位运算符——&0xFF的运算与讲解

    快放元旦假,没心思做啥的事,就去翻以前的代码遇到这句,但是又不懂,所以只好上网找,终于懂了那么一点点. 所以那个大神看到我说的有问题,请指出!谢谢.... 一:首先区分一下 A~F的意思先 A,代表十 ...

  9. i2c tools 使用

    1.查询罗列出I2C的控制器总线数目 # i2cdetect -l i2c-0 i2c OMAP I2C adapter I2C adapter i2c-1 i2c OMAP I2C adapter ...

  10. BRep Shapes Based on Tessellated Geometry

    BRep Shapes Based on Tessellated Geometry eryar@163.com Key Words. BRep Shape, Tessellated Geometry, ...