求助块链

P4008 [NOI2003] 文本编辑器

```cpp #include <bits/stdc++.h> using namespace std; #define For(i,x,y,...) for(int i=x,##__VA_ARGS__;i<=int(y);++i) #define rFor(i,x,y,...) for(int i=x,##__VA_ARGS__;i>=int(y);--i) #define Rep(i,x,y,...) for(int i=x,##__VA_ARGS__;i<int(y);++i) #define mem(a,x,n) memset(a,x,sizeof(a[0])*(n+1)) #define pb emplace_back #define MP make_pair #define fi first #define se second typedef long long LL; typedef unsigned long long ULL; typedef long double LD; typedef pair<int,int> PII; typedef vector<int> VI; char buf[1<<20],*p1=buf,*p2=buf,pbuf[1<<20],*pp=pbuf; #define getchar() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++) #define iocl() fwrite(pbuf,1,pp-pbuf,stdout),pp=pbuf,0 #define putchar(x) pp-pbuf==1<<20&&(iocl()),*pp++=x template<typename T>void read(T &x){ x=0;bool f=1;char c=getchar(); for(;!isdigit(c);c=getchar())if(c=='-')f=0; if(f)for(;isdigit(c);c=getchar())x=x*10+c-48; else for(;isdigit(c);c=getchar())x=x*10-c+48; } template<typename T,typename ...Args>void read(T &x, Args &...args) { read(x),read(args...); } template<typename T>void write(T x,char y=10) { if(!x)putchar(48); else{static int s[21];int l=0;if(x<0)putchar('-'),x=-x; for(;x;x/=10)s[l++]=x%10;while(l)putchar(s[--l]|48);} putchar(y); } template<typename T>void ckmax(T &x,T y) { if( y > x ) x = y; } template<typename T>void ckmin(T &x,T y) { if( y < x ) x = y; } #define MT make_tuple void reads(string &s) { s.clear(); char c=getchar(); while( !isalpha(c) ) c=getchar(); for(; isalpha(c); c=getchar()) s += c; } const int B = 1000; int now,n,p; string op,s,t; vector<string> bl; tuple<int,int> find(int k) { Rep(i,0,bl[i].size()) { if( k < bl[i].size() ) return MT(i,k); k -= bl[i].size(); } return MT(0,0); } void maintain(int u) { while( u != bl.size() ) { if( !bl[u].size() ) { bl.erase(bl.begin()+u); continue; } if( bl[u].size() > 2*B ) { bl.emplace(bl.begin()+u+1,bl[u].substr(bl[u].size()-B)), bl[u].erase(bl[u].size()-B); continue; } break; } } signed main() { // freopen("P4008_1.in","r",stdin); // freopen("a.out","w",stdout); bl.pb("$"); int m; read(m); while( m-- ) { reads(op); if( op == "Move" ) read(now); else if( op == "Insert" ) { read(n), s.clear(); while( n-- ) { char c=getchar(); if( c < 32 || 126 < c ) ++n; else s += c; } int i,j; tie(i,j) = find(now); bl[i].insert(j,s), maintain(i); } else if( op == "Delete" ) { read(n); int i,j; tie(i,j) = find(now); for(; n; ++i, j = 0) { int l = j, r = min(l+n,(int)bl[i].size()); bl[i].erase(l,r-l), n -= r-l; } maintain(i-1); } else if( op == "Get" ) { read(n); int i,j; tie(i,j) = find(now); for(; n; ++i, j = 0) { int l = j, r = min(l+n,(int)bl[i].size()); Rep(k,l,r) putchar(bl[i][k]); n -= r-l; } putchar(10); } else if( op == "Prev" ) --now; else ++now; } return iocl(); } ```
by 401rk8 @ 2021-10-05 08:32:59


完结 sb 操作:`Rep(i,0,bl[i].size())`
by 401rk8 @ 2021-10-19 19:46:16


|