社区讨论
#萌新求助:80分,1T1W
P4008[NOI2003] 文本编辑器参与者 3已保存回复 3
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @mi7rsi2y
- 此快照首次捕获于
- 2025/11/21 02:33 4 个月前
- 此快照最后确认于
- 2025/11/21 02:33 4 个月前
CPP
// luogu-judger-enable-o2
#include<bits/stdc++.h>
#define root ch[0][1]
using namespace std;
int t, k, tot;
int fa[2500005], ch[2500005][2];
char val[2500005];
int size[2500005];
inline void read(int &x) {
char c;
while(!isdigit(c = getchar()));
for(x = c^48; isdigit(c = getchar()); x = x*10 + (c^48));
}
inline void update(int x) {
size[x] = size[ch[x][0]] + size[ch[x][1]] + 1;
}
inline int pd(int x) {
return ch[fa[x]][1] == x;
}
inline void rotate(int x) {
int y = fa[x], g = fa[y], c = pd(x), B = ch[x][c^1];
fa[x] = g, ch[g][pd(y)] = x;
fa[y] = x, ch[x][c^1] = y;
fa[B] = y, ch[y][c] = B;
update(y), update(x);
}
inline void splay(int x, int goal) {
while(fa[x] != goal) {
int y = fa[x], g = fa[y];
if(g != goal) pd(x) == pd(y) ? rotate(y) : rotate(x);
rotate(x);
}
if(goal == 0) root = x;
}
inline int Next(int x, int y) {
if(x) splay(x, 0);
if(!ch[x][y]) return 0;
int u = ch[x][y];
while(ch[u][y^1]) u = ch[u][y^1];
return u;
}
inline void Move(int x) {
if(x == 0) {k = 0; return;}
int u = root;
while("I can't AK IOI") {
if(x > size[ch[u][0]] + 1) x -= size[ch[u][0]] + 1, u = ch[u][1];
else if(x <= size[ch[u][0]]) u = ch[u][0];
else {k = u; return;}
}
}
inline void insert(char x) {
// cout << tot << " " << x << "\n";
int u = Next(k, 1);
if(u == 0) ch[k][1] = ++tot, fa[tot] = k;
else ch[u][0] = ++tot, fa[tot] = u;
val[tot] = x, size[tot] = 1, k = tot;
splay(tot, 0);
}
inline void Delete(int x) {
int pre = Next(x, 0), ne = Next(x, 1);
if(pre == 0) splay(ch[x][1], 0), ch[root][0] = 0;
else if(ne == 0) splay(ch[x][0], 0), ch[root][1] = 0;
else splay(pre, 0), splay(ne, root), ch[fa[x]][pd(x)] = 0;
}
int main() {
char ra, rc[100];
int rb;
// freopen("in", "r", stdin);
// freopen("out", "w", stdout);
read(t);
while(t--) {
scanf("%s", rc);
if(rc[0] == 'I') {
read(rb);
for(int i = 1; i <= rb; ++i) {
ra = getchar();
if(ra < 32 || ra > 126) {--i; continue;}
else insert(ra);
}
while(rb--) k = Next(k, 0);
getchar();
}
else if(rc[0] == 'M') read(rb), Move(rb);
else if(rc[0] == 'D') {
read(rb);
for(int i = 1; i <= rb; ++i)
Delete(Next(k, 1));
}
else if(rc[0] == 'G') {
read(rb);
for(int i = 1, u = Next(k, 1); i <= rb; ++i)
printf("%c", val[u]), u = Next(u, 1);
putchar('\n');
}
else if(rc[0] == 'P') k = Next(k, 0);
else if(rc[0] == 'N') k = Next(k, 1);
}
return 0;
}
Wa的那个点是 Wrong answer too short
回复
共 3 条回复,欢迎继续交流。
正在加载回复...