#基数排序#CF1654F Minimal String Xoration
分析
有没有一种办法可以将每个 \(j\) 的比较过程同时进行,
可以发现其实这个过程很像后缀排序,实际上只是加号变成了异或,
从低位到高位重新将字符串排名,用同样的方法做到 \(O(2^nn)\)
代码
#include <iostream>
using namespace std;
const int N=300011; string S;
int n,two[N],rk[N],tp[N],Rk[N],M,c[N];
int main(){
ios::sync_with_stdio(0);
cin>>n>>S,two[0]=1;
for (int i=1;i<=n;++i) two[i]=two[i-1]<<1;
for (int i=0;i<two[n];++i) rk[i]=i,tp[i]=S[i]-96;
M=26;
for (int i=1;i<=n;++i){
for (int j=0;j<=M;++j) c[j]=0;
for (int j=0;j<two[n];++j) ++c[tp[rk[j]^two[i-1]]];
for (int j=1;j<=M;++j) c[j]+=c[j-1];
for (int j=two[n]-1;~j;--j) Rk[--c[tp[rk[j]^two[i-1]]]]=rk[j];
for (int j=0;j<=M;++j) c[j]=0;
for (int j=0;j<two[n];++j) ++c[tp[Rk[j]]];
for (int j=1;j<=M;++j) c[j]+=c[j-1];
for (int j=two[n]-1;~j;--j) rk[--c[tp[Rk[j]]]]=Rk[j];
for (int j=0;j<=M;++j) c[j]=0;
Rk[rk[0]]=0;
for (int j=1;j<two[n];++j)
Rk[rk[j]]=Rk[rk[j-1]]+(tp[rk[j]]!=tp[rk[j-1]]||tp[rk[j]^two[i-1]]!=tp[rk[j-1]^two[i-1]]);
for (int j=0;j<two[n];++j) tp[j]=Rk[j];
M=Rk[rk[two[n]-1]];
}
for (int i=0;i<two[n];++i) cout<<S[rk[0]^i];
return 0;
}
#基数排序#CF1654F Minimal String Xoration的更多相关文章
- Codeforces 797C - Minimal string
C. Minimal string 题目链接:http://codeforces.com/problemset/problem/797/C time limit per test 1 second m ...
- Minimal string CodeForces - 797C
Minimal string CodeForces - 797C 题意:有一个字符串s和空串t和u,每次操作可以将s的第一个字符取出并删除然后放到t的最后,或者将t的最后一个字符取出并删除然后放到u的 ...
- CodeForce-797C Minimal string(贪心模拟)
Minimal string CodeForces - 797C Petya 收到一个长度不超过 105 的字符串 s.他拿了两个额外的空字符串 t 和 u 并决定玩一个游戏.这个游戏有两种合法操作: ...
- Minimal string 栈 贪心
time limit per test 1 second memory limit per test 256 megabytes input standard input output standar ...
- CodeForces 797C Minimal string:贪心+模拟
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾 ...
- Minimal string CodeForces – 797C
题目链接 题目难度: 1700rating 题目类型:string+贪心+STL 题目思路: 由于题目要求的最终结果是字典序最小的那个字符串,那么我们从贪心的从’a’开始查找字符串里是否存在,如果存在 ...
- [cf797c]Minimal string(贪心+模拟)
题意: 给出了字符串s的内容,字符串t,u初始默认为空,允许做两种操作: 1.把s字符串第一个字符转移到t字符串最后 2.把t字符串最后一个字符转移到u字符串最后 最后要求s.t字符串都为空,问u字符 ...
- 【codeforces 797C】Minimal string
[题目链接]:http://codeforces.com/contest/797/problem/C [题意] 一开始,给你一个字符串s:两个空字符串t和u; 你有两种合法操作; 1.将s的开头字符加 ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals) C. String Reconstruction 并查集
C. String Reconstruction 题目连接: http://codeforces.com/contest/828/problem/C Description Ivan had stri ...
- Codeforces828 C. String Reconstruction
C. String Reconstruction time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
随机推荐
- Conda简单教程
目录 什么是Conda 安装Conda 虚拟环境管理 模块管理 何时使用Conda 什么是Conda Conda是Python中用于管理包和虚拟环境的一大利器. 使用Conda可以非常便利的使用数据科 ...
- 【Azure 应用服务】Azure Powershell Function 出错 The term 'Connect-AzAccount' is not recognized
问题描述 在Azure Function中,执行Powershell的Function脚本时,先后出现 1:[Error] ERROR: The term 'Connect-AzAccount' is ...
- 【Azure Developer】Java代码访问Key Vault Secret时候的认证问题,使用 DefaultAzureCredentialBuilder 或者 ClientSecretCredentialBuilder
问题描述 使用Java SDK获取Key Vault Secret机密信息时,需要获取授权.通常是使用AAD的注册应用(Client ID, Tenant ID, Client Secret)来获取 ...
- 【Azure 环境】如果Azure中的某一个资源被删除后是否可以查看到删除的记录呢?如Resource Group
问题描述 当一个资源从Azure中删除后,是否有地方可以查看到这些操作的记录呢?如操作人,操作时间等. 问题解答 可以的.通过 Azure订阅页面的活动日志,可以查看所有对订阅下资源的操作记录,包含D ...
- 【Azure 应用服务】如何禁止chinacloudsites.cn 访问?
问题描述 Azure App Service创建后,默认会有一个 Azure App Service创建后,默认会有一个 https://xxxxxxxxxxxxx.chinacloudsites. ...
- 调试 Docker 容器内部进程
首发于官方博客:https://nebula-graph.com.cn/posts/debug-nebula-graph-processes-docker/ 摘要:本文以 Nebula Graph 进 ...
- mysql-对应删除 dict 脚本
-- 1. 此 dict 是在不同租户下的数据字典,查询时需要根据 departid 进行分类查询 -- 2. 删除dict, dict分类主表类型与挂载的子表数据 -- 3. 通过查询到的主表的 g ...
- mysql中innodb创建表的一些限制
1. 背景 在新创建mysql数据表的时候.不太确定表能创建多少个字段,多少个索引.索引多少有限制么?mysql的数据是怎么存储的存在在哪里. 2.基本个数限制 在MySQL5.6.9以后的版本,一个 ...
- 调试分析 Linux 0.00 多任务切换
当执行完 system_interrupt 函数,执行 153 行 iret 时,记录栈的变化情况. 任务0在刚进入system_interrupt函数时(调用中断int 0x80处理程序),栈空间为 ...
- Seata的技术调研
引子 本文不剖析业内分布式组件,只剖析seata这一组件的技术调研.看看是否存在接入价值. 一.概述 Seata 是一款开源的分布式事务解决方案,致力于提供高性能和简单易用的分布式事务服务.Seata ...