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. poj 1664 放苹果 递归

    题目链接: http://poj.org/problem?id=1664 题目描述: 有n个苹果,m个盒子,盒子和苹果都没有顺序,盒子可以为空,问:有多少种放置方式? 解题思路: 当前有n个苹果,m个 ...

  2. 2017 JUST Programming Contest 3.0 K. Malek and Summer Semester

    K. Malek and Summer Semester time limit per test 1.0 s memory limit per test 256 MB input standard i ...

  3. 题解报告:hdu 1212 Big Number(大数取模+同余定理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1212 Problem Description As we know, Big Number is al ...

  4. 436 Find Right Interval 寻找右区间

    给定一组区间,对于每一个区间 i,检查是否存在一个区间 j,它的起始点大于或等于区间 i 的终点,这可以称为 j 在 i 的“右侧”.对于任何区间,你需要存储的满足条件的区间 j 的最小索引,这意味着 ...

  5. php之依赖注入和控制反转

      DI——Dependency Injection   依赖注入  IoC——Inversion of Control  控制反转  要想理解上面两个概念,就必须搞清楚如下的问题: 1.参与者都有谁 ...

  6. [BZOJ1025][SCOI2009]游戏 DP+置换群

    题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1025 题目中的排数就是多少次回到原来的序列.很显然对于题目所描述的任意一种对应法则,其中一 ...

  7. 【工具】sublime使用技巧

    Ctrl+N 新建一个编辑区,Ctrl+Shift+C 或!加 Ctrl+E新建一个骨架完好的文件. Ctrl+Shift+P开启命令模式,sshtml 切换html语法. esc退出,Ctrl+`打 ...

  8. 锐动SDK置于社区沙龙

    北京锐动天地信息技术有限公司成立于2007年9月.多年来一直专注于音视频领域核心技术的研发, 拥有Windows.iOS.Android全平台自主知识产权的领先技术产品. 2011年获得新浪战略投资, ...

  9. 使用Jenkins进行android项目的自动构建(5)

    之前在项目中引入的单元测试使用的是JUnit,可以在构建前进行测试,这里在介绍一下使用Instrumentation 进行单元测试.使用Instrumentation进行测试,比之前多一些步骤,需要把 ...

  10. elasticsearch.yml 配置说明

    cluster.name: 指定node所属的cluster. node.name: 本机的hostname. node.master: 是否可以被选举为master节点.(true or false ...