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. "HIBERNATE_SEQUENCE" does not exist问题处理

    JavaWeb应用在MySQL环境下可以正常运行,数据迁移至Oracle或者人大金仓后应用运行爆出如下错误: 严重: Servlet.service() for servlet [JeeCmsAdmi ...

  2. ORA-00020: maximum number of processes (300) exceeded

    SQL> select count(*) from v$session; COUNT(*)---------- 98 SQL> select count(*) from v$process ...

  3. Python基础第一天

    诞生时间:1991年,创造者Guido van Rossum 优点: 1.简单  Python是一种代表简单注意思想的语言 2.易学  Python是及其容易上手,因为Python有极其简单的说明文档 ...

  4. Oracle本地动态 SQL

    本地动态 SQL 首先我们应该了解什么是动态 SQL,在 Oracle数据库开发 PL/SQL块中我们使用的 SQL 分为:静态 SQL语句和动态 SQL语句.所谓静态 SQL指在 PL/SQL块中使 ...

  5. WinForm 对话框,流

    private void button1_Click(object sender, EventArgs e) { //显示颜色选择器 colorDialog1.ShowDialog(); //把取到的 ...

  6. Android 在代码中安装 APK 文件

    废话不说,上代码 private void install(String filePath) { Log.i(TAG, "开始执行安装: " + filePath); File a ...

  7. 5 Transforms 转移 笔记

    5 Transforms 转移 笔记   Transforms    Unfortunately, no one can be told what the Matrix is. You have to ...

  8. Farseer.net轻量级ORM开源框架 V1.x 入门篇:视图的数据操作

    导航 目   录:Farseer.net轻量级ORM开源框架 目录 上一篇:Farseer.net轻量级ORM开源框架 V1.x 入门篇:视图实体类映射 下一篇:Farseer.net轻量级ORM开源 ...

  9. C#枚举中的位运算权限分配

    什么是位运算 常用的位运算主要有与(&), 或(|)和非(~), 比如: & = ; | = ; ~ = ; 运用在权限设计中 先建立一个枚举表示所有的权限管理操作: [Flags] ...

  10. Google浏览器开发者工具:CSSViewer(一个Css查看器)

    CSSViewer的简介 CSSViewer是一款可以帮助用户快速查看当前的网页元素的CSS属性的谷歌浏览器插件,在Chrome中安装了CSSViewer插件以后,用户就可以在设计网页的时候,快速地模 ...