CodeForces 190D Non-Secret Cypher
双指针。
#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的更多相关文章
- 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 ...
- Codeforces 590D Top Secret Task
D. Top Secret Task time limit per test 3 seconds memory limit per test 256 megabytes input standard ...
- codeforces 966c//Big Secret// Codeforces Round #477 (Div. 1)
题意:一个数组,重新打乱后前缀异或和递增.问这样的排列. 将所有元素按照二进制最高位分组.每次选当前前缀和sum的二进制最低的0位,再从分组中挑一个作为答案.先放首1在较低位的再放首1在较高位的总是可 ...
- [Codeforces 925C]Big Secret
Description 题库链接 给出 \(n\) 个数,让你生成这 \(n\) 个数的一个排列 \(A\) .定义 \(B_i = \bigoplus\limits_{j=1}^i A_j\) , ...
- 【Codeforces 490C】Hacking Cypher
[链接] 我是链接,点我呀:) [题意] 让你把一个字符串分成左右两个部分 形成两个正数 使得这两个正数一个能被a整除,一个能被b整除 找到任意一个解就可以 [题解] 枚举分割的断点i 枚举的时候用同 ...
- 2018省赛赛第一次训练题解和ac代码
第一次就去拉了点思维很神奇的CF题目 2018省赛赛第一次训练 # Origin Title A CodeForces 607A Chain Reaction B CodeForces ...
- CodeForces 490C Hacking Cypher
Hacking Cypher Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Sub ...
- CodeForces 496B Secret Combination
Secret Combination Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u ...
- 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 ...
随机推荐
- if语句—交互程序二
参考:<笨方法学Python>—习题31 用了两个嵌套的if语句! # coding: utf-8 print u"欢迎来到玩家国度, 你需要根据提示完成闯关!" # ...
- E - Triangle
Description Johnny has a younger sister Anne, who is very clever and smart. As she came home from th ...
- 12C CLONE PDB and config service_listener
Clone PDB PtestDEV to Ptestuat in testuat 1) Clone PtestDEV to Ptestuat C:\Windows\system32> ...
- windows禅道环境搭建
zentao官网的几个网址 http://www.zentao.net/ http://www.zentao.net/article-view-79863.html 搭建环境需要下载两个文件 1) ...
- MFC中组合框CComboBox的使用
假如添加三行数据,其中当选择前两行时,提示自定义提示框信息,选择第三行时,提示当前字符串的内容,实现如下: void Cuse_demo_dllDlg::OnCbnSelchangeCombo1(){ ...
- mvc VIEW部分介绍
因为如果在view页面中的路径直接写死为<from action="/Home/Save" method="post">那么当Global.asax ...
- flash检测网络是否通畅
air: 要在 Adobe ® Flash ® Professional(CS4 或更高版本)中使用 air.net 包: 选择“文件”>“发布设置”命令. 在 Flash 面板中,单击 Act ...
- sublime Text 常用操作
原文出处:http://www.php100.com/html/it/focus/2014/1030/7666.html 1. 多光标操作:只要按下Cmd(Windows系统下Ctrl)键,再用鼠标选 ...
- 对象之function
开头啰嗦几句:程序之中,万事万物皆对象,这就是面向对象编程的核心思想,比如我们的js中的function,其实也是一个对象,是对象就可以有属性,在jq的源码中经常看到类似这样的方法: jQuery.E ...
- Error configuring application listener of class 报错 解决
Error configuring application listener of class 次错误是由于工程没有贬义Class文件造成的,clean一下编译一下工程,clean之后进入项目目录查看 ...