QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#113212#1944. Circle of Friendsckiseki#AC ✓86ms10208kbC++143.3kb2023-06-16 17:49:392023-06-16 17:49:40

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:49:40]
  • 评测
  • 测评结果:AC
  • 用时:86ms
  • 内存:10208kb
  • [2023-06-16 17:49:39]
  • 提交

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 + 1);
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        debug(bitset<5>(a[i]));
    }

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

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

    vector<int64_t> pre(n + 2), suf(n + 2);
    pre[0] = INF;
    for (int i = 1; i <= n; i++) {
        pre[i] = pre[i - 1] & a[i];
    }
    suf[n + 1] = INF;
    for (int i = n; i >= 1; i--)
        suf[i] = suf[i + 1] & a[i];

    vector<int> dp(n + 2);
    vector<int> predp(n + 2);

    int ans = 0;
    {
        dp[0] = 1;
        predp[0] = 1;
        for (int i = 1; i <= n; i++) {
            // bad[i] := minimum j, AND(a[j], a[j+1], ... a[i]) != 0
            // dp[i] =
            // dp[i-1]+dp[i-2]+...+dp[bad[i]+1] + dp[bad[i]]
            dp[i] = modsub(predp[i - 1], (bad[i] == 0 ? 0 : predp[bad[i] - 1]));
            predp[i] = modadd(predp[i - 1], dp[i]);
        }
        debug(dp[n]);
        ans = 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;

        dp[0] = predp[0] = 0;
        for (int t = 1; t <= n; t++) {
            dp[t] = modadd(dp[t], modsub(predp[t - 1], (bad[t] == 0 ? 0 : predp[bad[t] - 1])));
            predp[t] = modadd(predp[t - 1], dp[t]);
            if (t + 1 <= n && 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: 100
Accepted
time: 1ms
memory: 3468kb

input:

1
1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 1ms
memory: 3544kb

input:

1
1152921504606846975

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 5ms
memory: 4644kb

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:

792053081

result:

ok single line: '792053081'

Test #4:

score: 0
Accepted
time: 10ms
memory: 4584kb

input:

200000
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606...

output:

792053081

result:

ok single line: '792053081'

Test #5:

score: 0
Accepted
time: 45ms
memory: 10108kb

input:

200000
18031990763159554
108095195748368386
36029346783428610
184085739649376272
577639437895209218
72057594042191904
4508276314083330
9078671805521920
144255925580990466
432490704060547904
72059793094738017
562967269607456
26424786302976
68719476738
333275855713337352
11370333479109156
290271086772...

output:

697849429

result:

ok single line: '697849429'

Test #6:

score: 0
Accepted
time: 46ms
memory: 10104kb

input:

200000
38878877261704467
606583538776039621
325557318447172624
513696235393139082
288309595180245073
22000404187620950
28465258695911754
432534927738538528
217932069505099992
8444275091048961
378456596858036610
909745820721741897
10707049231951490
869769773255361289
1054197601224687632
2974146034978...

output:

472024961

result:

ok single line: '472024961'

Test #7:

score: 0
Accepted
time: 70ms
memory: 10200kb

input:

200000
231835759121035702
510237390901680560
1089228954142887951
546561500990948259
452812301317437416
674492659073810407
610376405449845423
336095507987037999
1104321677521773827
257064906190991194
551711390461204674
320506912224540602
57990152440076744
845010071877357771
403229887439671683
2693178...

output:

117345155

result:

ok single line: '117345155'

Test #8:

score: 0
Accepted
time: 62ms
memory: 10208kb

input:

200000
1041523633558056719
1133745259996491747
395753651864850428
1151926721450571413
1114422491360386046
1152921229520204786
1116662492370558395
1006273041715269578
86101463265049534
359143197109542363
242065648916576479
903956062749589338
1091893347132366767
670735077154993663
1142330444352434159
...

output:

648136624

result:

ok single line: '648136624'

Test #9:

score: 0
Accepted
time: 54ms
memory: 10148kb

input:

200000
1148136361283288575
864128178497519103
504403123704430591
1080722898202656703
1150660907089100671
1148417885111055871
1133781167519004367
1152921229712162815
1152902245931548635
1152846703454314239
1152358485925492735
1134766329820016511
1080863910560530363
1071715973758713727
468354552857362...

output:

21378100

result:

ok single line: '21378100'

Test #10:

score: 0
Accepted
time: 81ms
memory: 10200kb

input:

200000
576460752303419383
1150669704793159679
1152921504606846847
1152921504598458367
1143914030474199039
1152921504606846975
1152921504606846967
1152921504590069759
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152640029630136319
11529215046068...

output:

557285638

result:

ok single line: '557285638'

Test #11:

score: 0
Accepted
time: 78ms
memory: 10172kb

input:

200000
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606...

output:

438039103

result:

ok single line: '438039103'

Test #12:

score: 0
Accepted
time: 85ms
memory: 10180kb

input:

200000
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606...

output:

440098984

result:

ok single line: '440098984'

Test #13:

score: 0
Accepted
time: 86ms
memory: 10132kb

input:

200000
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606846975
1152921504606...

output:

413438309

result:

ok single line: '413438309'