博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
BZOJ 4516: [Sdoi2016]生成魔咒
阅读量:4965 次
发布时间:2019-06-12

本文共 3257 字,大约阅读时间需要 10 分钟。

二次联通门 : 

 

 

 

 

/*    BZOJ 4516: [Sdoi2016]生成魔咒    调了整整一天啊。。。    绝望啊        最后发现是1打成i了啊!!!     */#include 
#include
#include
#include
#include
const int BUF = 10000020;char Buf[BUF], *buf = Buf;void read (int &now){ for (now = 0; !isdigit (*buf); ++ buf); for (; isdigit (*buf); now = now * 10 + *buf - '0', ++ buf);}#define Max 200005int sa[Max], __rank[Max], height[Max];int str_1[Max], str_2[Max];int c[Max];inline void Swap (int *&x, int *&y){ int *now = x; x = y; y = now;}inline int min (int a, int b){ return a < b ? a : b;}void D (){ putchar ('\n'); for (int i = 1; i <= 10; i ++) printf ("%d ", sa[i]); putchar ('\n');}void Build_Sa (int *line, int N, int M){ static int *x = str_1, *y = str_2; register int i, pos; for (i = 0; i < M; c[i ++] = 0); for (i = 0; i < N; c[x[i] = line[i]] ++, ++ i); for (i = 1; i < M; c[i] += c[i - 1], ++ i); for (i = N - 1; i >= 0; sa[-- c[x[i]]] = i, i --); for (int j = 1; pos < N; j <<= 1, M = pos) { for (i = N - j, pos = 0; i < N; y[pos ++] = i ++); for (i = 0; i < N; ++ i) if (sa[i] >= j) y[pos ++] = sa[i] - j; for (i = 0; i < M; c[i ++] = 0); for (i = 0; i < N; ++ c[x[y[i]]], ++ i); for (i = 0; i < M; c[i] += c[i - 1], ++ i); for (i = N - 1; i >= 0; sa[-- c[x[y[i]]]] = y[i --]); Swap (x, y), pos = 1, x[sa[0]] = 0; for (i = 1; i < N; ++ i) x[sa[i]] = y[sa[i]] == y[sa[i - 1]] && y[sa[i] + j] == y[sa[i - 1] + j] ? pos - 1 : pos ++; } int j; for (i = 1; i < N; __rank[sa[i]] = i, ++ i); for (i = 0, pos = 0; i < N - 1; height[__rank[i ++]] = pos) for (pos ? pos -- : 0, j = sa[__rank[i] - 1]; line[i + pos] == line[j + pos]; ++ pos);}inline int max (int a, int b){ return a > b ? a : b;}int number[Max], level[Max];int st[Max][20];int Stack[Max], data[Max];int value[Max];std :: map
hash; int Main (){ fread (buf, 1, BUF, stdin); int N; read (N); register int i; for (i = 0; i < N; ++ i) read (number[i]), level[i] = number[i]; int Size = 0; for (i = 0; i < N; ++ i) if (hash.find (number[i]) == hash.end ()) hash[level[i]] = ++ Size; for (i = 0; i < N; ++ i) level[i] = hash[level[i]]; Build_Sa (level, N + 1, Size + 1); for (i = 1; i <= N; st[i][0] = height[i], ++ i); for (int j = 1; j <= 17; ++ j) for (i = 1; i + (1 << j - 1) <= N; ++ i) st[i][j] = min (st[i][j - 1], st[i + (1 << j - 1)][j - 1]); int top = 0, res, pos, l; for (i = 1; i <= N; ++ i) { for (; sa[Stack[top]] > sa[i] && top; -- top); res = Stack[top] + 1; l = (int) log2 (i - res + 1); data[i] = min (st[res][l], st[i - (1 << l) + 1][l]); Stack[++ top] = i; } for (i = N, Stack[top = 0] = N + 1; i; -- i) { for (; sa[Stack[top]] > sa[i] && top; -- top); res = Stack[top]; l = (int) log2 (res - i); data[i] = max (data[i], min (st[i + 1][l], st[res - (1 << l) + 1][l])); Stack[++ top] = i; } for (i = 1; i <= N; ++ i) value[data[i] + sa[i]] ++; long long now = 0, Answer = 0; for (i = 0; i < N; ++ i) { now += value[i]; Answer += now; printf ("%lld\n", Answer); } return 0;}int ZlycerQan = Main ();int main (int argc, char *argv[]) {;}

 

转载于:https://www.cnblogs.com/ZlycerQan/p/7359783.html

你可能感兴趣的文章
eclipse连接远程hadoop集群开发时0700问题解决方案
查看>>
《Head First Python》学习笔记 01
查看>>
innodb事务隔离级别
查看>>
python 编码问题随笔
查看>>
WSGI是一种编程接口,而uwsgi是一种传输协议
查看>>
爱可生技术文档
查看>>
vuex 学习 01
查看>>
剧烈变化的移动互联网O2O
查看>>
SVG文档的注意事项
查看>>
Intellij中快捷键
查看>>
找出十进制数中出现的''一''的个数
查看>>
注册页实现激活邮箱验证(asp.net c#) 详细实现
查看>>
打造完美的IE网页木马
查看>>
CF1109A Sasha and a Bit of Relax
查看>>
【Foreign】登山 [DP][数学]
查看>>
【codeforces】【比赛题解】#948 CF Round #470 (Div.2)
查看>>
关于实现线程死锁的一个例子
查看>>
FMDB保存数据小数
查看>>
JAVA中抽象类的一些总结
查看>>
分页, 解析器, 渲染器
查看>>