正文
增加 12 行删除 12 行
10 行未改动11121314151617181925 行未改动4546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899013 行未改动10410510610710810911011111235 行未改动1481491501511521531541551565 行未改动1621631641651661671681691709 行未改动1801811821831841851861871881891901912 行未改动10 行未改动然后考虑乘和乘方。先考虑朴素的 $O(n^2)$ 乘法。(~~通过手工模拟可得~~),代码为:```c++for (int i = 0; i < K; i++)for (int j = 0; i + j < K; j++)r.k[i + j] += k[i] * x.k[j];```如果要求更高的速度,可以用 FFT 优化。但是本题数据范围比较小,所以不用。25 行未改动class poly {public:int k[K];poly () { memset (k, 0, sizeof k); }poly (const poly &x) { memcpy (k, x.k, sizeof k); }poly &operator = (const poly &x) { memcpy (k, x.k, sizeof k); return *this; }poly (int x, bool flag = false) { memset (k, 0, sizeof k), k[flag] = x; }poly operator + (const poly &x) {poly r;for (int i = 0; i < K; i++) r.k[i] = (k[i] + x.k[i]) % P;return r;}poly operator - (const poly &x) {poly r;for (int i = 0; i < K; i++) r.k[i] = (k[i] + P - x.k[i]) % P;return r;}poly operator * (const poly &x) {poly r;for (int i = 0; i < K; i++) for (int j = 0; i + j < K; j++) (r.k[i + j] += k[i] * x.k[j] % P) %= P;return r;}poly operator ^ (int x) {poly r = *this, p = *this;--x;while (x) {if (x & 1) r = r * p;x >>= 1, p = p * p;}return r;}bool operator == (const poly &x) {for (int i = 0; i < K; i++) if (k[i] != x.k[i]) return false;return true;}friend ostream &operator << (ostream &out, const poly &x) {for (int i = K - 1; i >= 2; i--) if (x.k[i]) {if (x.k[i] == 1) out << "a^" << i << " + ";else if (x.k[i] == -1) out << "-a^" << i << " + ";13 行未改动void ins (char c){poly y, x;if (c == '(') return;if (q.empty ()) cout << "fuck off", exit (0);y = q.top (), q.pop ();if (q.empty ()) cout << "fuck off", exit (0);35 行未改动q.push (poly (x));if (c == '\n') break;else continue;}switch (c) {case 'a': q.push (poly (1, true)); break;case '(': op.push ('('), level++; break;case ')':5 行未改动op.push (c); break;}while (space (c = getchar ()) && c != '\n');} while (c != '\n');while (!op.empty ()) ins (op.top ()), op.pop ();return q.top ();}9 行未改动signed main (void){int n;poly res;res = expand ();n = read ();for (int i = 1; i <= n; i++) if (expand () == res) putchar ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i - 1]);putchar ('\n');return 0;}2 行未改动10 行未改动11121314151617181925 行未改动4546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899013 行未改动10410510610710810911011111235 行未改动1481491501511521531541551565 行未改动1621631641651661671681691709 行未改动1801811821831841851861871881891901912 行未改动10 行未改动然后考虑乘和乘方。先考虑朴素的 $O(n^2)$ 乘法。(~~通过手工模拟可得~~),代码为:```c++for (int i = 0; i < K; i++)for (int j = 0; i + j < K; j++)r.k[i + j] += k[i] * x.k[j];```如果要求更高的速度,可以用 FFT 优化。但是本题数据范围比较小,所以不用。25 行未改动class poly {public:int k[K];poly () { memset (k, 0, sizeof k); }poly (const poly &x) { memcpy (k, x.k, sizeof k); }poly &operator = (const poly &x) { memcpy (k, x.k, sizeof k); return *this; }poly (int x, bool flag = false) { memset (k, 0, sizeof k), k[flag] = x; }poly operator + (const poly &x) {poly r;for (int i = 0; i < K; i++) r.k[i] = (k[i] + x.k[i]) % P;return r;}poly operator - (const poly &x) {poly r;for (int i = 0; i < K; i++) r.k[i] = (k[i] + P - x.k[i]) % P;return r;}poly operator * (const poly &x) {poly r;for (int i = 0; i < K; i++) for (int j = 0; i + j < K; j++) (r.k[i + j] += k[i] * x.k[j] % P) %= P;return r;}poly operator ^ (int x) {poly r = *this, p = *this;--x;while (x) {if (x & 1) r = r * p;x >>= 1, p = p * p;}return r;}bool operator == (const poly &x) {for (int i = 0; i < K; i++) if (k[i] != x.k[i]) return false;return true;}friend ostream &operator << (ostream &out, const poly &x) {for (int i = K - 1; i >= 2; i--) if (x.k[i]) {if (x.k[i] == 1) out << "a^" << i << " + ";else if (x.k[i] == -1) out << "-a^" << i << " + ";13 行未改动void ins (char c){poly y, x;if (c == '(') return;if (q.empty ()) cout << "fuck off", exit (0);y = q.top (), q.pop ();if (q.empty ()) cout << "fuck off", exit (0);35 行未改动q.push (poly (x));if (c == '\n') break;else continue;}switch (c) {case 'a': q.push (poly (1, true)); break;case '(': op.push ('('), level++; break;case ')':5 行未改动op.push (c); break;}while (space (c = getchar ()) && c != '\n');} while (c != '\n');while (!op.empty ()) ins (op.top ()), op.pop ();return q.top ();}9 行未改动signed main (void){int n;poly res;res = expand ();n = read ();for (int i = 1; i <= n; i++) if (expand () == res) putchar ("ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i - 1]);putchar ('\n');return 0;}2 行未改动