QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#463238#8770. Comparatorstd_abs#AC ✓156ms278912kbC++203.7kb2024-07-04 16:18:062024-07-04 16:18:07

Judging History

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

  • [2024-07-04 16:18:07]
  • 评测
  • 测评结果:AC
  • 用时:156ms
  • 内存:278912kb
  • [2024-07-04 16:18:06]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) ((int)a.size())
const int mod = 1e9 + 7, N = 100000;

struct ST {
	vector <vector <pii>> val;
	ST (vector <pii> a) {
		int n = a.size();
		int g = __lg(n) + 1;
		val.assign(g, vector <pii>(n));
		for (int i = 0; i < n; ++i) {
			val[0][i] = a[i];
		}
		for (int j = 1; j < g; ++j) {
			for (int i = 0; i + (1 << j) <= n; ++i) {
				val[j][i] = min(val[j - 1][i], val[j - 1][i + (1 << j - 1)]);
			}
		}
	}
	pii query(int l, int r) {
		int cg = __lg(r - l);
		return min(val[cg][l], val[cg][r - (1 << cg)]);
	}
};

vector <pii> solve(string s) {
	int n = s.size();
	vector <pii> val(n);
	for (int i = 0; i < n; ++i) {
		if (i) {
			val[i] = val[i - 1];
		}
		if (s[i] == '(') {
			val[i].first++;
			val[i].second = 6 * n + i;
		} else if (s[i] == ')') {
			val[i].first--;
			val[i].second = 6 * n + i;
		} else if (s[i] == '!') {
			val[i].second = 5 * n + i;
		} else if (s[i] == '=') {
			val[i].second = 4 * n + i;
		} else if (s[i] == '&') {
			val[i].second = 3 * n + i;
		} else if (s[i] == '|') {
			val[i].second = 2 * n + i;
		} else if (s[i] == '^') {
			val[i].second = 1 * n + i;
		} else {
			val[i].second = 7 * n + i;
		}
	}
	ST DS(val);

	auto solve = [&](auto self, int l, int r, int vx, int vy) -> int {
		if (r - l == 1) {
			if (s[l] == 'x') {
				return vx;
			} else if (s[l] == 'y') {
				return vy;
			} else {
				assert('0' <= s[l] && s[l] <= '1');
				return s[l] - '0';
			}
		}
		auto [dep, id] = DS.query(l, r);
		int type = id / n, pos = id % n;
		if (type == 1) {
			return self(self, l, pos, vx, vy) ^ self(self, pos + 1, r, vx, vy);
		} else if (type == 2) {
			return self(self, l, pos, vx, vy) | self(self, pos + 1, r, vx, vy);
		} else if (type == 3) {
			return self(self, l, pos, vx, vy) & self(self, pos + 1, r, vx, vy);
		} else if (type == 4) {
			return self(self, l, pos, vx, vy) == self(self, pos + 1, r, vx, vy);
		} else if (type == 5) {
			assert(pos == l);
			return self(self, l + 1, r, vx, vy) ^ 1;
		} else {
			assert(s[l] == '(' && s[r - 1] == ')');
			return self(self, l + 1, r - 1, vx, vy);
		}
	};
	
	vector <pii> res;
	for (int vx : {0, 1}) for (int vy : {0, 1}) {
		if (solve(solve, 0, n, vx, vy) == 1) {
			res.emplace_back(vx, vy);
		}
	}
	return res;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, k;
	cin >> n >> k;
	vector vis(2 * k, vector <int>(2 * k, false));
	vector <array <int, 5>> events;
	for (int i = 0; i < n; ++i) {
		int a, b; string s; int r;
		cin >> a >> b >> s >> r, --a, --b;
		auto res = solve(s);
		for (auto [x, y] : res) {
			int nx = a + x * k, ny = b + y * k;
			if (!vis[nx][ny]) {
				vis[nx][ny] = true;
				events.pb({a, x, b, y, r});
			}
		}
	}
	int final; cin >> final;
	vector table(1 << k, vector <int>(1 << k, final));
	vector <bitset <1024>> row(1 << k), col(1 << k);
	for (int x = 0; x < 1 << k; ++x) for (int y = 0; y < 1 << k; ++y) {
		for (auto [px, vx, py, vy, r] : events) {
			if ((x >> px & 1) == vx && (y >> py & 1) == vy) {
				table[x][y] = r;
				break;
			}
		}
		if (table[x][y]) {
			row[x][y] = 1, col[y][x] = 1;
		}
	}

	int cnt[3] = {0, 0, 0};
	for (int x = 0; x < 1 << k; ++x) if (table[x][x]) {
		cnt[0]++;
	}
	for (int x = 0; x < 1 << k; ++x) for (int y = 0; y < 1 << k; ++y) {
		if (table[x][y] == 1 && table[y][x] == 1) {
			cnt[1]++;
		}
	}
	for (int x = 0; x < 1 << k; ++x) for (int y = 0; y < 1 << k; ++y) {
		if (table[x][y] == 0) {
			cnt[2] += (row[x] & col[y]).count();
		}
	}

	cout << cnt[0] << ' ' << cnt[1] << ' ' << cnt[2] << '\n';
}

