POJ 2887:Big String(分块)】的更多相关文章

题目大意 给一个字符串,长度不超过 106,有两种操作: 1. 在第 i 个字符的前面添加一个字符 ch 2. 查询第 k 个位置是什么字符 操作的总数不超过 2000 做法分析 好多不同的做法都可以搞 人生第一个块状链表,记录下 块状链表的思想其实挺简单的,传统的链表每个节点只记录一个字符,块状链表的每个节点记录的是 sqrt(n) 个信息,一个长度为 n 的字符串就被分成了 sqrt(n) 个.这样,查询和插入字符的操作就变成了 sqrt(n)级别的了,对于这题 2000 个操作来讲,时间复…
题目连接 http://poj.org/problem?id=2887 Big String Description You are given a string and supposed to do some string manipulations. Input The first line of the input contains the initial string. You can assume that it is non-empty and its length does not…
Big String Time Limit: 1000MS Memory Limit: 131072K Description You are given a string and supposed to do some string manipulations. Input The first line of the input contains the initial string. You can assume that it is non-empty and its length doe…
题意:给一个字符串(<=1000000)和n个操作(<2000),每个操作可以在某个位置插入一个字符,或者查询该位置的字符.问查询结果. 思路:块状数组. 如果将原来的字符串都存在一起,每次插入肯定会超时. 而操作数比较少,考虑使用分块法.假设原字符串长度为L,则取每块长度l=sqrt(L).这样每次插入,我们需要用sqrt(L)的时间找到对应的块,再用sqrt(L)在该块进行插入.查询同样需要sqrt(L)找到该块,如果用数组实现可以O(1)找到目标元素.(我尝试用stl链表来做,结果超时了…
http://poj.org/problem?id=2887 题意:给出一个字符串,还有n个询问,第一种询问是给出一个位置p和字符c,要在位置p的前面插入c(如果p超过字符串长度,自动插在最后),第二种询问是给出一个位置p,查找第p个位置的字符(p保证合法). 思路:暴力分块.一开始建成块之后,每次插入就在每个块的字符串插入字符,因为询问最多只有2000个,所以就算极端情况也不会超时. 注意:sz和cnt其中一个要向上取整.用string类会超时. #include <cstring> #in…
题意: 给你一个不超过1e6的字符串,和不超过2000次的操作 操作分为两种: 1.将一个字符插入到某个位置的前面 2.询问当前位置的字符 /* 块状链表模板水题(我的智商也就能做这种题了). 观察题目,我们发现询问次数是很少的,所以可以考虑暴力? 很明显暴力就会gg,但是可以把这n个字母分为√n 块,然后查找的时候先用√n的时间找出在哪一块, 然后只在这一块中找就行了. */ #include<cstdio> #include<iostream> #include<cstr…
splay瞎搞一下,正解是分块数组或分块链表,但是学不会啊! #include<cstdio> #include<cstdlib> #include<iostream> #include<string> #include<set> #include<algorithm> #include<vector> #include<queue> #include<list> #include<cmath…
#include <iostream> #include <string> #define MAXN 2000 using namespace std; struct node { char c; int place; }; node _node[MAXN]; int index; void fun_q(int place); int len; string s; int main() { //freopen("acm.acm","r",st…
题目大意:给一个字符串,有插入和询问操作,每次往一个位置插入一个字符或者询问第p个位置的字符是什么. 思路:我们离线询问,逆向把所有的字符都插入给线段树,然后再查询就好了,每次都要记得插入线段树的最后的位置,然后要把这个位置给保存下来在O(1)查询即可. //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #include <cstdio> #include<cstring> #include<algorithm> #include<…
算出next数组. 对于任何一个循环字串,len-next[len]必为最小循环节长度 若len%(len-next[len])==0 即为循环字串,n=len/(len-next[len]) 否则输出1 代码: #include<cstdio> #include<cstring> using namespace std; ; char str[N]; int next[N],ans,len; void make() { ,j=-; next[i]=j; while(i<le…
思路: 线段树 (分类讨论) 此题数据很水 数据很水 数据很水 但是卡个暴力还是没问题的-- //By SiriusRen #include <cstdio> #include <cstring> using namespace std; #define maxn 1500000 #define inf 1061109567 int n,tot,jy,xx,yy,tree[maxn*6],vis[maxn],cases,q[maxn]; inline int min(int x,i…
题目:http://poj.org/problem?id=2887       Big String Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 6527   Accepted: 1563 Description You are given a string and supposed to do some string manipulations. Input The first line of the input…
http://poj.org/problem?id=1789 Truck History Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 32474   Accepted: 12626 Description Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, o…
题目链接:http://poj.org/problem?id=1094 Sorting It All Out Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 35468   Accepted: 12458 Description An ascending sorted sequence of distinct values is one in which some form of a less-than operator…
经典问题 : 给出一个由某个循环节构成的字符串,要你找出最小的循环节,例如 abababab 最小循环节当是 ab ,而类似 abab 也可以成为它的循环节,但并非最短. 分析 : 对于上述问题有两个结论 如果对于next数组中的 i, 符合 i % ( i - next[i] ) == 0 && next[i] != 0 , 则说明字符串循环,而且 循环节长度为:    i - next[i] 循环次数为:       i / ( i - next[i] ) 水平有限,用自己的语言描述怕…
题目链接:http://poj.org/problem?id=3468 A Simple Problem with Integers Time Limit: 5000MS   Memory Limit: 131072K Total Submissions: 144616   Accepted: 44933 Case Time Limit: 2000MS Description You have N integers, A1, A2, ... , AN. You need to deal with…
题目:http://poj.org/problem?id=3096 题意:给定一个字符串S,从中找出所有有两个字符组成的子串,每当组成子串的字符之间隔着n字符时,如果没有相同的子串出现,则输出 "S is surprising." , 反之,则输出 "S is NOT surprising." . 例如 AABA 把它分成两个字符为一个整体的,1..相邻两个字符 AA,AB,BA 没有相同的;    2.隔一个字符的 AB AA 没有相同;          3.隔…
标题意味着小神童.加减可以计算. 只是说这个小神童的学科知识,究竟有多神,自己给自己找. 最后,因为数据是非常非常巨大的,我听说关闭50k结束了50000数字总和,可以想见他神教. 这似乎也是考试题目IQ什么! 水题,依照一般加减法做,肯定是WA了. 这里给出使用string的加减法运算.由于string是长度可增可减的,所以无论是多少位,仅仅要内存支持,那么本算法都能够支持了.也能够使用vector这些容器.只是string应该更加省点内存. 注意: POJ比較讨厌的就是不支持C++11,并且…
题目链接:https://cn.vjudge.net/problem/POJ-3468 题目大意:区间加减+区间查询操作. 具体思路:本来是一个线段树裸题,为了学习分块就按照分块的方法做吧. 分块真的好暴力,,,(但是还是挺优美的). 说一下各个数组的作用. a数组,代表每一个点的值. sum数组,代表分块后每一段的值. add数组,相当于线段树中的lazy标记,记录的数当前这一整段添加的值. l数组,r数组,记录每一段的左端点和右端点. belong数组,记录每一个数属于哪一个分块中. AC代…
矩阵乘法是可以分块的,而且幂的和也是具有线性的. 不难得到 Si = Si-1+A*Ai-1,Ai = A*Ai-1.然后矩阵快速幂就可以了. /********************************************************* * ------------------ * * author AbyssalFish * **********************************************************/ #include<cstd…
传送门 题目大意应该都清楚. 今天看到一篇博客用分块+莫对做了这道题,直接惊呆了. 首先常规地离散化后将询问分块,对于某一询问,将莫队指针移动到指定区间,移动的同时处理权值分块的数字出现次数(单独.整块),莫队完后,现在的权值分块就是关于当前区间的.然后再从左到右扫描分块,直到数字个数+该块个数>=k,这时进入该块逐个加,当数字个数>=k时,直接跳出输出离散化之前的数字. 试了很多种块的大小,最后还是选择sqrt(100000) ≈ 320,时间比我的主席树还少(肯定是我写的丑). code…
Manhattan 2025 Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 1318   Accepted: 703 Description Background Manhattan in the year 2025 - it is so densely populated that its old two-dimensional grid of streets and avenues fails to provide…
参考连接: KMP+DP: http://www.cnblogs.com/yuelingzhi/archive/2011/08/03/2126346.html 另外给出一个没用dp做的:http://blog.sina.com.cn/s/blog_82061db90100usxw.html 题意: 给出一个字符串,求它的各个前缀在字符串中出现的次数总和. 思路:记 dp[i] 为前 i 个字符组成的前缀出现的次数则 dp[next[i]]+=dp[i] dp[i]表示长度为i的前缀出现的次数,初…
String Matching Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4074   Accepted: 2077 Description It's easy to tell if two words are identical - just check the letters. But how do you tell if two words are almost identical? And how close…
Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 35049   Accepted: 10139   Special Judge Description Let us define a regular brackets sequence in the following way: 1. Empty sequence is a regular sequence. 2. If S is a r…
题目传送门 传送点I 传送点II 传送点III 题目大意 给定一个字母串,要求支持以下操作: 修改一个位置的字母 查询一段区间中,字符串$s$作为子串出现的次数 Solution 1 Bitset 每次匹配一段,可以看成,依次考虑每个位置,匹配的位置对应的起点取交集.例如: 大概就这个意思. bitset的count似乎很慢,可以用__builtin_popcount来数中间的位数,然后暴力数两端的位数会快很多.感觉手写倍增法数位数最快.但有人说前面那个内联函数比手写的$O(\log \log…
Shuffle'm Up Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14471 Accepted: 6633 Description A common pastime for poker players at a poker table is to shuffle stacks of chips. Shuffling chips is performed by starting with two stacks of po…
Facer’s string Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 2155   Accepted: 644 Description Minifacer was very happy these days because he has learned the algorithm of KMP recently. Yet his elder brother, Hugefacer, thought that Mini…
Given a string… Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 1819   Accepted: 390 Case Time Limit: 2000MS Description Peter’s Boss is now very upset. He said that Peter’s vision of the orthogonal sum of two strings is not collinear t…
String reduction Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1360   Accepted: 447 Description There is a string of characters 'a' and 'b' with the length of no more than 255 characters. You can perform the substring reduction on the…