QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#715685#6961. XOR Subsequencehejinming983282#AC ✓96ms5776kbC++231.7kb2024-11-06 13:01:492024-11-06 13:01:50

Judging History

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

  • [2024-11-06 13:01:50]
  • 评测
  • 测评结果:AC
  • 用时:96ms
  • 内存:5776kb
  • [2024-11-06 13:01:49]
  • 提交

answer

// Author : hejinming2012
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define dbg(x) cout << #x " = " << (x) << endl
#define quickio ios::sync_with_stdio(false);
#define quickin cin.tie(0);
#define quickout cout.tie(0);
#define maxn 300005
using namespace std;
inline int read() {
    int now = 0, nev = 1; char c = getchar();
    while(c < '0' || c > '9') { if(c == '-') nev = -1; c = getchar(); }
    while(c >= '0' && c <= '9') { now = (now << 1) + (now << 3) + (c & 15); c = getchar(); }
    return now * nev;
}
void write(int x) {
    if(x < 0) putchar('-'), x = -x;
    if(x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
int n, a[maxn];
bool ok;
void work() {
    int i, k = 1, j = 1ll << 30;
    for( ; j; j >>= 1) {
        for(i = k; i <= n; i++)
            if(a[i] & j) break ;
        if(i > n) continue ;
        swap(a[i], a[k]);
        for(i = 1; i <= n; i++)
            if(i != k && a[i] & j) a[i] ^= a[k];
        k++;
    }
    k--;
    if(k != n) ok = 1;
    else ok = 0;
    n = k;
}
signed main() {
    quickio
    quickin
    quickout
    int T = read();
    while(T--) {
        n = read(); int sum = 0;
        int tmp = (1ll << n) - 1;
        swap(n, tmp);
        for(int i = 1; i <= n; i++)
            a[i] = read(), sum ^= a[i];
        if(n == 1) {
            write(a[1]), putchar(10);
            continue ;
        }
        if(sum != 0) {
            write(-1), putchar(10);
            continue ;
        }
        work();
        while(tmp > n) write(0), putchar(' '), tmp--;
        for(int i = n; i >= 1; i--)
            write(a[i]), putchar(' ');
        putchar(10);
    }
    return 0;
}

详细

Test #1:

score: 100
Accepted
time: 96ms
memory: 5776kb

input:

4115
1
220426753
2
75752216 139004411 214624995
3
425320853 659634699 1040767902 61426054 620262285 1033998872 451979283
4
289669156 16842978 272957638 16779852 289737354 21236708 4456872 268501358 285213068 272894568 4524806 21299530 68270 285281058 268438464
5
288507119 704365180 764545802 9869220...

output:

220426753
75752216 139004411 
61426054 425320853 620262285 
68270 4456872 16779852 268438464 
25699612 34220493 74041718 280650227 678684512 
-1
0 0 0 67108864 134217728 268435456 536870912 
136604 6052763 27897018 37591031 75573769 136661209 279830679 547648454 
2026397 2791316 8827893 17803262 381...

result:

ok 4115 lines