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 ...
随机推荐
- kali linux 更新软件源,安装中文输入法,修复Linux与windows引导菜单解决windows引导丢失
1. 更新软件源打开sources.list文件,进行添加更新源:leafpad /etc/apt/sources.list 2. 添加软件源#官方源 deb http://http.kali.org ...
- sync命令
sync命令用于强制被改变的内容立刻写入磁盘,更新超块信息. 在Linux/Unix系统中,在文件或数据处理过程中一般先放到内存缓冲区中,等到适当的时候再写入磁盘,以提高系统的运行效率.sync命令则 ...
- 基于QTcpSocket和QTcpServer的Tcp通讯以及QDataStream序列化数据
最近要在QT下开发Tcp通讯,发送序列化数据以便于接收. 这里涉及到几个问题: 1.QTcpSocket.QTcpServer的通讯 2.QDataStream序列化数据 多的不说,直接上干货!!! ...
- was性能调优
数据库设置 使用此页面来指定数据库会话支持的设置. 要查看此管理控制台页面,请单击服务器 > 服务器类型 > WebSphere 应用程序服务器 > server_name > ...
- Vim 配置Markdown
通过vundle工具安装以下插件: vim-markdown 语法高亮 vim-markdown-preview.vim 通过浏览器实时预览(支持同步滚动) -/.vimrc vundle部分添 ...
- PAT (Top Level) Practise 1005 Programming Pattern (35)
后缀数组.排序之后得到height数组,然后从上到下将height>=len的都分为一组,然后找到第一组个数最多的输出即可. #pragma comment(linker, "/STA ...
- java操作cookies
建立一个无生命周期的cookie,即随着浏览器的关闭即消失的cookie,代码如下 HttpServletRequest request HttpServletResponse response Co ...
- undefine refrence to "*******"
windows mingw gcc 编译出现莫名的错误 wsaaddresstostringa, 理解起来,应该是link的时候,出现的问题 (在console的日志栏也能看出来) 然后,在ECL ...
- leetcode83,删除有序链表中的重复元素
Given a sorted linked list, delete all duplicates such that each element appear only once. For examp ...
- akka 文章 博客
http://blog.csdn.net/wsscy2004/article/category/2430395 Actor生命周期理解 Actor生命周期理解 镇图:Actor内功心法图 Actor的 ...