详细

Test #1:

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

input:

3 2
1 1 (x=0)&(y=1) 1
1 1 (x=1)&(y=(x^x)) 0
2 2 (x=1)|(y=0) 0
1

output:

0 0 0

result:

ok single line: '0 0 0'

Test #2:

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

input:

4 3
2 1 x=0&(y=1) 1
1 2 !x^!!y 0
2 3 ((x|1)=y)&1&1 1
3 1 !x&!x&!x 0
1

output:

3 25 52

result:

ok single line: '3 25 52'

Test #3:

score: 0
Accepted
time: 66ms
memory: 3904kb

input:

1413 3
1 3 0 0
3 3 !x 0
2 2 x=0 1
1 2 !y^0 1
2 3 (x^1) 0
3 2 ((!0)) 1
1 1 !!1=(y) 0
2 2 !(1^x)&y 1
3 2 (y)&1|!!1 0
3 1 !x=(y&y=y) 0
2 1 (((!1)^!x)) 1
2 3 !0=(0&y)=1&y 0
1 2 ((((!0)))|!1) 0
3 1 !(y=!1=x|(!x)) 0
1 1 ((((y=!y)))&!0) 0
2 3 ((y=1)^!1^!!1|0) 1
2 3 1|(!x)&!x|1|(x=1) 1
2 3 !0^!!!!y&0=(!1&!0...

output:

4 16 0

result:

ok single line: '4 16 0'

Test #4:

score: 0
Accepted
time: 120ms
memory: 7644kb

input:

181737 10
5 2 1 1
1 10 !1=!x 0
10 1 (1^x) 0
2 4 !1 1
10 8 y=(!1)^1 1
6 2 !((x&!x)) 1
1 10 !!((!x)|x) 1
7 10 (((0))) 0
7 3 !(1)^!x 0
10 4 (!1)&x 0
7 7 !y&!0 1
8 8 !1=(x)|1^1 1
2 6 ((!!!x)) 0
7 2 1 1
2 2 y=1=0 0
6 3 (!0) 0
6 4 0 0
1 1 (!1) 1
1 8 y 1
3 5 !x|!x^!1 0
4 7 (!0) 0
3 4 !1&1&!1|!0 1
2 7 ((0|1...

output:

1024 1048576 0

result:

ok single line: '1024 1048576 0'

Test #5:

score: 0
Accepted
time: 156ms
memory: 278912kb

input:

1 3
1 1 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!...

output:

4 16 0

result:

ok single line: '4 16 0'

Test #6:

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

input:

1 1
1 1 x^y|1 0
1

output:

1 1 0

result:

ok single line: '1 1 0'

Test #7:

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

input:

1 1
1 1 x&y|1 0
1

output:

0 0 0

result:

ok single line: '0 0 0'

Test #8:

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

input:

1 1
1 1 x=y|1 0
1

output:

0 0 0

result:

ok single line: '0 0 0'

Test #9:

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

input:

2 2
1 2 !x&!y 1
1 1 !x&y 0
1

output:

4 12 2

result:

ok single line: '4 12 2'

Test #10:

score: 0
Accepted
time: 66ms
memory: 12880kb

input:

2 10
9 8 ((((!((!x=1))^(!1&(x|x|!y))&((!y&!x=(x=y)))&!((((x=1))&(0=(y))^(!!(!!x^1=x)&(x)^y&1=!x&1=(((!0^(1)^1))^!(((((y))|x|!y))))^!!0=!y&(0)|(y=x&!y&y=x)))=((((!!y&!!0|!0^!0)=!x))))^0&(((!1=!(!x)))|(((((x=1|!y|y)=(!1^1^0^(0)))=!0^1)))=(!(!1^(((((!1)^!x^0))))=(1)^((((y=((x))|(0)|(!1^1)))|(!!!y))=((!...

output:

0 0 0

result:

ok single line: '0 0 0'

Test #11:

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

input:

4 3
1 1 !!!!!!x 0
2 1 !!y 1
1 2 !!!!!x 1
2 2 !!!x 0
1

output:

4 16 0

result:

ok single line: '4 16 0'

Test #12:

score: 0
Accepted
time: 12ms
memory: 36560kb

input:

1 1
1 1 ((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((((...

output:

1 1 0

result:

ok single line: '1 1 0'

Test #13:

score: 0
Accepted
time: 101ms
memory: 7592kb

input:

200000 10
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10 !x^!y 1
3 10...

output:

512 262144 134217728

result:

ok single line: '512 262144 134217728'

Test #14:

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

input:

10 3
3 1 (!x) 1
3 2 !1&x&1&!y 1
2 1 ((x)&y) 1
1 3 0 0
2 2 !1&0=y&0 1
3 3 (!y)^y 1
2 1 0|((!y)) 0
3 2 x 0
2 2 (y|1^x) 0
2 1 ((!0)|y) 0
1

output:

8 64 0

result:

ok single line: '8 64 0'

Test #15:

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

input:

0 3
1

output:

8 64 0

result:

ok single line: '8 64 0'