四川今天又上热搜了,继南部疫情的未雨绸缪后,龙槽沟是真的倾盆大雨了。我没有兴趣虚伪矫情地对罹难的游人表达同情,因为人与人互不相通徒增谈资;我也没有兴趣居高临下地对擅闯的愚人表达不屑,因为你我皆为乌合之众,在流媒体的灯红酒绿下娱乐至死。地球上最聪明的大脑像条二极管,只能接受最简单的二元判断,稍微复杂的变量就足以使之熔断。基础工作人员与群众大抵是存在着些割裂的,只要就着喇叭喊叫,就一定是在表达“认同你”或“否定你”其一,绝无“陈述事实”一说。学了几十年逻辑,还是顺应情绪,不断窥视大众行为决断,也是,法不责众嘛。有人扭曲身形挤进人群刷安全感,有人刻意和大众对立谋求优越感,殊途原来也是可以同归的呵。

亚当夏娃唉声叹气

达尔文骂骂咧咧地投靠上帝

hash求子串可以O(1),

$click$ $for$ $codes$
# include "bits/stdc++.h"
using namespace std;
constexpr int N = 3e5 + 3;
char str[N], str_new[N << 1];
int main() {
ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
int n;
cin >> n;
unordered_map<unsigned long long, int> mp;
unordered_map<unsigned long long, int> mp2;
unordered_map<unsigned long long, bool> vis[6];
unordered_map<unsigned long long, bool> vis2[6];
int ans = 0;
str_new[0] = '!';
str_new[1] = '@';
for(int i = 1; i <= n; ++i) {
cin >> str + 1;
int len = strlen(str + 1);
int len_new = 1;
for(int j = 1; j <= len; ++j) {
str_new[++len_new] = str[j];
str_new[++len_new] = '@';
}
str_new[++len_new] = '#';
int r = 0, center;
vector<int> p(len_new + 1 << 1);
vector<int> pos;
for(int j = 1; j <= len_new; ++j) {
p[j] = (j < r) ? min(p[(center << 1) - j], r - j) : 1;
while(str_new[j - p[j]] == str_new[j + p[j]]) ++p[j];
if(r < j + p[j]) {
r = j + p[j];
center = j;
}
if(p[j] > 1) pos.push_back(j);
} constexpr unsigned long long base = 122777, mod = 91815541, mod2 = 19260817; // hash value, which is indescibable
vector<unsigned long long> h(len + 1), b(len + 1), h2(len + 1), b2(len + 1);
b[0] = 1, b2[0] = 1;
for(int i = 1; i <= len; ++i) {
h[i] = (h[i - 1] * base % mod + (unsigned long long) str[i]) % mod;
h2[i] = (h2[i - 1] * base % mod2 + (unsigned long long) str[i]) % mod2;
b[i] = b[i - 1] * base % mod;
b2[i] = b2[i - 1] * base % mod2;
}
auto hash = [&](int l, int r) -> unsigned long long {
return (h[r] - h[l - 1] * (unsigned long long)b[r - l + 1] % mod + mod) % mod;
};
auto hash2 = [&](int l, int r) -> unsigned long long { // double hash reduces chance and thus improves accuracy
return (h2[r] - h2[l - 1] * (unsigned long long)b2[r - l + 1] % mod2 + mod2) % mod2;
};
for(auto j : pos) {
int len = p[j];
while(len) {
if((j - len + 2 >> 1) > (j + len - 2 >> 1)) break; // from several manual simulations, we'll find that the palindrome string centered on i in the new string is (i - p[i】 + 2) / 2 ---> (i + p[i] - 2) / 2 in the corresponding position in the original string
unsigned long long sub_str_1 = hash( (j - len + 2 >> 1), (j + len - 2 >> 1) );
unsigned long long sub_str_2 = hash2( (j - len + 2 >> 1), (j + len - 2 >> 1) );
if(vis[i][sub_str_1] == true && vis2[i][sub_str_2] == true) break;
vis[i][sub_str_1] = vis2[i][sub_str_2] = true;
++mp[sub_str_1], ++mp2[sub_str_2];
if(mp[sub_str_1] >= n && mp2[sub_str_2] >= n) ++ ans;
len -= 2; // manachar only directly finds the longest palindrome string, but the string may contain other substrings
if(len < 0) break;
}
}
} cout << ans;
return 0;
}
/*
9999
abcba
abcccba
*/

最新文章

  1. 初学者--bootstrap(四)栅格系统----在路上(8)
  2. Leetcode Trapping Rain Water
  3. 在线代码编辑器CodeMirror简介
  4. 《DSP using MATLAB》示例Example4.14
  5. Gulp自动化工具之图片压缩
  6. jstring, String, char* 变换函数
  7. maven仓库--搭建局域网私服(windows版)
  8. [js] webgl 初探 - 绘制三角形
  9. Java中的Lock锁
  10. Linux System Programming --Chapter Nine
  11. anguments
  12. go/node/python 多进程与多核cpu
  13. oracle 中update多个字段
  14. stm32-arduino-f103
  15. [原创]K8Cscan插件之Web主机扫描(存活主机、机器名、Banner、标题)
  16. 章节四、1-if条件语句
  17. windows 批处理语言学习
  18. 【LOJ】#2494. 「AHOI / HNOI2018」寻宝游戏
  19. 小程序嵌套h5
  20. 第6章—渲染web视图—SpringMVC+Thymeleaf 处理表单提交

热门文章

  1. CSS3:scrollbar样式设置
  2. 《HALCON数字图像处理》第六章笔记
  3. 计算机网络 - HTTP和HTTPS的区别
  4. App上看到就忍不住点的小红点是如何实现的?
  5. SQL Server默认数据库存放位置
  6. ExtJS 布局-Absolute布局(Absolute layout)
  7. 李呈祥:bilibili在湖仓一体查询加速上的实践与探索
  8. WPF开发随笔收录-自定义图标控件
  9. 用python做个计算器不是轻轻松松吗~
  10. docker下node环境搭建