LOJ#3103. 「JSOI2019」节日庆典

能当最小位置的值一定是一个最小后缀,而有用的最小后缀不超过\(\log n\)个

为什么不超过\(\log n\)个,看了一下zsy的博客。。

假如\(i = AAB\),\(j = AB\),\(B\)是\(A\)的一个严格前缀,\(|j| < |i| < 2|j|\)

但是有\(k = B\),导致了若\(j\)比\(i\)优,则\(k\)会比\(j\)优,\(j\)比\(k\)优,则\(i\)会比\(j\)优,那么\(j\)就没用了

然后取这\(\log\)里最大的就是一段后缀和开头比较,可以预处理出每个串和开头的lcp,用扩展kmp

#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define ba 47
#define MAXN 5005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
res = 0;T f = 1;char c = getchar();
while(c < '0' || c > '9') {
if(c == '-') f = -1;
c = getchar();
}
while(c >= '0' && c <= '9') {
res = res * 10 +c - '0';
c = getchar();
}
res *= f;
}
template<class T>
void out(T x) {
if(x < 0) {x = -x;putchar('-');}
if(x >= 10) {
out(x / 10);
}
putchar('0' + x % 10);
}
char s[3000006];
int L,lcp[3000006];
bool cmp(int l0,int r0,int l1,int r1) {
if(r0 < l0) return true;
if(r1 < l1) return false;
int l = min(lcp[l0],min(r1,r0 - l0 + 1));
if(s[l0 + l] <= s[l1 + l]) return true;
return false;
}
void Solve() {
scanf("%s",s + 1);
L = strlen(s + 1);
lcp[1] = L;int p = 0,r = 0;
for(int i = 2 ; i <= L ; ++i) {
int t = 0;
if(r >= i) t = min(r - i + 1,lcp[i - p + 1]);
while(i + t <= L && s[t + 1] == s[i + t]) ++t;
lcp[i] = t;
if(r < i + t - 1) {p = i;r = i + t - 1;}
}
vector<int> f;f.clear();
for(int i = 1 ; i <= L ; ++i) {
vector<int> g;g.clear();g.pb(i);
for(auto t : f) {
while(g.size() && s[t + i - g.back()] < s[i]) g.pop_back();
if(g.size() == 0 || s[t + i - g.back()] == s[i]) {
while(g.size() && i - t + 1 <= 2 * (i - g.back() + 1)) g.pop_back();
g.pb(t);
}
}
f = g;
int res = f[0];
for(int j = 1 ; j < f.size() ; ++j) {
if(cmp(f[j] + i - res + 1,res - 1,1,res - f[j] - 1)) res = f[j];
}
out(res);space;
}
enter;
}
int main(){
#ifdef ivorysi
freopen("f1.in","r",stdin);
#endif
Solve();
}

