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. 逆序数 UVALive 6508 Permutation Graphs

    题目传送门 /* 题意:给了两行的数字,相同的数字连线,问中间交点的个数 逆序数:第一行保存每个数字的位置,第二行保存该数字在第一行的位置,接下来就是对它求逆序数 用归并排序或线段树求.想到了就简单了 ...

  2. UIAlertController的使用,代替UIAlertView和UIActionSheet

    在iOS8以后,UIAlertView就开始被抛弃了. 取而代之是UIAlertController 以前是警示框这样写: UIAlertView *alert = [[UIAlertView all ...

  3. h5学习-h5嵌入android中

    嵌入Android中的h5界面: 将此页面复制到android项目中的assets目录下边: <!DOCTYPE html> <html lang="en"> ...

  4. js点击修改按钮后修改

    <button id="click">改变内容</button> <div id="t">要改变的内容</div> ...

  5. php socket通信演示以及socket操作类

    准备做Java的课程设计,一个通讯录.采用C/S架构.客户端用java FX和Java,服务器端用php,采用socket通信. 下面来讲一讲php的socket通信: 讲之前,得先讲一下TCP/IP ...

  6. 学习笔记 第九章 使用CSS美化表格

    第9章  使用CSS美化表格 学习重点 正确使用表格标签: 设置表格和单元格属性: 设计表格的CSS样式. 9.1 表格的基本结构 表格由行.列.单元格3部分组成,单元格时行与列交叉的部分. 在HTM ...

  7. 【转】qqface使用实例

    原网址:http://www.xwcms.net/js/bddm/51565.html <div id="show"></div>   <div cl ...

  8. quazip非静态成员。。错误

    转载请注明出处:http://www.cnblogs.com/dachen408/p/7147155.html 问题:quazip非静态成员..错误 解决方案:quazip_global.h  第42 ...

  9. CentOS 7 安装Oracle VirtualBox

    1. 下载VirtualBox的repo文件: 登陆 https://www.virtualbox.org/wiki/Linux_Downloads 在网页的最下端的repo链接上右键下载,或者wge ...

  10. 循环和递归的区别(以前以为递归就是for循环!错的!)

    这里直接上代码!!!! //代码1:(for循环实现的代码) void main() { ; ; i<;i++) { n++; } printf("%d",n); } //代 ...