QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#182809#2343. First of Her NamePetroTarnavskyiCompile Error//C++172.2kb2023-09-18 16:13:342023-09-18 16:13:34

Judging History

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

  • [2023-09-18 16:13:34]
  • 评测
  • [2023-09-18 16:13:34]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, b, a) for(int i = (b) - 1; i >= (a); i--)
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int MAX = 1'000'447;
const int AL = 26;

struct Node
{
	int p;
	int c;
	int g[AL];
	int nxt[AL];
	int link;
	
	void init()
	{
		c = -1;
		p = -1;
		fill(g, g + AL, -1);
		fill(nxt, nxt + AL, -1);
		link = -1;
	}
};

struct AC
{
	node A[MAX];
	int sz;
	void init()
	{
		A[0].init();
		sz = 1;
	}
	void addStr(const string& s)
	{
		int x = 0;
		FOR (i, 0, SZ(s))
		{
			int c = s[i] - 'a';
			if (A[x].nxt[c] == -1)
			{
				A[x].nxt[c] = sz;
				A[sz].init();
				A[sz].c = c;
				A[sz].p = x;
				sz++;
			}
			x = A[x].nxt[c];
		}
	}
	int go(int x, int c)
	{
		if (A[x].g[c] == -1)
		{
			if (A[x].nxt[c] != -1)
				A[x].g[c] = A[x].nxt[c];
			else if (x != 0)
				A[x].g[c] = go(getLink(x), c);
			else
				A[x].g[c] = 0;
		}
		return A[x].g[c];
	}
	int getLink(int x)
	{
		if (A[x].link != -1)
			return A[x].link;
		if (x == 0 || A[x].p == 0)
			return 0;
		return A[x].link = go(getLink(A[x].p, A[x].c));
	}
} A;

int c[MAX];
VI g[MAX];
VI g2[MAX];
int a[MAX];
int val[MAX];

void dfs(int v, int x)
{
	x = A.go(x, c[v] - 'A');
	val[x]++;
	for (auto to : g[v])
		dfs(to, x);
}

void dfs2(int v)
{
	for (auto to : g2[v])
	{
		if (to != 0)
		{	
			dfs2(to);
			val[v] += val[to];
		}
	}
}


int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(15);
	
	int n, k;
	cin >> n >> k;
	vector<string> v(k);
	FOR (i, 0, n)
	{
		char ch;
		int par;
		cin >> ch >> par;
		c[i + 1] = ch;
		g[par].PB(i + 1);
	}
	A.init();
	FOR (i, 0, k)
	{
		cin >> v[i];
		reverse(ALL(v[i]));
		a[i] = A.addStr(v[i]);
	}
	FOR (i, 0, A.sz)
	{
		g2[A.getLink(i)].PB(i);
	}
	dfs(1, 0);
	dfs2(0);
	FOR (i, 0, k)
	{
		cout << val[a[i]] << '\n';
	}
	cerr << double(clock()) / CLOCKS_PER_SEC << '\n';
	
	return 0;
}


Details

answer.code:41:9: error: ‘node’ does not name a type; did you mean ‘Node’?
   41 |         node A[MAX];
      |         ^~~~
      |         Node
answer.code: In member function ‘void AC::init()’:
answer.code:45:17: error: ‘A’ was not declared in this scope; did you mean ‘AC’?
   45 |                 A[0].init();
      |                 ^
      |                 AC
answer.code: In member function ‘void AC::addStr(const string&)’:
answer.code:54:29: error: ‘A’ was not declared in this scope; did you mean ‘AC’?
   54 |                         if (A[x].nxt[c] == -1)
      |                             ^
      |                             AC
answer.code:62:29: error: ‘A’ was not declared in this scope; did you mean ‘AC’?
   62 |                         x = A[x].nxt[c];
      |                             ^
      |                             AC
answer.code: In member function ‘int AC::go(int, int)’:
answer.code:67:21: error: ‘A’ was not declared in this scope; did you mean ‘AC’?
   67 |                 if (A[x].g[c] == -1)
      |                     ^
      |                     AC
answer.code:76:24: error: ‘A’ was not declared in this scope; did you mean ‘AC’?
   76 |                 return A[x].g[c];
      |                        ^
      |                        AC
answer.code: In member function ‘int AC::getLink(int)’:
answer.code:80:21: error: ‘A’ was not declared in this scope; did you mean ‘AC’?
   80 |                 if (A[x].link != -1)
      |                     ^
      |                     AC
answer.code:82:31: error: ‘A’ was not declared in this scope; did you mean ‘AC’?
   82 |                 if (x == 0 || A[x].p == 0)
      |                               ^
      |                               AC
answer.code:84:24: error: ‘A’ was not declared in this scope; did you mean ‘AC’?
   84 |                 return A[x].link = go(getLink(A[x].p, A[x].c));
      |                        ^
      |                        AC
answer.code: In function ‘int main()’:
answer.code:137:32: error: void value not ignored as it ought to be
  137 |                 a[i] = A.addStr(v[i]);
      |                        ~~~~~~~~^~~~~~