随笔分类 - Bitset
摘要:题意:给定一棵树,带边权。然后Q次询问,每次给出(u,v),求这个路径上最小的未出现的边权。 思路:树上莫队,求mex可以用分块或者bitset,前者可能会快一点。 莫队过程:求出欧拉序,即记录dfs的in和out时间戳。 然后摊平成数组,在数组上进行莫队。 一般的莫队需要单独考虑LCA,因为LCA
阅读全文
摘要:题解见:http://ecustacm.cn/contest/11/announcements A #include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<=b;i++) using namespace std; const int maxn
阅读全文
摘要:2124: 等差子序列 Description 给一个1到N的排列{Ai},询问是否存在1<=p1<p2<p3<p4<p5<…<pLen<=N (Len>=3), 使得Ap1,Ap2,Ap3,…ApLen是一个等差序列。 给一个1到N的排列{Ai},询问是否存在1<=p1<p2<p3<p4<p5<…
阅读全文
摘要:题意:给定A,B长度相同的字符串,Q次操作,修改操作位单个字符修改,查询操作为询问从某点开始有多少连续相同的字符。 思路:我们把不相同的设为1,相同的设为0,那么询问就是找下一个为1的为位置,可以用线段树解决,可以用set的lower_bound解决,这里用bitset的Find_next函数,效率
阅读全文
摘要:题意:T组样例,给次给出一个N节点的点权树,以及M,问连通块的点权和sum的情况,输出sum=1到M,用0或者1表示。 思路:背包,N^2,由于是无向的连通块,所以可以用分治优化到NlgN。 然后背包可以用bitset优化。注意不要想着背包合并背包,背包只能合并单点。
阅读全文
摘要:You are given a string ss. You should answer nn queries. The ii-th query consists of integer kiki and string mimi. The answer for this query is the mi
阅读全文
摘要:Notice: unusual memory limit! After the war, destroyed cities in the neutral zone were restored. And children went back to school. The war changed the
阅读全文
摘要:It is Dandiya Night! A certain way how dandiya is played is described: There are N pairs of people playing at a time. Both the person in a pair are pl
阅读全文
摘要:题意:给定字符串S,多次修改区间值,多次询问区间有多少匹配串T,可以失配3次。 超时思路:用bitset的思路去做的,每次记录T的相应位置[0,L-1]的集合,一位一位的移、求并,对于出现的失配位置,我们最多可以更新3次。假设数据小一点,没准可以过。 主要还是修改操作那里太暴力的,单点操作的题是遇到
阅读全文
摘要:Ada the Ladybug lives near an orange tree. Instead of reading books, she investigates the oranges. The oranges on orange tree can be in up to 5*50 Sha
阅读全文
摘要:Rainbow 6 is a very popular game in colleges. There are 2 teams, each having some members and the 2 teams play some matches against each other. The te
阅读全文
摘要:Recently in school Alina has learned what are the persistent data structures: they are data structures that always preserves the previous version of i
阅读全文
摘要:之前有过区域赛,简化版问题: 给定一个小写字符组成的字符串S,(|S|<1e5,下标从1开始),现在有Q种操作,对于每个操作Q(Q<=1e5),输入opt, 如果opt==1,输入x,c,表示把S[x]改为c,(c是小写字母)。 如果opt==2,输入L,R,和字符串T,输出S[L-R]中有多少个字
阅读全文
摘要:Mr. Fib is a mathematics teacher of a primary school. In the next lesson, he is planning to teach children how to add numbers up. Before the class, he
阅读全文
摘要:Median Sum You are given N integers A1, A2, ..., AN. Consider the sums of all non-empty subsequences of A. There are 2N−1 such sums, an odd number. Le
阅读全文
摘要:Each of Farmer John's N cows (1 ≤ N ≤ 1,000) produces milk at a different positive rate, and FJ would like to order his cows according to these rates
阅读全文
摘要:题意:求有向图里面有多少个三元环。 思路:枚举起点A,遍历A可以到的B,然后求C的数量,C的数量位B可以到是地方X集合,和可以到A的地方Y集合的交集(X&Y)。 B点可以枚举,也可以遍历。(两种都试过,区别不大。) 枚举代码: 遍历代码:
阅读全文
摘要:You are given N sets, the i-th set (represent by S(i)) have C(i) element (Here "set" isn't entirely the same as the "set" defined in mathematics, and
阅读全文
摘要:一题题目: 一题题解: 这个题目哪来入门再好不过了,支老板之前没有接触过这个东西,然后一点即通:就是把一个int(32位)拆成32个只放0或1的位置,然后这32个的单点操作或者32个一起操作的复杂度是O(1),所以长度位N的bitset的一次单点操作是O(1),整体操作是O(N/w),其中w=32。
阅读全文