POJ2887(块状链表)
| Time Limit: 1000MS | Memory Limit: 131072K | |
| Total Submissions: 6346 | Accepted: 1525 |
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 exceed 1,000,000.
The second line contains the number of manipulation commands N (0 < N ≤ 2,000). The following N lines describe a command each. The commands are in one of the two formats below:
- I ch p: Insert a character ch before the p-th character of the current string. If p is larger than the length of the string, the character is appended to the end of the string.
- Q p: Query the p-th character of the current string. The input ensures that the p-th character exists.
All characters in the input are digits or lowercase letters of the English alphabet.
Output
For each Q command output one line containing only the single character queried.
Sample Input
ab
7
Q 1
I c 2
I d 4
I e 2
Q 5
I f 1
Q 3
Sample Output
a
d
e
标准块状链表.
#include"cstdio"
#include"cstring"
#include"cmath"
#include"algorithm"
using namespace std;
const int MAXN=;
char str[MAXN*MAXN];
struct Block_List{
int size,next;
char s[*MAXN];
Block_List()
{
memset(s,,sizeof(s));
size=;
next=-;
} void push(char ch)
{
s[size++]=ch;
} void insert(int pos,char ch)
{
for(int i=size;i>pos;i--)
{
s[i]=s[i-];
}
s[pos]=ch;
size++;
}
}bkl[MAXN]; int bsize,cnt,m;
void Init()
{
gets(str);
scanf("%d",&m);
bsize=(int)sqrt(double(strlen(str)+m));
for(int i=;str[i];i++)
{
if(bkl[cnt].size==bsize)
{
bkl[cnt].next=cnt+;
cnt++;
}
bkl[cnt].push(str[i]);
}
cnt++;
} void Update(int u)
{
if(bkl[u].size<*bsize) return ;
/*
for(int i=bsize;i<bkl[u].size;i++)
{
bkl[cnt].push(bkl[u].s[i]);
}
*/
strcpy(bkl[cnt].s,bkl[u].s+bsize);
bkl[cnt].size=strlen(bkl[u].s)-bsize;
bkl[u].size=bsize;
bkl[cnt].next=bkl[u].next;
bkl[u].next=cnt;
cnt++;
}
void handle()
{
int cas=;
while(++cas<=m)
{
char op[];
scanf("%s",op);
if(op[]=='Q')
{
int pos;
scanf("%d",&pos);
int i;
for(i=;pos>bkl[i].size;i=bkl[i].next)
{
pos-=bkl[i].size;
}
printf("%c\n",bkl[i].s[pos-]);
}
else
{
char ch[];
int pos;
scanf("%s%d",ch,&pos);
int i;
for(i=;pos>bkl[i].size&&bkl[i].next!=-;i=bkl[i].next)
{
pos-=bkl[i].size;
}
bkl[i].insert(pos-,ch[]);
Update(i);
}
}
}
int main()
{
Init();
handle();
return ;
}
POJ2887(块状链表)的更多相关文章
- 【POJ2887】【块状链表】Big String
Description You are given a string and supposed to do some string manipulations. Input The first lin ...
- 【BZOJ-1507】Editor 块状链表
1507: [NOI2003]Editor Time Limit: 5 Sec Memory Limit: 162 MBSubmit: 3397 Solved: 1360[Submit][Stat ...
- ZOJ 2112 Dynamic Rankings(动态区间第 k 大+块状链表)
题目大意 给定一个数列,编号从 1 到 n,现在有 m 个操作,操作分两类: 1. 修改数列中某个位置的数的值为 val 2. 询问 [L, R] 这个区间中第 k 大的是多少 n<=50,00 ...
- POJ 2887 Big String(块状链表)
题目大意 给一个字符串,长度不超过 106,有两种操作: 1. 在第 i 个字符的前面添加一个字符 ch 2. 查询第 k 个位置是什么字符 操作的总数不超过 2000 做法分析 好多不同的做法都可以 ...
- 【BZOJ 1507】【NOI 2003】&【Tyvj P2388】Editor 块状链表模板题
2016-06-18 当时关于块状链表的想法是错误的,之前维护的是一个动态的$\sqrt{n}$,所以常数巨大,今天才知道原因TwT,请不要参照这个程序为模板!!! 模板题水啊水~~~ 第一次写块状链 ...
- BZOJ 1507 Editor(块状链表)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=1507 题意:一个文本编辑器,模拟以下操作: 思路:块状链表的主要操作: (1)find( ...
- bzoj 3809 Gty的二逼妹子序列(莫队算法,块状链表)
[题意] 回答若干个询问,(l,r,a,b):区间[l,r]内权值在[a,b]的数有多少[种]. [思路] 考虑使用块状链表实现莫队算法中的插入与删除. 因为权值处于1..n之间,所以我们可以建一个基 ...
- 【BZOJ1500】【块状链表】维修数列
Description Input 输入文件的第1行包含两个数N和M,N表示初始时数列中数的个数,M表示要进行的操作数目.第2行包含N个数字,描述初始时的数列.以下M行,每行一条命令,格式参见问题描述 ...
- 【BZOJ2741】【块状链表+可持久化trie】FOTILE模拟赛L
Description FOTILE得到了一个长为N的序列A,为了拯救地球,他希望知道某些区间内的最大的连续XOR和. 即对于一个询问,你需要求出max(Ai xor Ai+1 xor Ai+2 .. ...
随机推荐
- ss请cc来家里钓鱼,鱼塘可划分为n*m的格子,每个格子有不同的概率钓上鱼,cc一直在坐标(x,y)的格子钓鱼,而ss每分钟随机钓一个格子。问t分钟后他们谁至少钓到一条鱼的概率大?为多少?
include "stdafx.h" #include<iostream> #include<vector> #include<math.h> ...
- HDU1864 最大报销额 01背包
非常裸的01背包,水题.注意控制精度 #include <iostream> #include <algorithm> #include <cstdio> #inc ...
- poj 2096 Collecting Bugs 【概率DP】【逆向递推求期望】
Collecting Bugs Time Limit: 10000MS Memory Limit: 64000K Total Submissions: 3523 Accepted: 1740 ...
- python发布IIS
参考文档 https://segmentfault.com/a/1190000008909201 http://blog.51cto.com/anngle/1922041 https://www.cn ...
- Circling Round Treasures CodeForces - 375C
C. Circling Round Treasures time limit per test 1 second memory limit per test 256 megabytes input s ...
- COGS1532. [IOI2001]移动电话
1532. [IOI2001]移动电话 ★☆ 输入文件:mobilephones.in 输出文件:mobilephones.out 简单对比时间限制:5 s 内存限制:256 MB [ ...
- EasyPlayerPro Windows播放器电子放大/局部放大播放功能实现
背景描述 在视频监控软件中,我们看到很多的软件都有电子放大功能, 按住鼠标左键不放,框选一个区域,再松开鼠标左键,即对选中的区域进行放大显示, 且可以重复该操作,逐步放大所需显示的区域, 有没有觉得, ...
- 点聚-weboffice 6.0 (二)
1.修订操作 //设置当前操作用户 function SetUserName() { try{ var webObj=document.getElementById("WebOffice1& ...
- 基于 HTTP 协议的几种实时数据获取技术(转)
HTTP协议 HTTP协议大家都很熟悉了,开始本文之前,首先简单回顾一下HTTP协议. HTTP协议是建立在TCP协议上的应用层协议,协议的本质是请求----应答: 即对于HTTP协议来说,服务端给一 ...
- Oozie-1-安装、配置 让Hadoop流动起来
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/wl101yjx/article/details/27881739 写在前面一: 本文总结 基于Had ...