QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#113200 | #1944. Circle of Friends | rgnerdplayer# | WA | 4ms | 4656kb | C++20 | 4.8kb | 2023-06-16 17:33:27 | 2023-06-16 17:33:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
template <int MOD, int ROOT = 3>
struct Modint {
static constexpr int P = MOD;
static constexpr int RT = ROOT;
private:
int v;
static int minv(int a, int m) {
a %= m;
assert(a);
return a == 1 ? 1 : m - 1LL * minv(m, a) * m / a;
}
public:
Modint() : v(0) {}
Modint(i64 v_) : v(v_ % P) {
if (v < 0) v += P;
}
explicit operator int() const { return v; }
friend ostream& operator<<(ostream &out, const Modint &n) {
return out << int(n);
}
friend istream& operator>>(istream &in, Modint &n) {
i64 v;
in >> v;
n = Modint(v);
return in;
}
friend string to_string(Modint a) {
return to_string(int(a));
}
friend bool operator==(const Modint &a, const Modint &b) {
return a.v == b.v;
}
friend bool operator!=(const Modint &a, const Modint &b) {
return a.v != b.v;
}
Modint inv() const {
Modint res;
res.v = minv(v, P);
return res;
}
Modint operator-() const {
Modint res;
res.v = v ? P - v : 0;
return res;
}
Modint& operator++() {
v++;
if (v == P) v = 0;
return *this;
}
Modint& operator--() {
if (v == 0) v = P;
v--;
return *this;
}
Modint& operator+=(const Modint &o) {
v -= P - o.v;
v = (v < 0) ? v + P : v;
return *this;
}
Modint& operator-=(const Modint &o) {
v -= o.v;
v = (v < 0) ? v + P : v;
return *this;
}
Modint& operator*=(const Modint &o) {
v = 1LL * v * o.v % P;
return *this;
}
Modint& operator/=(const Modint &o) { return *this *= o.inv(); }
friend Modint operator++(Modint &a, int) {
Modint r = a;
++a;
return r;
}
friend Modint operator--(Modint &a, int) {
Modint r = a;
--a;
return r;
}
friend Modint operator+(const Modint &a, const Modint &b) {
return Modint(a) += b;
}
friend Modint operator-(const Modint &a, const Modint &b) {
return Modint(a) -= b;
}
friend Modint operator*(const Modint &a, const Modint &b) {
return Modint(a) *= b;
}
friend Modint operator/(const Modint &a, const Modint &b) {
return Modint(a) /= b;
}
Modint qpow(i64 p) {
Modint res = 1, x = v;
while (p > 0) {
if (p & 1) res *= x;
x *= x;
p >>= 1;
}
return res;
}
};
constexpr int P = 998244353;
using Mint = Modint<P>;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
auto solve = [&]() {
int n;
cin >> n;
vector<i64> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
{
i64 all = -1;
for (int i = 0; i < n; i++) {
all &= a[i];
}
if (all != 0) {
cout << Mint(2).qpow(n - 1) << '\n';
return;
}
}
Mint ans = 0;
auto work = [&](vector<i64> a) {
int n = a.size();
int lg = __lg(n) + 1;
vector f(lg + 1, vector<i64>(n));
f[0] = a;
for (int i = 1; i <= lg; i++) {
for (int j = 0; j + (1 << i) <= n; j++) {
f[i][j] = f[i - 1][j] & f[i - 1][j + (1 << i - 1)];
}
}
vector<Mint> dp(n + 1), suf(n + 2);
dp[n] = suf[n] = 1;
for (int i = n - 1; i >= 0; i--) {
int j = i;
for (int b = lg, cur = -1; b >= 0; b--) {
if (j + (1 << b) <= n && (cur & f[b][j]) != 0) {
cur &= f[b][j];
j += 1 << b;
}
}
dp[i] = suf[i + 1] - suf[j + 1];
suf[i] = suf[i + 1] + dp[i];
}
ans += dp[0];
int p = 0, cur = a.back();
while (p < n && (cur & a[p]) == a.back()) {
cur &= a[p];
ans += dp[++p];
}
cur &= a[p++];
a.back() = cur;
return vector<i64>(a.begin() + p, a.end());
};
while (!count(a.begin(), a.end(), 0)) {
auto b = work(a);
swap(a, b);
}
cout << ans << '\n';
};
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 3536kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3448kb
input:
1 1152921504606846975
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 4ms
memory: 4656kb
input:
200000 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1...
output:
895248717
result:
wrong answer 1st lines differ - expected: '792053081', found: '895248717'