【LOJ】#3103. 「JSOI2019」节日庆典的更多相关文章

  1. LOJ #3103. 「JSOI2019」节日庆典

    题意 给定字符串 \(S\) ,对于 \(S\) 的每个前缀 \(T\) 求 \(T\) 所有循环同构串的字典序最小的串,输出其起始下标.(如有多个输出最靠前的) \(|S| \le 3 \times ...

  2. Loj #3102. 「JSOI2019」神经网络

    Loj #3102. 「JSOI2019」神经网络 题目背景 火星探险队发现,火星人的思维方式与人类非常不同,是因为他们拥有与人类很不一样的神经网络结构.为了更好地理解火星人的行为模式,JYY 对小镇 ...

  3. 【LOJ】#3102. 「JSOI2019」神经网络

    LOJ#3102. 「JSOI2019」神经网络 首先我们容易发现就是把树拆成若干条链,然后要求这些链排在一个环上,同一棵树的链不相邻 把树拆成链可以用一个简单(但是需要复杂的分类讨论)的树背包实现 ...

  4. 【LOJ】#3101. 「JSOI2019」精准预测

    LOJ#3101. 「JSOI2019」精准预测 设0是生,1是死,按2-sat连边那么第一种情况是\((t,x,1) \rightarrow (t + 1,y,1)\),\((t + 1,y, 0) ...

  5. Loj #2568. 「APIO2016」烟花表演

    Loj #2568. 「APIO2016」烟花表演 题目描述 烟花表演是最引人注目的节日活动之一.在表演中,所有的烟花必须同时爆炸.为了确保安全,烟花被安置在远离开关的位置上,通过一些导火索与开关相连 ...

  6. Loj #2192. 「SHOI2014」概率充电器

    Loj #2192. 「SHOI2014」概率充电器 题目描述 著名的电子产品品牌 SHOI 刚刚发布了引领世界潮流的下一代电子产品--概率充电器: 「采用全新纳米级加工技术,实现元件与导线能否通电完 ...

  7. Loj #3096. 「SNOI2019」数论

    Loj #3096. 「SNOI2019」数论 题目描述 给出正整数 \(P, Q, T\),大小为 \(n\) 的整数集 \(A\) 和大小为 \(m\) 的整数集 \(B\),请你求出: \[ \ ...

  8. Loj #3093. 「BJOI2019」光线

    Loj #3093. 「BJOI2019」光线 题目描述 当一束光打到一层玻璃上时,有一定比例的光会穿过这层玻璃,一定比例的光会被反射回去,剩下的光被玻璃吸收. 设对于任意 \(x\),有 \(x\t ...

  9. Loj #3089. 「BJOI2019」奥术神杖

    Loj #3089. 「BJOI2019」奥术神杖 题目描述 Bezorath 大陆抵抗地灾军团入侵的战争进入了僵持的阶段,世世代代生活在 Bezorath 这片大陆的精灵们开始寻找远古时代诸神遗留的 ...

随机推荐

  1. 51nod 1086

    https://www.cnblogs.com/TnT2333333/p/6879709.html 二进制优化多重背包 怎么用二进制优化多重背包,举一个例子就明白了. 如果要放n个苹果,可以将n个苹果 ...

  2. Ajax请求如何设置csrf_token

    1. 方式一 通过获取隐藏的input标签中的csrfmiddlewaretoken值,放置在data中发送. $.ajax({ url: "/cookie_ajax/", typ ...

  3. 使用Android手机作为树莓派的屏幕

    在使用树莓派时,有时出于应急,身边没有屏幕,或者外出携带时也不方便带着屏幕走.如果能使用随身携带的智能手机当做其屏幕,则会方便许多.看看效果,一个树莓派+充电宝+手机,就会非常有用了. 满足以下条件即 ...

  4. An error occurred while starting a transaction on the provider connection. See the inner exception for details.

    用EntityFramework循环操作数据时,报了如下错误 An error occurred while starting a transaction on the provider connec ...

  5. 黑马vue---28、vue中全局过滤器的基本使用

    黑马vue---28.vue中全局过滤器的基本使用 一.总结 一句话总结: vue中的过滤器可以传递参数(根据参数来过滤),也可以用管道符拼接多个过滤器:例如<p>{{ msg | msg ...

  6. ubantu 安装boost库 c++connector

    安装libmysqlcppconn: sudo apt-get install libmysqlcppconn-dev 安装libboost: sudo apt-get install libboos ...

  7. ARP Poisoning Attack and Mitigation Techniques ARP欺骗 中间人攻击 Man-In-The-Middle (MITM) attack 嗅探 防范 Can one MAC address have two different IP addresses within the network?

    小结: 1. ARP缓存投毒,窃听中毒者之间的通信: 2. ARP Poisoning Attack and Mitigation Techniques - Ciscohttps://www.cisc ...

  8. 智能指针-共享式shared_ptr

    #include <iostream>#include <string>#include <vector>#include <memory> using ...

  9. 防止sshd服务被暴力破解

    方法有很多种,这里介绍两种. (1).配置安全的shhd设置 不允许root用户直接登录到系统,添加一个普通用户,必要时再切换到root用户. 修改默认端口号. 不允许密码登录,只能通过密钥登录系统. ...

  10. 建立第一个Django工程---linux中的python

    建立第一个Django工程 环境: ip: 192.168.0.92 系统:centos7.5 安装django pip install django 启动一个HelloWorld工程 django- ...