BZOJ 1507: [NOI2003]Editor rope

来源:互联网 发布:棋盘覆盖算法 编辑:程序博客网 时间:2024/06/03 16:16

1507: [NOI2003]Editor

Time Limit: 5 Sec  Memory Limit: 162 MB
Submit: 3885  Solved: 1601
[Submit][Status][Discuss]

Description

Input

输入文件editor.in的第一行是指令条数t,以下是需要执行的t个操作。其中: 为了使输入文件便于阅读,Insert操作的字符串中可能会插入一些回车符,请忽略掉它们(如果难以理解这句话,可以参考样例)。 除了回车符之外,输入文件的所有字符的ASCII码都在闭区间[32, 126]内。且行尾没有空格。 这里我们有如下假定:  MOVE操作不超过50000个,INSERT和DELETE操作的总个数不超过4000,PREV和NEXT操作的总个数不超过200000。  所有INSERT插入的字符数之和不超过2M(1M=1024*1024),正确的输出文件长度不超过3M字节。  DELETE操作和GET操作执行时光标后必然有足够的字符。MOVE、PREV、NEXT操作必然不会试图把光标移动到非法位置。  输入文件没有错误。 对C++选手的提示:经测试,最大的测试数据使用fstream进行输入有可能会比使用stdio慢约1秒。

Output

输出文件editor.out的每行依次对应输入文件中每条GET指令的输出。

Sample Input

15
Insert 26
abcdefghijklmnop
qrstuv wxy
Move 15
Delete 11
Move 5
Insert 1
^
Next
Insert 1
_
Next
Next
Insert 4
.\/.
Get 4
Prev
Insert 1
^
Move 0
Get 22

Sample Output

.\/.
abcde^_^f.\/.ghijklmno

rope大法 腻害的很呐


#include<cmath>#include<ctime>#include<cstdio>#include<cstring>#include<cstdlib>#include<complex>#include<iostream>#include<algorithm>#include<iomanip>#include<vector>#include<string>#include<bitset>#include<queue>#include<map>#include<set>using namespace std;#include<ext/rope>using namespace __gnu_cxx;rope<char>s;inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch<='9'&&ch>='0'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}void print(int x){if(x<0)putchar('-'),x=-x;if(x>=10)print(x/10);putchar(x%10+'0');}const int N=3000010;char tmp[N];int main(){register int n=read(),now=0,len,i;char ch[20];while(n--){scanf("%s",ch);switch(ch[0]){case 'I':len=read();for(i=0;i<len;++i)while((tmp[i]=getchar())=='\n');tmp[len]='\0';s.insert(now,tmp);break;case 'M':now=read();break;case 'D':len=read();s.erase(now,len);break;case 'G':len=read();for(i=now;i<=now+len-1;++i)putchar(s[i]);puts("");break;case 'P':now--;break;case 'N':now++;break;}}return 0;}/*15Insert 26abcdefghijklmnopqrstuv wxyMove 15Delete 11Move 5Insert 1^NextInsert 1_NextNextInsert 4.\/.Get 4PrevInsert 1^Move 0Get 22.\/.abcde^_^f.\/.ghijklmno*/


原创粉丝点击