QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#778650 | #7679. Master of Both IV | liliwa | WA | 576ms | 121952kb | C++23 | 1.5kb | 2024-11-24 15:36:14 | 2024-11-24 15:36:15 |
Judging History
answer
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
typedef long long ll;
using namespace std;
#define rep(i, a, b) for(ll i = (a); i <= (b); i++)
#define lep(i, a, b) for(ll i = (a); i >= (b); i--)
// #define int ll
using namespace std;
const ll p = 998244353;
const int N = 1e6 + 10;
vector<int> e[N];
ll n, m, k;
ll a[N], bs[N], cnt[N];
ll qmi(ll a, ll b)
{
if(b < 0) return 1;
ll res = 1;
for(; b; b >>= 1, a = a * a % p) if(b & 1) res = res * a % p; return res;
}
ll insert(ll x)
{
lep(i, 20, 0) if(x >> i & 1)
{
if(bs[i] == 0)
{
bs[i] = x; return 1;
}
x ^= bs[i];
}
return 0;
}
void solve()
{
cin >> n;
rep(i, 0, 20) bs[i] = 0; rep(i, 1, n) cnt[i] = 0;
ll c1 = 0;
rep(i, 1, n) cin >> a[i], c1 += insert(a[i]), cnt[a[i]]++;
ll res = qmi(2ll, n - c1) - 1; res = (res % p + p) % p;
//cout << res << '\n';
rep(i, 1, n)
{
ll c2 = 0, c3 = 0; rep(i, 0, 20) bs[i] = 0;
for(auto j : e[a[i]]) if(j < a[i]) c2 += cnt[j], c3 += insert(j);
//cout << a[i] << ' ' << qmi(2, c2 - c3) << ' ' << c2 << ' ' << c3 << '\n';
(res += qmi(2, c2 - c3)) %= p;
}
cout << (res % p + p) % p << '\n';
}
// 101 011 001
signed main()
{
IOS;
int T = 1;
for(ll i = 1; i <= N - 1; i++) for(ll j = i; j <= N - 1; j += i) e[j].push_back(i);
cin>>T;
while(T--) solve();
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 541ms
memory: 121900kb
input:
2 3 1 2 3 5 3 3 5 1 1
output:
4 11
result:
ok 2 number(s): "4 11"
Test #2:
score: -100
Wrong Answer
time: 576ms
memory: 121952kb
input:
40000 5 4 2 5 5 5 5 5 5 5 5 4 5 1 4 4 4 2 5 2 5 2 4 1 5 3 2 4 5 3 5 1 5 5 3 4 5 5 5 5 4 3 5 4 3 3 5 1 5 4 5 5 2 1 5 2 5 4 2 5 5 3 4 3 4 3 5 5 3 5 1 3 5 5 1 2 4 4 5 4 2 5 1 5 5 5 4 2 5 4 5 5 2 5 2 4 5 1 4 5 4 5 5 4 2 3 2 3 5 1 4 1 3 5 5 1 1 2 1 5 5 5 2 5 1 3 5 3 1 2 5 3 5 5 5 1 1 5 5 2 2 2 1 3 5 3 1 ...
output:
8 12 8 9 8 8 8 8 8 8 12 8 8 8 8 8 12 8 10 14 8 8 15 12 8 11 8 8 8 12 15 9 8 8 8 8 11 9 10 12 14 8 12 8 8 8 8 12 11 8 8 11 8 8 10 14 9 8 8 8 8 14 11 8 15 8 13 8 8 8 12 9 8 11 8 13 9 8 14 8 8 8 8 8 8 15 8 11 12 8 9 11 8 16 11 13 18 12 12 14 8 8 8 8 8 8 12 14 15 8 8 12 9 10 8 8 11 8 8 11 8 9 8 12 13 11...
result:
wrong answer 1st numbers differ - expected: '9', found: '8'