所以这题一直WA是为啥啊,真看不出来哪里有错= =
// Author: Ame__
#include<bits/stdc++.h>
#define _ 0
#define AME__DEBUG
#define LL long long
#define bomb exit(0)
#define LOG(FMT...) fprintf(stderr , FMT)
#define TOWA(FMT...) fprintf(stdout , FMT)
using namespace std;
/*Grievous Lady*/
typedef int32_t i32;
typedef int64_t i64;
typedef double qwq;
const int BUF_SIZE = 1 << 12;
char buf[BUF_SIZE] , *buf_s = buf , *buf_t = buf + 1;
#define PTR_NEXT() \
{ \
buf_s ++; \
if(buf_s == buf_t) \
{ \
buf_s = buf; \
buf_t = buf + fread(buf , 1 , BUF_SIZE , stdin); \
} \
}
#define mians(_s_) \
{ \
while(!isgraph(*buf_s)) PTR_NEXT();\
char register *_ptr_ = (_s_); \
while(isgraph(*buf_s) || *buf_s == '-') \
{ \
*(_ptr_ ++) = *buf_s; \
PTR_NEXT(); \
} \
(*_ptr_) = '\0'; \
}
template <typename _n_> void mian(_n_ & _x_){
char buf_s; while(buf_s != '-' && !isdigit(buf_s)) buf_s = getchar();
bool register _nega_ = false; if(buf_s == '-'){ _nega_ = true; buf_s = getchar(); }
_x_ = 0; while(isdigit(buf_s)){ _x_ = _x_ * 10 + buf_s - '0'; buf_s = getchar(); } if(_nega_) _x_ = -_x_;
}
const i32 atri = 6e6 + 10;
const i32 kato = 1e6 + 5e5 + 10;
template <typename _n_> bool cmax(_n_ &a , const _n_ &b){ return a < b ? a = b , 1 : 0; }
template <typename _n_> bool cmin(_n_ &a , const _n_ &b){ return a > b ? a = b , 1 : 0; }
i32 n , mask , ans;
char s[atri] , opt[50];
namespace towa{
struct LCT{
struct node{
node *ch[2] , *fa;
static queue<node*> q;
i32 tot , size , val , rev;
node(node *fa = 0x0 , i32 tot = 0 , i32 size = 0 , i32 val = 0 , i32 rev = 0): fa(fa) , tot(tot) , size(size) , val(val) , rev(rev){
ch[0] = ch[1] = 0x0;
}
inline void down(){
if(this -> rev){
if(this -> ch[0]) this -> ch[0] -> Modify_rev(); if(this -> ch[1]) this -> ch[1] -> Modify_rev();
this -> rev ^= 1;
}
}
inline bool ntr(){
return fa && (fa -> ch[0] == this || fa -> ch[1] == this);
}
inline bool isr(){
return this == fa -> ch[1];
}
inline void up(){
tot = size + val + (ch[0] ? ch[0] -> tot : 0) + (ch[1] ? ch[1] -> tot : 0);
}
inline void Modify_rev(){
rev ^= 1; swap(ch[0] , ch[1]);
}
void *operator new(size_t){
static node *S = 0x0 , *T = 0x0; node *tmp;
return q.empty() ? (S == T && (T = (S = new node[1024]) + 1024 , S == T) ? 0x0 : S ++) : (tmp = q.front() , q.pop() , tmp);
}
void operator delete(void *qaq){ q.push(static_cast<node*>(qaq)); }
}pool[kato];
inline void split(node *x){
node *y = x -> fa , *z = y -> fa;
int k = x -> isr(); node *w = x -> ch[!k];
if(y -> ntr()) z -> ch[y -> isr()] = x;
x -> ch[!k] = y , y -> ch[k] = w;
y -> fa = x , x -> fa = z;
if(w) w -> fa = y;
y -> up() , x -> up();
}
inline void splay(node *o){
static node *tree[kato]; i32 top = 0;
tree[top = 1] = o;
while(tree[top] -> ntr()) tree[top + 1] = tree[top] -> fa , top ++;
while(top) tree[top --] -> down();
while(o -> ntr()){
if(o -> fa -> ntr()) split(o -> isr() ^ o -> fa -> isr() ? o : o -> fa);
split(o);
}
}
inline void access(node *x){
for(node *y = 0x0 ; x ; x = (y = x) -> fa){
splay(x);
if(x -> ch[1]) x -> size += x -> ch[1] -> tot;
if((x -> ch[1] = y)) x -> size -= x -> ch[1] -> tot;
x -> up();
}
}
inline void Move_to_root(node *x){
access(x) , splay(x) , x -> Modify_rev();
}
inline void link(node *x , node *y){
Move_to_root(x); access(y); splay(y);
(x -> fa = y) -> size += x -> tot;
y -> up();
}
inline void cut(node *x , node *y){
Move_to_root(x); access(y); splay(y);
if(y -> ch[0] == x) y -> ch[0] = x -> fa = 0x0 , y -> up();
}
inline i32 get_ans(node *x , node *y){
Move_to_root(x) , access(y) , splay(y);
return y -> val + y -> size;
}
inline node *id(i32 x){ return pool + x; }
}qaq;
queue<LCT::node*> LCT::node::q;
struct SuffixAutoMaton{
protected:
struct node{
static const size_t CHARSET_SIZE = 26;
node *ch[CHARSET_SIZE] , *nxt;
i32 len , size;
node(node *nxt = 0x0 , i32 len = 0 , i32 size = 0): nxt(nxt) , len(len) , size(size){
memset(ch , 0x0 , sizeof ch);
}
}*root , *tail , *ls , _pool[kato];
inline void extend(int c){
node *u = new(tail ++) node(0x0 , ls -> len + 1 , 1) , *v = ls;
qaq.id(u - _pool) -> val = 1 , qaq.id(u - _pool) -> up();
for(; v && !v -> ch[c] ; v = v -> nxt) v -> ch[c] = u;
if(!v) u -> nxt = root , qaq.link(qaq.id(u - _pool) , qaq.id(root - _pool));
else if(v -> ch[c] -> len == v -> len + 1) u -> nxt = v -> ch[c] , qaq.link(qaq.id(u - _pool) , qaq.id(v -> ch[c] - _pool));
else{
node *n = new(tail ++) node(0x0 , v -> len + 1) , *o = v -> ch[c];
copy(o -> ch , o -> ch + node::CHARSET_SIZE , n -> ch);
qaq.id(n - _pool) -> up();
qaq.cut(qaq.id(o - _pool) , qaq.id(o -> nxt - _pool));
qaq.link(qaq.id(n - _pool) , qaq.id(o -> nxt - _pool));
qaq.link(qaq.id(o - _pool) , qaq.id(n - _pool));
qaq.link(qaq.id(u - _pool) , qaq.id(n - _pool));
for(; v && v -> ch[c] == o ; v = v -> nxt) v -> ch[c] = n;
n -> nxt = o -> nxt , o -> nxt = u -> nxt = n;
}
ls = u;
}
void clear(){ tail = _pool , root = ls = new(tail ++) node(); }
public:
SuffixAutoMaton(){ clear(); }
inline void insert(char *s){ for(char *p = s ; *p ; p ++) extend(*p - 'A'); }
inline i32 get_ans(char *s){
node *o = root;
for(char *p = s ; *p ; p ++){
i32 res = *p - 'A';
if(o -> ch[res]) o = o -> ch[res];
else return 0;
}
return ans = qaq.get_ans(qaq.id(root - _pool) , qaq.id(o - _pool));
}
}yuni;
inline void get_str(i32 len , i32 tmp){
for(int i = 0;i < len;i ++){
tmp = (tmp * 131 + i) % len;
swap(s[i] , s[tmp]);
}
}
}
inline int Ame_(){
#ifdef AME__
freopen(".in" , "r" , stdin); freopen(".out" , "w" , stdout); int nol_cl = clock();
#endif
mian(n);
scanf("%s" , s); towa::yuni.insert(s);
for(; n --> 0 ;){
scanf("%s" , opt);
if(opt[0] == 'A') scanf("%s" , s) , towa::get_str(strlen(s) , mask) , towa::yuni.insert(s);
if(opt[0] == 'Q') scanf("%s" , s) , towa::get_str(strlen(s) , mask) , TOWA("%d\n" , towa::yuni.get_ans(s)) , mask ^= ans;
}
#ifdef AME__TIME
LOG("Time: %dms\n", int((clock() - nol_cl) / (qwq)CLOCKS_PER_SEC * 1000));
#endif
return ~~(0^_^0); /*さようならプログラム*/
}
int Ame__ = Ame_();
int main(){;}