P2414 [NOI2011]阿狸的打字机
暴力跑AC自动机,询问离线,只有70分
好像还得建fail树,这又是什么高端操作==
#include<bits/stdc++.h> using namespace std; #define maxn 100004 struct Trie { int trie[maxn][26]; int tot,rt; int fail[maxn]; int val[maxn]; int ans[maxn]; vector<int>ed [maxn]; void init() { tot=-1; newNod(); } int newNod() { memset(trie[++tot],0,sizeof trie[0]); fail[tot]=val[tot]=0; return tot; } void insert(char *s,int k) { int cur=0; for(int i=0; s[i]; i++) { if(trie[cur][s[i]-'a']==0) { trie[cur][s[i]-'a']=newNod(); } cur=trie[cur][s[i]-'a']; } ++val[cur]; ed[cur].push_back(k); } void build() { queue<int> q; for(int i=0; i<26; i++) { if(trie[0][i]) { q.push(trie[0][i]); } } while(!q.empty()) { int u=q.front(); q.pop(); for(int i=0; i<26; i++) { if(trie[u][i]) { fail[trie[u][i]]=trie[fail[u]][i]; q.push(trie[u][i]); } else trie[u][i]=trie[fail[u]][i]; ; } } } int query(char *s,int k) { for(int i=0;i<=k;i++)ans[i]=0; int cur=0,res=0; for(int i=0; s[i]; i++) { if(trie[cur][s[i]-'a']) { cur=trie[cur][s[i]-'a']; int tmp=cur; while(tmp&&val[tmp]>=0) { for(int i=0; i<ed[tmp].size(); i++) { ans[ed[tmp][i]]+=1; } //res+=val[tmp]; tmp=fail[tmp]; } } } return res; } } ac; int m; struct QAQ { int x,y; int i; int v; } Q[maxn]; bool cmp(QAQ a,QAQ b) { if(a.x==b.x)return a.y<b.y; return a.x<b.x; } bool cmp1(QAQ a,QAQ b) { return a.i<b.i; } char A[maxn]; char B[maxn]; char* T[maxn]; vector<char*>v; void work() { v.push_back(""); int j=0,k=1; for(int i=0; A[i]; i++) { if(A[i]=='P') { B[j]='