Jingles of a String

Time Limit: 2000ms
Memory Limit: 524288KB

This problem will be judged on CodeForcesGym. Original ID: 100524J
64-bit integer IO format: %I64d      Java class name: (Any)

 
 
解题:题目很厉害啊!借鉴某大牛的思路。
 
由于都是小写字母,所以对任意一个区间,最多只有26个,用二进制表示该区间出现过的字母
 
然后就是固定一个左边界,可以算出左边界到字符串末这区间中1个个数,那么枚举这些1的个数,进行二分查找出现这么多个1的区间的最大右边界。
 
RMQ st可以这么用,也是涨姿势了
 #include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int maxn = ;
int st[maxn][];
char str[maxn];
int query(int L,int R) {
int lg = - __builtin_clz(R - L + );
return st[L][lg]|st[R - (<<lg) + ][lg];
}
unordered_map<int,int>ump;
int main() {
#define NAME "jingles"
freopen(NAME".in","r",stdin);
freopen(NAME".out","w",stdout);
int kase;
scanf("%d",&kase);
while(kase--) {
scanf("%s",str);
int len = strlen(str);
for(int i = ; i < len; ++i)
st[i][] = <<(str[i] - 'a');
for(int j = ; (<<j) <= len; ++j) {
for(int i = ; i + (<<j) <= len; ++i)
st[i][j] = st[i][j-]|st[i+(<<(j-))][j-];
}
ump.clear();
for(int i = ; i < len; ++i) {
int x = query(i,len - );
ump[x] = max(ump[x],len - i);
int cnt = __builtin_popcount(x);
for(int j = ; j < cnt; ++j) {
int low = i,high = len-,ret;
while(low <= high) {
int mid = (low + high)>>;
int y = __builtin_popcount(query(i,mid));
if(y <= j) {
low = mid + ;
ret = mid;
} else high = mid - ;
}
ump[query(i,ret)] = max(ump[query(i,ret)],ret - i + );
}
}
LL ans = ;
for(auto &it:ump)
ans += __builtin_popcount(it.first)*(LL)it.second;
printf("%d %I64d\n",ump.size(),ans);
}
return ;
}

CodeForcesGym 100524J Jingles of a String的更多相关文章

  1. CodeForcesGym 100735H Words from cubes

    Words from cubes Time Limit: Unknown ms Memory Limit: 65536KB This problem will be judged on CodeFor ...

  2. CodeForcesGym 100735G LCS Revised

    LCS Revised Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on CodeForcesGym. O ...

  3. CodeForcesGym 100641B A Cure for the Common Code

    A Cure for the Common Code Time Limit: 3000ms Memory Limit: 262144KB This problem will be judged on  ...

  4. CodeForcesGym 100548G The Problem to Slow Down You

    The Problem to Slow Down You Time Limit: 20000ms Memory Limit: 524288KB This problem will be judged ...

  5. CodeForcesGym 100676G Training Camp

    G. Training Camp Time Limit: 1000ms Memory Limit: 262144KB This problem will be judged on CodeForces ...

  6. 透过WinDBG的视角看String

    摘要 : 最近在博客园里面看到有人在讨论 C# String的一些特性. 大部分情况下是从CODING的角度来讨论String. 本人觉得非常好奇, 在运行时态, String是如何与这些特性联系上的 ...

  7. JavaScript String对象

    本编主要介绍String 字符串对象. 目录 1. 介绍:阐述 String 对象的说明以及定义方式. 2. 实例属性:介绍 String 对象的实例属性: length. 3. 实例方法:介绍 St ...

  8. ElasticSearch 5学习(9)——映射和分析(string类型废弃)

    在ElasticSearch中,存入文档的内容类似于传统数据每个字段一样,都会有一个指定的属性,为了能够把日期字段处理成日期,把数字字段处理成数字,把字符串字段处理成字符串值,Elasticsearc ...

  9. [C#] string 与 String,大 S 与小 S 之间没有什么不可言说的秘密

    string 与 String,大 S 与小 S 之间没有什么不可言说的秘密 目录 小写 string 与大写 String 声明与初始化 string string 的不可变性 正则 string ...

随机推荐

  1. Linux磁盘分区、格式化和挂载

    一.查看磁盘使用 [root@iZ88rvassw1Z ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/vda1 40G .3G 3 ...

  2. C#画图——Graphics

    C#要实现简单的画图功能可以利用Graphics这个类,要使用Graphics必需using命名空间System.Drawing(此名明空间下都是关于图形的操作).首先创建画布: Bitmap bmp ...

  3. 静态代理,jdbc动态代理和cglib动态代理

    静态代理 1.定义抽象主题接口. package com.zhangguo.Spring041.aop02; /** * 接口 * 抽象主题 */ public interface IMath { / ...

  4. AJPFX: Java基础多线程(一)

    多线程是Java学习的非常重要的方面,是每个Java程序员必须掌握的基本技能.本文只是多线程细节.本质的总结,并无代码例子入门,不适合初学者理解.初学者学习多线程,建议一边看书.看博文,以便写代码尝试 ...

  5. 微信小程序组件解读和分析:七、button按钮

    button按钮组件说明: button,顾名思义,按钮,类似于html的button标签.我们可以设置按钮的属性,比如字体颜色大小,背景颜色等,可以给按钮绑定事件,用户点击时会触发事件. butto ...

  6. apache反向代理配置

    apache简单的反向代理配置 Proxypass /api /http://locahost:3000 反向代理-1.jpg

  7. Farseer.net轻量级ORM开源框架 V1.x 入门篇:视图实体类映射

    导航 目   录:Farseer.net轻量级ORM开源框架 目录 上一篇:Farseer.net轻量级ORM开源框架 V1.x 入门篇:表的数据操作 下一篇:Farseer.net轻量级ORM开源框 ...

  8. JPA createNativeQuery遇到的几个问题

    1.count方法返回值类型为java.math.BigInteger Query query = null; String sql = null; sql = "select count( ...

  9. 新建 vue项目时报错,无法成功搭建项目

    之前电脑已经安装 Node环境和 vue-cli脚手架,但是过段时间没有使用,然后现在用 vue-cli 搭建项目的时候,启动服务器的时候报错,无法启动成功,摸索半天,发现是因为 Node和vue-c ...

  10. leetcode_650. 2 Keys Keyboard_dp

    https://leetcode.com/problems/2-keys-keyboard/ 初始一个A,两种操作,复制当前所有A,粘贴,问得到n个A最少需要多少步操作. class Solution ...