QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#214287#2343. First of Her Nameucup-team2172#AC ✓353ms487936kbC++141.6kb2023-10-14 18:30:262023-10-14 18:30:26

Judging History

你现在查看的是最新测评结果

  • [2023-10-14 18:30:26]
  • 评测
  • 测评结果:AC
  • 用时:353ms
  • 内存:487936kb
  • [2023-10-14 18:30:26]
  • 提交

answer

#include <bits/stdc++.h>
#define inf (0x7f7f7f7f)
#define Max(a, b) ((a) > (b) ? (a) : (b))
#define Min(a, b) ((a) < (b) ? (a) : (b))
typedef long long ll;
using namespace std;
template <class T>
inline void read(T &x){
	int ch = 0, f = 0; x = 0;
	for(; !isdigit(ch); ch = getchar()) if(ch == '-') f = 1;
	for(; isdigit(ch); ch = getchar()) x = x * 10 + ch - 48;
	if(f) x = -x;
}
const int N = 2000005;
char s[N];
int n, m;
namespace AC{
	vector<int> g[N];
	queue<int> q;
	int ch[N][26], tr[N][26], fa[N], sum[N], pos[N], size = 1;
	inline void init(int n){
		for(int i = 1, x; i <= n; i++){
			sum[++size] = 1;
			int c = getchar() - 'A';
			read(x);
			ch[x+1][c] = size;
		}
	}
	inline void ins(char *str, int id){
		int n = strlen(str + 1), p = 1;
		for(int i = n; i >= 1; i--){
			int c = str[i] - 'A';
			if(!ch[p][c]) ch[p][c] = ++size;
			p = ch[p][c];
		}
		pos[id] = p;
	}
	inline void build(){
		for(int i = 0; i < 26; i++) tr[0][i] = 1;
		for(q.push(1); !q.empty(); q.pop()){
			int u = q.front();
			for(int i = 0; i < 26; i++){
				if(ch[u][i]){
					int v = ch[u][i];
					tr[u][i] = v;
					fa[v] = tr[fa[u]][i];
					q.push(v);
				}
				else tr[u][i] = tr[fa[u]][i];
			}
		}
		for(int i = 2; i <= size; i++)
			g[fa[i]].push_back(i);
	}
	inline void dfs(int u){
		for(auto v : g[u]) dfs(v), sum[u] += sum[v];
	}
}

int main(){
	read(n), read(m);
	AC::init(n);
	for(int i = 1; i <= m; i++){
		scanf("%s", s + 1);
		AC::ins(s, i);
	}
	AC::build();
	AC::dfs(1);
	for(int i = 1; i <= m; i++)
		printf("%d\n", AC::sum[AC::pos[i]]);
	return 0;
}

Details

Test #1:

score: 100
Accepted
time: 0ms
memory: 59116kb

Test #2:

score: 0
Accepted
time: 3ms
memory: 59128kb

Test #3:

score: 0
Accepted
time: 7ms
memory: 59108kb

Test #4:

score: 0
Accepted
time: 0ms
memory: 59408kb

Test #5:

score: 0
Accepted
time: 3ms
memory: 59088kb

Test #6:

score: 0
Accepted
time: 3ms
memory: 59364kb

Test #7:

score: 0
Accepted
time: 4ms
memory: 59120kb

Test #8:

score: 0
Accepted
time: 8ms
memory: 59136kb

Test #9:

score: 0
Accepted
time: 9ms
memory: 57344kb

Test #10:

score: 0
Accepted
time: 4ms
memory: 59104kb

Test #11:

score: 0
Accepted
time: 87ms
memory: 326636kb

Test #12:

score: 0
Accepted
time: 7ms
memory: 59096kb

Test #13:

score: 0
Accepted
time: 10ms
memory: 59372kb

Test #14:

score: 0
Accepted
time: 0ms
memory: 61376kb

Test #15:

score: 0
Accepted
time: 0ms
memory: 59096kb

Test #16:

score: 0
Accepted
time: 3ms
memory: 59088kb

Test #17:

score: 0
Accepted
time: 9ms
memory: 59160kb

Test #18:

score: 0
Accepted
time: 4ms
memory: 57120kb

Test #19:

score: 0
Accepted
time: 0ms
memory: 59348kb

Test #20:

score: 0
Accepted
time: 3ms
memory: 59088kb

Test #21:

score: 0
Accepted
time: 6ms
memory: 59092kb

Test #22:

score: 0
Accepted
time: 4ms
memory: 59100kb

Test #23:

score: 0
Accepted
time: 3ms
memory: 61984kb

Test #24:

score: 0
Accepted
time: 7ms
memory: 61764kb

Test #25:

score: 0
Accepted
time: 7ms
memory: 61252kb

Test #26:

score: 0
Accepted
time: 4ms
memory: 61540kb

Test #27:

score: 0
Accepted
time: 7ms
memory: 59248kb

Test #28:

score: 0
Accepted
time: 5ms
memory: 61324kb

Test #29:

score: 0
Accepted
time: 11ms
memory: 59540kb

Test #30:

score: 0
Accepted
time: 3ms
memory: 59652kb

Test #31:

score: 0
Accepted
time: 3ms
memory: 61724kb

Test #32:

score: 0
Accepted
time: 7ms
memory: 66696kb

Test #33:

score: 0
Accepted
time: 7ms
memory: 75748kb

Test #34:

score: 0
Accepted
time: 80ms
memory: 328992kb

Test #35:

score: 0
Accepted
time: 219ms
memory: 279516kb

Test #36:

score: 0
Accepted
time: 353ms
memory: 487936kb

Test #37:

score: 0
Accepted
time: 69ms
memory: 289536kb

Test #38:

score: 0
Accepted
time: 127ms
memory: 276464kb

Test #39:

score: 0
Accepted
time: 95ms
memory: 320252kb

Test #40:

score: 0
Accepted
time: 87ms
memory: 315004kb

Test #41:

score: 0
Accepted
time: 112ms
memory: 317468kb

Test #42:

score: 0
Accepted
time: 159ms
memory: 402032kb

Test #43:

score: 0
Accepted
time: 104ms
memory: 279472kb

Test #44:

score: 0
Accepted
time: 147ms
memory: 333252kb

Test #45:

score: 0
Accepted
time: 208ms
memory: 281488kb

Test #46:

score: 0
Accepted
time: 7ms
memory: 59048kb

Test #47:

score: 0
Accepted
time: 3ms
memory: 59084kb

Test #48:

score: 0
Accepted
time: 4ms
memory: 59092kb

Test #49:

score: 0
Accepted
time: 3ms
memory: 57264kb

Test #50:

score: 0
Accepted
time: 4ms
memory: 59096kb

Test #51:

score: 0
Accepted
time: 9ms
memory: 59324kb

Test #52:

score: 0
Accepted
time: 7ms
memory: 59096kb

Test #53:

score: 0
Accepted
time: 4ms
memory: 62364kb

Test #54:

score: 0
Accepted
time: 7ms
memory: 61756kb

Test #55:

score: 0
Accepted
time: 14ms
memory: 59112kb

Test #56:

score: 0
Accepted
time: 6ms
memory: 63376kb