记录编号 602817 评测结果 RRRRRRRRRR
题目名称 4167.镜牢 最终得分 0
用户昵称 Gravatar小福鑫 是否通过 未通过
代码语言 C++ 运行时间 1.406 s
提交时间 2025-07-05 21:42:59 内存使用 3.36 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int N = 1e5 + 10;
long long a[N], b[N], p[N];
int c[N];
char str[N];
long long ans;
int n;

int main() {
    int t;
    scanf("%d", &t);
    while (t--) {
        scanf("%d", &n);
        ans = 0;
        for (int i = 1; i <= n; i++) {
            scanf("%lld", &a[i]);
            ans ^= a[i];
        }
        for (int i = 1; i <= n; i++) {
            scanf("%lld", &b[i]);
            p[i] = a[i] ^ b[i];
        }
        scanf("%s", str + 1);
        for (int i = 1; i <= n; i++) {
            c[i] = str[i] - '0';
        }

        for (int i = 60; i >= 0; i--) {
            int lst = 0;
            for (int j = 1; j <= n; j++) {
                if ((p[j] >> i) & 1) {
                    lst = j;
                }
            }
            if (lst) {
                if ((((ans >> i) & 1) == 0 && c[lst] == 1) || 
                    (((ans >> i) & 1) == 1 && c[lst] == 0)) {
                    ans ^= p[lst];
                }
                for (int j = 1; j <= n; j++) {
                    if ((p[j] >> i) & 1) {
                        p[j] ^= p[lst];
                    }
                }
            }
        }
        printf("%lld\n", ans);
    }
    return 0;
}