QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#108110#6507. Recover the Stringwoyouxiangbaile#WA 5ms11264kbC++144.5kb2023-05-23 16:34:572023-05-23 16:34:59

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-05-23 16:34:59]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:11264kb
  • [2023-05-23 16:34:57]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define rep(i, d, u) for(int i = d; i <= u; ++i)
#define dep(i, u, d) for(int i = u; i >= d; --i)
#define cep(n) while(n--)
#define gep(i, a) for(int i = firs[a]; i; i = neig[i])
int ured() {
	int re = 0;
	char ch;
	do {
		ch = getchar();
	} while('9' < ch || ch < '0');
	do {
		re = re * 10 + (ch ^ '0');
	} while('0' <= (ch = getchar()) && ch <= '9');
	return re;
}
void uwit(int da) {
	int ch[21], cn = 0;
	do {
		ch[++cn] = da - da / 10 * 10;
	} while(da /= 10);
	do {
		putchar('0' ^ ch[cn]);
	} while(--cn);
}
mt19937 tran(time(0) * 1000 + clock());
int iran(int le, int ri) {
	uniform_int_distribution<int> re(le, ri);
	return re(tran);
}
const int _maxn = 1000011, _maxa = 1000000, _maxm = 2000011, _modf = 1000000007, _mods = 1000000009;
int qpow(int da, int up, int mo) {
	int re = 1;
	while(up) {
		if(up & 1) {
			re = 1ll * re * da % mo;
		}
		da = 1ll * da * da % mo, up >>= 1;
	}
	return re;
}
int fbas[_maxn], sbas[_maxn], finv, sinv;
struct mhas {
	int fh, sh, ln;
	mhas() {}
	mhas(int da) : fh(da), sh(da), ln(1) {}
	mhas(int fi, int se, int th) : fh(fi), sh(se), ln(th) {}
} zdat[_maxn], fdat[_maxn];
mhas operator+(mhas le, mhas ri) {
	return mhas((1ll * le . fh * fbas[ri . ln] + ri . fh) % _modf, (1ll * le . sh * sbas[ri . ln] + ri . sh) % _mods, le . ln + ri . ln);
}
mhas operator-(mhas le, int ri) {
	return mhas(1ll * (le . fh - ri + _modf) * finv % _modf, 1ll * (le . sh - ri + _mods) * sinv % _mods, le . ln - 1);
}
mhas operator-(int le, mhas ri) {
	return mhas((1ll * (_modf - fbas[ri . ln - 1]) * le + ri . fh) % _modf, (1ll * (_mods - sbas[ri . ln - 1]) * le + ri . sh) % _mods, ri . ln - 1);
}
bool operator==(mhas le, mhas ri) {
	return le . fh == ri . fh && le . sh == ri . sh && le . ln == ri . ln;
}
int t, n, m, u, v, lson[_maxn], rson[_maxn], indu[_maxn], firs[_maxn], neig[_maxm], arri[_maxm], queu[_maxn], head, tail;
int tdat[_maxn], edat[_maxn], cnts, atno;
bool stat[_maxn][2];
int main() {
	t = ured(), fbas[0] = sbas[0] = 1, fbas[1] = iran(10000, 100000), sbas[1] = iran(200000, 300000);
	rep(i, 2, _maxa) {
		fbas[i] = 1ll * fbas[i - 1] * fbas[1] % _modf, sbas[i] = 1ll * sbas[i - 1] * sbas[1] % _mods;
	}
	finv = qpow(fbas[1], _modf - 2, _modf), sinv = qpow(sbas[1], _mods - 2, _mods);
	cep(t) {
		n = ured(), m = ured();
		rep(i, 1, n) {
			lson[i] = rson[i] = indu[i] = firs[i] = 0;
		}
		rep(i, 1, m) {
			u = ured(), v = ured(), neig[i] = firs[u], firs[u] = i, arri[i] = v;
			if(lson[v]) {
				rson[v] = u;
			} else {
				lson[v] = u;
			}
			++indu[v];
		}
		head = tail = cnts = 0;
		rep(i, 1, n) {
			if(!indu[i]) {
				queu[++tail] = i;
			}
		}
		while(head < tail) {
			atno = queu[++head];
			if(lson[atno] && rson[atno]) {
				if(tdat[lson[atno]] - zdat[lson[atno]] == zdat[rson[atno]] - edat[rson[atno]]) {
					zdat[atno] = zdat[lson[atno]] + edat[rson[atno]], fdat[atno] = fdat[rson[atno]] + tdat[lson[atno]];
					tdat[atno] = tdat[lson[atno]], edat[atno] = edat[rson[atno]], stat[atno][0] = 0, stat[atno][1] = 0;
				} else if(tdat[lson[atno]] - zdat[lson[atno]] == fdat[rson[atno]] - tdat[rson[atno]]) {
					zdat[atno] = zdat[lson[atno]] + tdat[rson[atno]], fdat[atno] = fdat[rson[atno]] + tdat[lson[atno]];
					tdat[atno] = tdat[lson[atno]], edat[atno] = tdat[rson[atno]], stat[atno][0] = 0, stat[atno][1] = 1;
				} else if(edat[lson[atno]] - fdat[lson[atno]] == zdat[rson[atno]] - edat[rson[atno]]) {
					zdat[atno] = zdat[lson[atno]] + edat[rson[atno]], fdat[atno] = fdat[rson[atno]] + edat[lson[atno]];
					tdat[atno] = edat[lson[atno]], edat[atno] = edat[rson[atno]], stat[atno][0] = 1, stat[atno][1] = 0;
				} else if(edat[lson[atno]] - fdat[lson[atno]] == fdat[rson[atno]] - tdat[rson[atno]]) {
					zdat[atno] = zdat[lson[atno]] + tdat[rson[atno]], fdat[atno] = fdat[rson[atno]] + edat[lson[atno]];
					tdat[atno] = edat[lson[atno]], edat[atno] = tdat[rson[atno]], stat[atno][0] = 1, stat[atno][1] = 1;
				}
			} else if(lson[atno]) {
				zdat[atno] = fdat[atno] = zdat[lson[atno]] + edat[lson[atno]], tdat[atno] = edat[atno] = tdat[lson[atno]];
			} else {
				zdat[atno] = fdat[atno] = mhas(tdat[atno] = edat[atno] = cnts++);
			}
			gep(i, atno) {
				if(!--indu[arri[i]]) {
					queu[++tail] = arri[i];
				}
			}
		}
		for(int i = 1, j = queu[tail], k = 0; j; ++i) {
			if(k) {
				putchar('a' + tdat[j]), k = stat[j][1], j = rson[j];
			} else {
				putchar('a' + edat[j]), k = stat[j][0], j = lson[j];
			}
		}
		putchar('\n');
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 5ms
memory: 11264kb

input:

3
1 0
5 6
2 4
2 5
5 3
4 3
1 5
1 4
8 11
1 2
1 4
1 6
2 5
3 4
3 6
4 5
4 7
5 8
6 7
7 8

output:

a
bab
abaa

result:

wrong answer 2nd lines differ - expected: 'aba', found: 'bab'