E. DNA Evolution 题目连接: http://codeforces.com/contest/828/problem/E Description Everyone knows that DNA strands consist of nucleotides. There are four types of nucleotides: "A", "T", "G", "C". A DNA strand is a seque…
题意:给你一个串k,进行两个操作: “1 a b”:把a位置的字母换成b “2 l r s”:求l到r有多少个字母和s匹配,匹配的条件是这样:从l开始无限循环s形成一个串ss,然后匹配ss和指定区间的匹配个数,如图. 思路:用树状数组预处理.因为模板串是不断重复循环的,所以我们可以一个位置一个位置求.对于长len的模板串来说,如果位置i,j满足 i%len == j%len,那么i和j匹配时对模板串来说是一样的(匹配同一个字符).所以我们定义node[字母][模板串长度][相对位置][位置]来遍…
[Codeforces 1208D]Restore Permutation (树状数组) 题面 有一个长度为n的排列a.对于每个元素i,\(s_i\)表示\(\sum_{j=1,a_j<a_i}^i a_j\).即前面比它小的元素的值之和. 给出\(s_1,s_2 \dots s_n\),求a 分析 考虑如何求\(a_n\),\(s_n\)实际上表示的是1~n中比\(a_n\)小的所有数的和,可以直接求出\(a_n\) 然后我们可以倒序求\(a_i\),求到\(a_i\)的时候,我们已经知道\(…
题目链接:http://codeforces.com/contest/828/problem/E E. DNA Evolution time limit per test 2 seconds memory limit per test 512 megabytes input standard input output standard output Everyone knows that DNA strands consist of nucleotides. There are four typ…
Codeforces 题目传送门 & 洛谷题目传送门 我怕不是个 nt--一开始忽略了"询问独立"这个条件--然后就一直在想有什么办法维护全局 LIS--心态爆炸 首先离散化.预处理出以每个点为结尾的 LIS 长度 \(f_i\),以及以每个点为开头的 LIS 长度 \(g_i\). 不难发现每次只修改一个元素,故每次询问的答案只可能是原序列 LIS 的长度 \(mx\pm 1\). 我们不妨来探究什么情况下询问的答案为 \(mx+1\),什么情况下询问的答案为 \(mx-1\…
Dish Shopping 将每个物品拆成p 和 s 再加上人排序. 然后问题就变成了, 对于一个线段(L - R), 问有多少个(li, ri)满足  L >= li && R >= ri, 这个东西可以直接树状数组套平衡树维护. 但是这个题目有个特殊性,因为排好序之后不会存在 li > L && ri > R的点, 所以可以直接 用平衡树, 或者线段树去维护这个东西. 平板电视 #include<bits/stdc++.h> #inc…
B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 10…
题意: 给出一个序列\(A\),有若干询问. 每次询问某个区间中值相等且距离最短的两个数,输出该距离,没有则输出-1. 分析: 令\(pre_i = max\{j| A_j = A_i, j < i\}\),也就是前一个与\(A_i\)相等的数字的下标. 这个可以通过对序列排序,数值相等按照下标排序来计算. 将询问离线,按照询问区间的右端点从左到右排序. 从左到右扫描,向树状数组中在位置\(pre_i\)插入\(i - pre_i\),并维护一个后缀最小值. 查询的时候直接查即可. #inclu…
题目链接: G. Hiring time limit per test 4 seconds memory limit per test 512 megabytes input standard input output standard output The head of human resources department decided to hire a new employee. He created a test exercise for candidates which shoul…
B. Cards Sorting time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 10…