Codeforces 653F Paper task SA】的更多相关文章

Paper task 如果不要求本质不同直接st表二分找出最右端, 然后计数就好了. 要求本质不同, 先求个sa, 然后用lcp求本质不同就好啦. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int> #define PII…
[CF653F] Paper task Description 给定一个括号序列,统计合法的本质不同子串的个数. Solution 很容易想到,只要在传统统计本质不同子串的基础上修改一下即可. 考虑经典统计过程,对于第 \(i\) 个后缀,它的贡献为 \(n - sa[i] + 1 - h[i]\) 也就意味着,它产生贡献的区间是 \([sa[i]+h[i], n]\) .换言之,对任意 \(j \in [sa[i]+h[i], n]\) , \(s[sa[i],j]\) 是一个答案. 那么我们…
题目链接:http://codeforces.com/problemset/problem/653/F 大意是给出一个只包含'('和')'的括号串,求有多少不同的子串是合法的括号串 解法:对于每一个后缀,需要能够求出这个后缀有多少前缀是合法的括号串,这个可以用O(log n)复杂度的二分来解决.注意,二分的范围并不是整个后缀,因为如果将'('视作+1, ')'视作-1,则一个合法的括号串必须时刻不能小于0.所以可以在ST表上二分出合法范围,在这个范围内去统计有多少合法串(即'('与')'正负相消…
题目链接:洛谷 首先我们不考虑本质不同这个限制. 既然不能直接用栈乱搞,我们就可以用一个前缀和的套路了. 我们将(设为1,将)设为-1,记前缀和为$s_i$,则$[i,j]$这一段是回文子串当且仅当 1.$s_j=s_{i-1}$ 2.$\forall k\in [i,j],s_k\geq s_{i-1}$ 于是我们枚举$i$,显然$j$要满足第二个性质就肯定不能超过一个上界,这个上界是可以二分的.每次check的时候就判断一下区间最小值,可以用ST表维护. 然后看看本质不同如何做. 这时候我们…
Liar 刚开始感觉只要开个dp[ i ][ j ][ 0 / 1 ]表示处理了s的前 i 个用了 k 段, i 是否是最后一段的最后一个字符 的 t串最长匹配长度, 然后wa24, 就gg了.感觉这个转移感觉很对, 但是实际上不对... 比如s = ababcde, t = abcde, x = 1, 转移会出现问题. 我们可以用dp[ i ][ j ]表示处理了 s 串的前 i 个, 用了 j 段的最大匹配长度, 我们转移的时候时候肯定是在后面接lcp, 套个sa就好啦. #include<…
Codeforces 题目传送门 & 洛谷题目传送门 这是一道 *2900 的 D1E,而且被!我!自!己!搞!出!来!了! 虽然我承认它难度及摆放的位置异常异常虚高,并且就算我到了现场也不可能切掉 下记 \(t_x\) 表示 \(x\) 是否可以被选择. 首先题目要我们统计五元组 \((a,b,c,d,e)\) 的个数,但稍微观察下就能发现 \(a,e\) 的个数是很好维护的,并且它不受到 \(t_x\) 的值的影响,因此我们可以提前把它预处理出来,记 \(pre_i=\sum\limits_…
题目描述:  A Simple Task time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Given a simple graph, output the number of simple cycles in it. A simple cycle is a cycle with no repeated vertices or…
LINK time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In…
B. Anton and Lines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/593/problem/B Description The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforc…
B. Anton and Lines   The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Codeforces. In the task he was given a set of n lines defined by the equations y = ki·x + bi. It was necess…
/* Netbeans连接数据库 NetBeans项目的“项目属性”中“库”一栏中.Tab页“编译和运行”中已经加上jdbc的驱动文件 */ Connection conn = null;//连接数据库的对象 PreparedStatement pstmt = null;//执行sql对象 try { try { Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver"); } catch (ClassNotFoundEx…
Anton and Lines time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output The teacher gave Anton a large geometry homework, but he didn't do it (as usual) as he participated in a regular round on Cod…
E. A Simple Task Problem's Link: http://codeforces.com/problemset/problem/558/E Mean: 给定一个字符串,有q次操作,每次操作将(l,r)内的字符升序或降序排列,输出q次操作后的字符串. analyse: 基本思想是计数排序. 所谓计数排序,是对一个元素分布较集中的数字集群进行排序的算法,时间复杂度为O(n),但使用条件很苛刻.首先对n个数扫一遍,映射出每个数字出现的次数,然后再O(n)扫一遍处理出:对于数字ai,…
题目链接:http://codeforces.com/contest/70/problem/D Once a walrus professor Plato asked his programming students to perform the following practical task. The students had to implement such a data structure that would support a convex hull on some set of…
Problem D"Decoding Task" Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100002 Description In the near future any research and publications about cryptography are outlawed throughout the world on the grounds of national se…
C. Appleman and a Sheet of Paper   Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q queries. Each query will hav…
题目链接:http://codeforces.com/contest/558/problem/E E. A Simple Task time limit per test5 seconds memory limit per test512 megabytes inputstandard input outputstandard output   This task is very simple. Given a string S of length n and q queries each qu…
原文链接http://www.cnblogs.com/zhouzhendong/p/9026184.html 题目传送门 - Codeforces 802I 题意 求一个串中,所有本质不同子串的出现次数的平方和. $|s|\leq 10^5$ 题解 首先,这一题用 SAM 做就是模板题,比较简单. 但是,本着练一练 SA 的心态,我开始了 SA+单调栈 的苦海. 真毒瘤. 这里讲一讲 SA 的做法,也是经典的做法. SA 闭着眼睛先写了再说. 首先,我们考虑出现次数大于 $1$ 次的子串. 考虑…
E. A Simple Task 题目连接: http://www.codeforces.com/contest/558/problem/E Description This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting of the characters from…
题目链接: http://codeforces.com/problemset/problem/558/E E. A Simple Task time limit per test5 secondsmemory limit per test512 megabytes 问题描述 This task is very simple. Given a string S of length n and q queries each query is on the format i j k which mea…
\(>Codeforces\space959 F. Mahmoud\ and\ Ehab\ and\ yet\ another\ xor\ task<\) 题目大意 : 给出一个长度为 \(n\) 序列 \(A\),和 \(q\) 次询问,对于每一次询问给出两个数 \(l, x\) ,你需要计算在前缀和 \(A[1, l]\) 中选取若干个数,使得它们 \(xor\) 起来的结果等于 \(x\) 的方案数 $n , q \leq 10^5   0 \leq A_i \leq 2^{20} $…
地址:http://codeforces.com/problemset/problem/70/D 题目: D. Professor's task time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Once a walrus professor Plato asked his programming students to perf…
E. Forensic Examination http://codeforces.com/problemset/problem/666/E 题目大意:给模式串S以及m个特殊串,q个询问,询问S的子串[pl,pr]在特殊串编号属于[l,r]中出现次数最多的次数以及在哪个特殊串. 一开始打算用S建SAM,特殊串去匹配...测样例时才想起这样不对.胡搞一番后,才开始写下面的做法. S与特殊串连在一起建SAM,记录S串[1,x]在SAM上节点位置,用来子串定位.每个节点的{right}该串出现的所有地…
A Simple Task CodeForces - 11D 题意:输出一个无向图的简单环数量.简单环指无重复边的环.保证图无重边自环. ans[i][j]表示"包含i中的点,以i中第一个点为起点,以j为终点"的路径条数. 对于某个i,枚举当前终点j(显然不能是首个点),产生一个状态.再枚举上一次终点k,如果能转移就转移. 如果i中点数大于2且j到i中第一个点有路,就认为产生了环.最后每个环记录了两遍,要除以2. #include<cstdio> #include<c…
time limit per test5 seconds memory limit per test512 megabytes inputstandard input outputstandard output This task is very simple. Given a string S of length n and q queries each query is on the format i j k which means sort the substring consisting…
Codeforces 959D. Mahmoud and Ehab and another array construction task 题意 构造一个任意两个数都互质的序列,使其字典序大等于a序列且最小. 思路 其实这题乱搞就行了.用到了之前HDdalao教我的素因子分解方法,可以快速地对枚举的数进行检测. 我们维护一个当前已填的数的素因子集合以及一个大于1的自然数集合(考虑最坏情况,我们总可以都用素数来构造这个序列.由素数的密度可知,n/ln(n)要大于1e5,所以该自然数集合上限达到2e…
题目链接:http://codeforces.com/contest/558/problem/E 题意:有一串字符串,有两个操作:1操作是将l到r的字符串升序排序,0操作是降序排序. 题解:建立26棵线段树,类似计数排序思想. #include <bits/stdc++.h> using namespace std; ; struct SegTree { ], sum[], l, r; }T[N << ]; ][N]; void pushup(int p, int c) { T[p…
D. Top Secret Task time limit per test 3 seconds memory limit per test 256 megabytes input standard input output standard output A top-secret military base under the command of Colonel Zuev is expecting an inspection from the Ministry of Defence. Acc…
A. Playing with Paper One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular a mm  ×  b mm sheet of paper (a > b). Usually the first step in making an origami is making a square piece of paper from the…
题目大意就是给一个字符串,然后多个操作.每次操作能够把每一段区间的字符进行升序或者降序排序,问终于的字符串是如何的. 做法的话就是用线段树维护区间和 一開始仅仅考虑字符串中字符'a'的情况.如果操作区间[L,R]中有x个'a',那么一次操作后,这x个'a'要么去最左(升序).要么去最右(降序),我们能够建立一颗线段树来维护这种操作,字符'a'出现的位置值为1,否则为0,那么q次操作后,最后值为1的地方填的就是'a'了. 然后,在考虑字符'a'和'b'的情况,操作的情况和上面类似,字符'a'和'b…