双指针。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int maxn=+;
int n,k,a[maxn],b[maxn];
int cnt[maxn]; int get(int val)
{
int l=,r=n;
int pos=-;
while(l<=r)
{
int mid=(l+r)/;
if(b[mid]>val) r=mid-;
else if(b[mid]<val) l=mid+;
else pos=mid, r=mid-;
}
return pos;
} int main()
{
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
b[i]=a[i];
}
sort(b+,b++n);
for(int i=;i<=n;i++) a[i]=get(a[i]); memset(cnt,,sizeof cnt); int l=,r=; cnt[a[]]++;
long long ans=;
while()
{
if(cnt[a[r]]==k)
{
ans=ans+(long long)(n-r+);
cnt[a[l]]--;
l++;
} else
{
r++;
cnt[a[r]]++;
}
if(l>n||r>n) break; }
printf("%lld\n",ans); return ;
}

CodeForces 190D Non-Secret Cypher的更多相关文章

  1. Day8 - B - Non-Secret Cypher CodeForces - 190D

    Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their nativ ...

  2. Codeforces 590D Top Secret Task

    D. Top Secret Task time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  3. codeforces 966c//Big Secret// Codeforces Round #477 (Div. 1)

    题意:一个数组,重新打乱后前缀异或和递增.问这样的排列. 将所有元素按照二进制最高位分组.每次选当前前缀和sum的二进制最低的0位,再从分组中挑一个作为答案.先放首1在较低位的再放首1在较高位的总是可 ...

  4. [Codeforces 925C]Big Secret

    Description 题库链接 给出 \(n\) 个数,让你生成这 \(n\) 个数的一个排列 \(A\) .定义 \(B_i = \bigoplus\limits_{j=1}^i A_j\) , ...

  5. 【Codeforces 490C】Hacking Cypher

    [链接] 我是链接,点我呀:) [题意] 让你把一个字符串分成左右两个部分 形成两个正数 使得这两个正数一个能被a整除,一个能被b整除 找到任意一个解就可以 [题解] 枚举分割的断点i 枚举的时候用同 ...

  6. 2018省赛赛第一次训练题解和ac代码

    第一次就去拉了点思维很神奇的CF题目 2018省赛赛第一次训练 # Origin Title     A CodeForces 607A Chain Reaction     B CodeForces ...

  7. CodeForces 490C Hacking Cypher

    Hacking Cypher Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Sub ...

  8. CodeForces 496B Secret Combination

    Secret Combination Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u ...

  9. Codeforces Round #279 (Div. 2) C. Hacking Cypher 前缀+后缀

    C. Hacking Cypher time limit per test 1 second memory limit per test 256 megabytes input standard in ...

随机推荐

  1. SpringMVC 的重定向时,参数非法问题

    在重定向时,携带的参数出现非法 /shopping/editShippingAddressCart?cs=0eaa49d6-9c6e-4d02-85d0-40c3c7939207|ef9d80b1-7 ...

  2. python [1:3]

    Python下标是以0开始的x[1:3]表示返回集合中下标1至3(不包括3)的元素集合x[:3] 表示返回从开始到下标3(不包括3)的元素集合x[3:]表示返回从下标3到结束的元素集合X[:]表示返回 ...

  3. SQL 课程

    今天,我主要学习了数据库的基本查询,模糊查询.排序查询.聚合函数.计数和分组,以及数学函数.字符串函数.时间日期函数. create database lianxi0720gouse lianxi07 ...

  4. Python 学习笔记7

    今天很残酷,明天很残酷,后天很美好.但绝大多数人会死在明天的路上.只有真正的勇士才能看到后天的太阳! Python学习是枯燥的.但是一定要坚持! 昨天学习了数据结构和模块. 今天学习输入和输出.错误与 ...

  5. 配置mac自带的Apache服务器

    第一步: 484  cd /etc/apache2 备份httpd.conf文件,以防万一 486  sudo cp httpd.conf httpd.conf.bak 如果操作错误,可以通过 491 ...

  6. ssh environment variable

    1 down vote When you run a command as an argument to ssh, the command is run directly by sshd; the s ...

  7. zendstudio 安装 手册

    安装 http://jingyan.baidu.com/article/b907e627b14fbb46e6891c65.html 选择baidu官方32bit安装 补丁破解网址 http://dwt ...

  8. Struts2--课程笔记3

    获取ServletAPI: 第一种方式: //在request域中放入属性req,暂且认为getContext()获取的是request域空间,但实际不是        ActionContext.g ...

  9. mybatis---------insert,delete ,update的批量操作

    在数据量大的情况下,可以使用批量 提高性能 批量插入insert 方法一: <insert id="insertbatch" parameterType="java ...

  10. Servie之前台Service

    public class MyService extends Service { public static final String TAG = "MyService"; pri ...