QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#188126#7508. Fast Debugger_set_AC ✓319ms393076kbC++203.8kb2023-09-25 15:22:082023-09-25 15:22:08

Judging History

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

  • [2023-09-25 15:22:08]
  • 评测
  • 测评结果:AC
  • 用时:319ms
  • 内存:393076kb
  • [2023-09-25 15:22:08]
  • 提交

answer

// test std

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

typedef long long s64;
const int N = 12000 + 5, INF = int(1e9) + 5;
int readReg() {
	string reg;
	cin >> reg;
	return reg[0] - 'a';
}
int vis[16];
struct G {
	int nex[16];
	vector<int> chain[16], cycle[16];
	void init() {
		for (int j = 0; j < 16; ++j) {
			memset(vis, 0, sizeof(vis));
			int nt = 0, x = j;
			while (!vis[x]) {
				vis[x] = nt;
				++nt;
				x = nex[x];
			}
			int y = j;
			while (y != x) {
				chain[j].push_back(y);
				y = nex[y];
			}
			cycle[j].push_back(y);
			while ((y = nex[y]) != x)
				cycle[j].push_back(y);
		}
	}
	int calc(int t, int j) {
		return t < chain[j].size() ? chain[j][t] : cycle[j][(t - chain[j].size()) % cycle[j].size()];
	}
};
struct Op {
	int t, tot_1, tot;
	vector<Op*> son;
	vector<int> sum;
	vector<array<G, 8>> g1;
	G g[8];
	void read(string str) {
		int a, b;
		a = readReg();
		g1.resize(1);
		if (str.back() != 'i') {
			b = readReg();
			for (int i = 0; i < 8; ++i)
				for (int j = 0; j < 16; ++j) {
					int va = (j >> a) & 1,
						vb = (j >> b) & 1;
					int k = j ^ ((va ^ (str[0] == 'o' ? (va | vb) : (str[0] == 'a' ? (va & vb) : (va ^ vb)))) << a);
					g[i].nex[j] = g1[0][i].nex[j] = k;
				}
		} else {
			cin >> b;
			for (int i = 0; i < 8; ++i)
				for (int j = 0; j < 16; ++j) {
					int va = (j >> a) & 1,
						vb = (b >> i) & 1;
					int k = j ^ ((va ^ (str[0] == 'o' ? (va | vb) : (str[0] == 'a' ? (va & vb) : (va ^ vb)))) << a);
					g[i].nex[j] = g1[0][i].nex[j] = k;
				}
		}
		for (int i = 0; i < 8; ++i) {
			g[i].init();
			g1[0][i].init();
		}
	}
	void init(bool is_root) {
		if (!t) {
			tot_1 = tot = 1;
			return;
		}
		tot_1 = 0;
		auto son0 = son;
		son.clear();
		for (auto op: son0) {
			op->init(0);
			if (op->t == 1) {
				son.insert(son.end(), op->son.begin(), op->son.end());
			} else
				son.push_back(op);
			tot_1 = min(INF, tot_1 + op->tot);
		}
		if (tot_1 == INF) t = 1;
		tot = min(s64(INF), s64(tot_1) * t);
		if (t == 1 && !is_root) return;
		sum.resize(son.size() + 1);
		g1.resize(son.size() + 1);
		for (int i = 0; i < 8; ++i)
			for (int j = 0; j < 16; ++j)
				g1[0][i].nex[j] = j;
		for (int h = 0; h < son.size(); ++h) {
			sum[h + 1] = min(INF, sum[h] + son[h]->tot);
			for (int i = 0; i < 8; ++i) {
				for (int j = 0; j < 16; ++j) {
					g1[h + 1][i].nex[j] = son[h]->g[i].nex[g1[h][i].nex[j]];
				}
			}
		}
		for (int h = 0; h <= son.size(); ++h)
			for (int i = 0; i < 8; ++i)
				g1[h][i].init();
		for (int i = 0; i < 8; ++i) {
			for (int j = 0; j < 16; ++j)
				g[i].nex[j] = g1.back()[i].calc(t, j);
			g[i].init();
		}
	}
	int calc(int i, int k, int j) {
		assert(k <= tot);
		if (k >= tot_1) {
			j = g1.back()[i].calc(k / tot_1, j);
			k %= tot_1;
		}
		if (!k) return j;
		int h = lower_bound(sum.begin(), sum.end(), k) - sum.begin() - 1;
		return son[h]->calc(i, k - sum[h], g1[h][i].nex[j]);
	}
};
Op op[N];

int main() {
#ifdef kcz
	freopen("1.in", "r", stdin); //freopen("1.out","w",stdout);
#endif
	int n, q;
	cin >> n >> q;
	int t = 0;
	vector<int> st;
	++t;
	op[1].t = 1;
	st.push_back(1);
	for (int tmp = 1; tmp <= n; ++tmp) {
		string str;
		cin >> str;
		if (str == "end") {
			st.pop_back();
		} else {
			++t;
			op[st.back()].son.push_back(op + t);
			if (str == "repeat") {
				st.push_back(t);
				scanf("%d", &op[t].t);
			} else {
				op[t].read(str);
			}
		}
	}
	op[1].init(1);
	while (q--) {
		int k, a[4];
		cin >> k;
		for (int i = 0; i < 4; ++i) {
			cin >> a[i];
		}
		int ans[4] = {};
		for (int i = 0; i < 8; ++i) {
			int j = 0;
			for (int k = 0; k < 4; ++k) j |= ((a[k] >> i) & 1) << k;
			int x = op[1].calc(i, k, j);
			for (int k = 0; k < 4; ++k) ans[k] |= ((x >> k) & 1) << i;
		}
		for (int i = 0; i < 4; ++i) cout << ans[i] << " \n"[i == 3];
	}
}

