結果

問題 No.2895 Zero XOR Subset
ユーザー vjudge1
提出日時 2024-10-07 17:49:25
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 4,917 bytes
コンパイル時間 5,159 ms
コンパイル使用メモリ 333,132 KB
実行使用メモリ 6,824 KB
最終ジャッジ日時 2024-10-07 17:49:32
合計ジャッジ時間 7,324 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 35
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#ifdef ONLINE_JUDGE
#pragma GCC optimize(3, "Ofast", "inline")
#endif
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define rt return
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pu pair<ull, ull>
#define int long long
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define Endl endl
#define all(x) x.begin(), x.end()
#define all1(x) next(x.begin()), x.end()
#define lll __int128_t
#define ulll __uint128_t
using namespace std;
const int maxn = 1e5 + 50;
const int mod = 998244353;
const ll maxl = 2e18 + 5;
const int maxi = 1e9 + 7;
struct LinearBase
{
// ????? idx?1??
// ????? idx?0??
int N;
vector<ull> base;
vector<set<int>> idx;
int iffzero = 0;
LinearBase()
{
N = 105;
base.resize(102);
}
LinearBase(int n)
{
N = n + 5;
base.resize(n + 20);
idx.resize(n + 20);
}
void clear()
{
N = 0;
base.clear();
}
bool insert(ull x, int dx)
{
set<int> st;
st.insert(dx);
assert(N != 0);
for (int i = 62; i >= 0; i--)
{
if (!(x & (1ull << i)))
continue;
if (!base[i])
{
base[i] = x;
idx[i] = st;
return 1;
}
x ^= base[i];
for (auto j : idx[i])
{
if (st.contains(j))
{
st.erase(j);
}
else
st.insert(j);
}
if (x == 0)
{
iffzero = 1;
return false;
}
}
return 1;
}
void goass()
{
assert(N != 0);
sort(base.begin(), base.end(), greater<ull>());
int row = 0;
for (int i = 62; i >= 0; i--)
{
for (int j = row; j < N; j++)
{
if ((1ull << i) & base[j])
{
swap(base[j], base[row]);
swap(idx[j], idx[row]);
}
}
if (!((1ull << i) & base[row]))
continue;
for (int j = 0; j < N; j++)
{
if (j == row)
continue;
if ((1ull << i) & base[j])
{
base[j] ^= base[row];
}
}
row++;
}
}
void printbi(ull x)
{
for (int j = 62; j >= 0; j--)
{
if ((1ull << j) & x)
{
cerr << 1;
}
else
cerr << 0;
}
cerr << endl;
}
void print()
{
assert(N != 0);
for (int i = 0; i < N; i++)
{
for (int j = 62; j >= 0; j--)
{
if ((1ull << j) & base[i])
{
cerr << 1;
}
else
cerr << 0;
}
cerr << endl;
}
cerr << endl;
}
};
void init()
{
}
void solve()
{
int n;
cin >> n;
vector<ull> a(n + 1);
for (int i = 1; i <= n; i++)
cin >> a[i];
LinearBase lb(105);
set<int> ans;
vector<int> ans2;
for (int i = 1; i <= n; i++)
{
if (a[i] == 0)
ans2.push_back(i);
else if (!lb.insert(a[i], i))
{
// lb.goass();
ans.insert(i);
ull x = a[i];
for (int j = 62; j >= 0; j--)
{
if (!(x & (1ull << j)))
continue;
x ^= lb.base[j];
if (lb.idx[j].size())
{
for (auto k : lb.idx[j])
{
if (ans.contains(k))
{
ans.erase(k);
}
else
ans.insert(k);
}
}
}
break;
}
}
// ranges::sort(ans);
if (ans2.size() >= 1)
{
cout << ans2.size() << endl;
for (int i = 0; i < ans2.size(); i++)
{
cout << ans2[i] << " \n"[i == ans2.size() - 1];
}
}
else if (ans.size())
{
cout << ans.size() << endl;
for (auto i : ans)
{
cout << i << " ";
}
}
else
{
cout << -1 << endl;
}
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("1.txt", "r", stdin);
freopen("2.txt", "w", stdout);
#endif
std::ios::sync_with_stdio(0);
std::cin.tie(0);
int __ = 1;
// std::cin >> __;
init();
while (__--)
{
solve();
// cerr<<"TIME"<<qq-__<<endl;
}
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0