【LG1368】工艺
【LG1368】工艺
题面
题解
好套路的一道题。。。
我们倍长这个字符串,然后我们要查询的串就为这个倍长过后串的长度\(n\)一个子串,要求字典序最小
然后就可以非常愉快地后缀排序了
后缀的话,直接往每个状态的字典序最小的后继状态跑就行了。
代码
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <map>
using namespace std;
inline int gi() {
register int data = 0, w = 1;
register char ch = 0;
while (!isdigit(ch) && ch != '-') ch = getchar();
if (ch == '-') w = -1, ch = getchar();
while (isdigit(ch)) data = 10 * data + ch - '0', ch = getchar();
return w * data;
}
const int MAX_N = 3e5 + 5;
struct Node {
map<int, int> ch;
int len, fa;
} t[MAX_N << 2];
int tot = 1, lst = 1;
void extend(int c) {
++tot, t[lst].ch[c] = tot;
t[tot].len = t[lst].len + 1;
int p = t[lst].fa; lst = tot;
while (p && t[p].ch.find(c) == t[p].ch.end()) t[p].ch[c] = tot, p = t[p].fa;
if (!p) t[tot].fa = 1;
else {
int q = t[p].ch[c];
if (t[q].len == t[p].len + 1) t[tot].fa = q;
else {
int _q = ++tot; t[_q] = t[q];
t[tot - 1].fa = t[q].fa = _q, t[_q].len = t[p].len + 1;
while (p) {
map<int, int> :: iterator ite;
ite = t[p].ch.find(c);
if (ite == t[p].ch.end() || ite->second != q) break;
t[p].ch[c] = _q;
p = t[p].fa;
}
}
}
}
int N, a[MAX_N];
int main () {
#ifndef ONLINE_JUDGE
freopen("cpp.in", "r", stdin);
freopen("cpp.out", "w", stdout);
#endif
N = gi();
for (int i = 1; i <= N; i++) a[i] = gi();
for (int i = 1; i <= N; i++) extend(a[i]);
for (int i = 1; i <= N; i++) extend(a[i]);
int v = 1;
for (int i = 1; i <= N; i++) {
printf("%d ", t[v].ch.begin()->first);
v = t[v].ch.begin()->second;
}
putchar('\n');
return 0;
}
【LG1368】工艺的更多相关文章
- BZOJ 2882: 工艺
2882: 工艺 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 599 Solved: 268[Submit][Status][Discuss] D ...
- PCB表面处理工艺
PCB表面处理最基本的目的是保证良好的可焊性或电性能.由于自然界的铜在空气中倾向于以氧化物的形式存在,不大可能长期保持为原铜,因此需要对铜进行其他处理. 1.热风整平(喷锡) 热风整平又名热风焊料整平 ...
- 注塑成型工艺知识大全(Injection Molding)
注塑成型,广泛用于热塑性塑料产品的制造工艺 工艺成本:模具费用(高),单件费用(低) 典型产品:汽车塑料部件,消费电子产品塑料外壳等 产量适合:只适合大批量生产 质量:极高的表面精确度,同一批次的产品 ...
- PCB工艺镀金(电金)和沉金(化金)的区别
1.镀金和沉金的别名分别是什么? 镀金:硬金,电金(镀金也就是电金) 沉金:软金,化金 (沉金也就是化金) 2.别名的由来: 镀金:通过电镀的方式,使金粒子附着到pcb板上,所以叫电金,因为附着 ...
- 钣金的折弯成型工艺(Press Braking)
钣金的折弯成型:金属板材的弯曲和成型是在弯板机上进行的,将要成型的板材放置在弯板机上,用升降杠杆将制动片提起,工件滑动到适当的位置,然后将制动片降低到要成型的板材上,通过对弯板机上的弯曲杠杆施力而实现 ...
- 一张图让你看懂锻压、CNC、压铸、冲压四类工艺!
(锻压+CNC+阳极.CNC+阳极.压铸+阳极.冲压+阳极手机外壳比较) 上图为一张雷达图,该图比较直观形象地描述了4大手机外壳工艺在6个维度(加工成本.CNC用量.加工周期.成品率.可设计性.外观质 ...
- 手机金属外壳加工工艺:铸造、锻造、冲压、CNC
现如今金属手机成为行业的热点,在消费电子产品中应用越来越广,本文详细介绍几种金属加工工艺及相关产品应用. 1.CNC+阳极:iPhone 5/6, HTC M7 2.锻造+CNC:华为P8,HTC M ...
- 从iPhone4、iPhone5、iPhone6看手机外壳加工工艺进化史
从iPhone4.iPhone5到iPhone6,苹果为我们推出了一代又一代新产品,让我们享受到最新的科技产品.每次不只是配置上的改变,苹果在工艺上也不断改变.下面就阐述一下我对这几款手机在设计和制造 ...
- BZOJ2882: 工艺
题解: 裸的字符串最小表示... 可以戳这里:http://www.cnblogs.com/ACAC/archive/2010/05/23/1742349.html 这里说一下为什么a[i+k]> ...
随机推荐
- TreeView失去焦点时亮显选中状态
Windows Form下设置属性即可. TreeView.HideSelection = false
- 【three.js练习程序】动画效果,100个方块随机运动
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- pages bookmarks for machine learning domain
http://www.ai-start.com/dl2017/html/lesson4-week2.html 达叔深度学习笔记 http://cs231n.github.io/convolution ...
- 将sqllite3数据库迁移到mysql
一.安装python mysql module (OneDrive): 1.运行python D:\OneDrive\Work\django\mysqlregistry.py2.http://www. ...
- 中式台球 规则 ( ChinaBilliards )
中式台球比赛规则 中式台球兴起于上世纪八十年代末,之前叫法有“中式8球”.“中式9球”.“十六彩”.“美式落袋”.“普尔“.”八球””等等.中国台球协会于2012年宣布统一该项运动称呼,定名为“中式台 ...
- QT的setwindowflags的属性总结
:setWindowFlags(Qt::CustomizeWindowHint);//设置窗口标题栏自定义 setWindowFlags(Qt::WindowMinimizeButtonHint);/ ...
- 【MYSQL】语法复习
一.数据类型 截图来源: http://www.runoob.com/mysql/mysql-data-types.html 二.基本语句 1.创建数据表 -- 主键自增,T_User CREATE ...
- tp5多数据库配置
1.在项目文件下建立extra文件夹,复制dadabase.php改名为database_foo.php,并将从数据库配置信息配置好,如下图: 2.调用 1)调用从数据库$data = Db::con ...
- Win7 user profile cant logon
1.local user:testlb1 1234@cat can login safe model 1.重新启动计算机开机时连续点击F8,选择进入安全模式.2.开始-在搜索栏中输入services. ...
- mysql用户管理与权限
1.设置密码 set password for 用户名@localhost = password('密码'); 2.取消密码 set password for 用户名@localhost = pass ...