详细

Test #1:

score: 100
Accepted
time: 4ms
memory: 82760kb

input:

6 2
repeat 5
xor ax bx
xori ax 3
and cx ax
xor cx dx
end
10 1 2 4 3
8 4 1 2 3

output:

0 2 2 3
4 1 3 3

result:

ok 8 numbers

Test #2:

score: 0
Accepted
time: 319ms
memory: 393076kb

input:

11982 10000
repeat 2
repeat 2
andi bx 201
xori cx 241
repeat 4
xor cx bx
xor ax dx
repeat 8
or dx bx
xori dx 22
end
repeat 2
xor dx bx
xor dx bx
repeat 7
xor bx bx
or cx dx
and bx cx
end
andi dx 33
xori ax 179
xori bx 56
end
xori dx 63
xori cx 91
xori dx 228
or cx dx
repeat 6
xor cx dx
xori bx 198
x...

output:

24 195 0 75
0 195 0 245
199 193 6 13
252 73 245 67
0 0 0 0
51 0 0 245
99 26 0 196
51 195 0 75
247 253 247 37
119 198 119 186
235 235 44 36
4 0 181 0
76 228 253 0
51 245 245 33
119 119 176 0
198 198 1 11
199 93 154 3
106 106 152 21
93 92 42 3
236 236 247 147
198 198 204 135
0 51 0 75
119 118 10 151
1...

result:

ok 40000 numbers

Test #3:

score: 0
Accepted
time: 307ms
memory: 393064kb

input:

11978 10000
repeat 3
repeat 3
xor ax dx
xori cx 74
repeat 2
repeat 2
repeat 10
xor bx dx
xori bx 167
xor dx bx
and cx bx
end
xori cx 140
xor bx cx
repeat 5
repeat 2
xor ax cx
xor ax cx
xor bx ax
repeat 2
xor bx cx
xori bx 237
xori ax 68
xor cx cx
and cx bx
xori ax 225
end
xor dx dx
repeat 5
repeat 5...

output:

141 144 167 0
250 230 51 0
243 168 87 0
195 106 164 164
151 138 51 151
94 34 164 94
245 207 174 0
59 152 164 164
219 239 54 147
49 1 27 0
186 96 30 0
70 15 143 0
43 70 0 0
46 207 138 138
150 146 164 50
114 180 164 114
19 155 164 164
69 249 253 147
236 100 5 72
202 160 184 157
192 90 234 0
246 164 78...

result:

ok 40000 numbers

Test #4:

score: 0
Accepted
time: 312ms
memory: 389912kb

input:

11981 10000
repeat 5
repeat 4
or cx ax
repeat 2
xor ax ax
repeat 6
xori dx 75
xor cx dx
ori ax 200
xori ax 90
and cx bx
xori bx 10
end
repeat 6
ori dx 63
xor bx dx
end
xor cx cx
xori dx 157
end
xori cx 137
xor bx dx
repeat 5
repeat 3
xori bx 43
xor dx dx
xor cx ax
xori ax 116
xori bx 239
xori dx 87
...

output:

103 34 24 11
0 102 129 2
103 34 24 108
142 108 142 142
253 34 253 201
0 35 253 0
20 111 20 2
71 34 95 0
139 109 139 2
253 34 253 201
35 50 20 209
0 102 133 2
135 49 171 184
0 35 253 2
0 34 205 142
98 239 205 145
2 103 0 2
117 34 13 68
242 235 20 17
165 34 24 210
117 34 192 123
16 160 8 134
18 0 167 ...

result:

ok 40000 numbers

Test #5:

score: 0
Accepted
time: 300ms
memory: 390500kb

input:

11986 10000
repeat 5
and ax cx
repeat 5
xori ax 116
xor bx dx
xori bx 66
xori bx 206
repeat 2
xor bx bx
xor bx dx
xor cx bx
end
end
repeat 5
xor ax cx
xor cx bx
xori bx 22
repeat 4
repeat 7
or ax dx
xor cx bx
end
repeat 5
xori dx 24
or dx ax
repeat 3
repeat 9
xori cx 249
xori ax 168
xor dx cx
andi a...

output:

0 89 9 0
0 89 25 0
0 155 229 199
0 89 25 230
0 89 25 0
0 89 9 0
0 89 9 0
0 89 25 0
78 224 9 7
209 148 76 154
0 89 9 0
0 126 230 229
0 126 229 196
0 255 230 230
0 89 9 0
0 89 139 0
0 89 9 230
0 89 25 0
0 89 9 0
0 89 9 0
0 89 9 191
0 89 25 0
0 126 230 196
0 89 9 0
0 89 9 0
78 10 248 84
0 89 9 0
0 0 25...

result:

ok 40000 numbers