QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#248276 | #7679. Master of Both IV | ucup-team859# | WA | 21ms | 3748kb | C++14 | 2.5kb | 2023-11-11 18:07:23 | 2023-11-11 18:07:23 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
using ll = long long;
using ull = unsigned long long;
string to_string(const string &s) {
return '"' + s + '"';
}
string to_string(bool b) {
return b ? "true" : "false";
}
template <typename A, typename B>
string to_string(const pair<A, B> &p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename T>
string to_string(const T &v) {
string s = "{";
bool first = true;
for (const auto &it : v) {
if (!first)
s += ", ";
else
first = false;
s += to_string(it);
}
return s += "}";
}
void debug_out() {
cerr << endl;
}
template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
cerr << to_string(first) << " ";
debug_out(rest...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
auto startTime = high_resolution_clock::now();
int get_time() {
auto stopTime = chrono::high_resolution_clock::now();
auto duration = duration_cast<milliseconds>(stopTime - startTime);
return duration.count(); // in ms
}
const int MOD = 998244353;
void add_to_b(vector<int> &b, int &nrb, int x) {
for (int bit = 20; bit >= 0; --bit) {
if (x & (1 << bit)) {
if (b[bit] == 0) {
b[bit] = x;
++nrb;
continue;
}
x ^= b[bit];
}
}
}
int lgput(int x, int p) {
int ans = 1, aux = x;
for (int i = 1; i <= p; i <<= 1) {
if (i & p)
ans = 1LL * ans * aux % MOD;
aux = 1LL * aux * aux % MOD;
}
return ans;
}
void solve() {
int n;
cin >> n;
vector<int> f(n + 1, 0);
vector<int> cnt(n + 1, 0);
vector<int> nr(n + 1, 0);
vector<vector<int>> b(n + 1, vector<int> (21, 0));
for (int i = 1; i <= n; ++i) {
int x;
cin >> x;
++f[x];
}
int ans = 0;
for (int i = 1; i <= n; ++i) {
if (!f[i])
continue;
add_to_b(b[0], nr[0], i);
for (int j = i * 2; j <= n; j += i) {
add_to_b(b[j], nr[j], i);
cnt[j] += f[i];
}
ans = (1LL * ans + 1LL * lgput(2, cnt[i] - nr[i] + f[i] - 1)) % MOD;
}
ans = (1LL * ans + 1LL * lgput(2, n - nr[0]) - 1 + MOD) % MOD;
cout << ans << '\n';
}
int main() {
cin.tie(NULL);
ios_base::sync_with_stdio(false);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3748kb
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: 21ms
memory: 3632kb
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:
9 16 9 9 8 8 9 8 8 9 9 8 8 8 8 9 12 9 11 15 8 8 17 13 8 11 8 8 8 13 15 9 9 8 8 8 11 9 11 13 15 9 17 9 8 8 8 9 11 8 9 11 8 8 11 15 9 8 9 8 8 15 11 8 17 9 15 8 8 8 12 9 9 11 8 13 9 8 15 8 8 9 8 8 8 15 8 11 9 8 9 11 8 19 11 13 19 17 9 15 8 8 8 9 8 9 9 15 17 9 9 17 9 11 9 9 11 9 9 11 8 9 9 13 15 11 8 11...
result:
wrong answer 11th numbers differ - expected: '13', found: '9'