QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#113193#1944. Circle of Friendsckiseki#WA 1ms3456kbC++143.1kb2023-06-16 17:20:402023-06-16 17:20:42

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-16 17:20:42]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3456kb
  • [2023-06-16 17:20:40]
  • 提交

answer

#include <bits/stdc++.h>
#ifdef CKISEKI
#define safe cerr<<__PRETTY_FUNCTION__<<" line "<<__LINE__<<" safe\n"
#define debug(a...) debug_(#a, a)
#define orange(a...) orange_(#a, a)
using std::cerr;
template <typename ...T>
void debug_(const char *s, T ...a) {
    cerr << "\e[1;32m(" << s << ") = (";
    int cnt = sizeof...(T);
    (..., (cerr << a << (--cnt ? ", " : ")\e[0m\n")));
}
template <typename I>
void orange_(const char *s, I L, I R) {
    cerr << "\e[1;32m[ " << s << " ] = [ ";
    for (int f = 0; L != R; ++L)
        cerr << (f++ ? ", " : "") << *L;
    cerr << " ]\e[0m\n";
}
#else
#define safe ((void)0)
#define debug(...) ((void)0)
#define orange(...) ((void)0)
#endif

#define all(v) begin(v),end(v)

using namespace std;

const int mod = 998244353;
const int64_t INF = (1LL << 60) - 1;

int modadd(int a, int b) {
    return a + b >= mod ? a + b - mod : a + b;
}
int modsub(int a, int b) {
    return a - b < 0 ? a - b + mod : a - b;
}

signed main() {
    cin.tie(nullptr) -> sync_with_stdio(false);
    int n;
    cin >> n;

    vector<int64_t> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        debug(bitset<5>(a[i]));
    }

    {
        int64_t totand = INF;
        for (int i = 0; i < n; i++)
            totand &= a[i];
        if (totand) {
            int ans = 1;
            for (int i = 0; i < n; i++)
                ans = modadd(ans, ans);
            cout << ans << '\n';
            return 0;
        }
    }

    vector<int> bad(n);
    {
        int idx[60] = {};
        for (int i = 0; i < n; i++) {
            int mn = 1e9;
            for (int j = 0; j < 60; j++) {
                if (!(a[i] >> j & 1)) {
                    idx[j] = i + 1;
                }
                mn = min(idx[j], mn);
            }
            bad[i] = mn;
        }
    }

    vector<int64_t> pre(n + 1), suf(n + 1);

    pre[0] = INF;
    for (int i = 0; i < n; i++) {
        pre[i + 1] = pre[i] & a[i];
    }

    suf[n] = INF;
    for (int i = n - 1; i >= 0; i--)
        suf[i] = suf[i + 1] & a[i];

    orange(all(bad));

    vector<int> dp(n + 1);
    vector<int> predp(n + 1);
    int ans = 0;

    {
        predp[0] = 0;
        for (int t = 0; t + 1 < n; t++) {
            if (pre[t + 1]) dp[t] = modadd(dp[t], 1);
            dp[t] = modadd(dp[t], modsub(predp[t], predp[bad[t]]));
            predp[t + 1] = modadd(predp[t], dp[t]);
            debug(t, dp[t], predp[t], suf[t + 1]);
            if (suf[t + 1]) ans = modadd(ans, dp[t]);
        }
        debug(dp[n]);
    }


    for (int i = 1, j; i < n; i = j) {
        for (j = i; j < n; j++)
            if (pre[j] != pre[i])
                break;
        debug(pre[i], i, j);

        fill(dp.begin(), dp.end(), 0);
        for (int t = i; t < j; t++)
            dp[t - 1] = 1;

        predp[0] = 0;
        for (int t = 0; t + 1 < n; t++) {
            dp[t] = modadd(dp[t], modsub(predp[t], predp[bad[t]]));
            predp[t + 1] = modadd(predp[t], dp[t]);
            if (suf[t + 1] & pre[i]) {
                debug(t, suf[t + 1], pre[i], dp[t], predp[t]);
                ans = modadd(ans, dp[t]);
            }
        }
    }

    cout << ans << '\n';

    return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3456kb

input:

1
1

output:

2

result:

wrong answer 1st lines differ - expected: '1', found: '2'