QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#130563#1944. Circle of Friendskaruna#TL 36ms70740kbC++171.4kb2023-07-24 16:12:492023-07-24 16:12:56

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-24 16:12:56]
  • 评测
  • 测评结果:TL
  • 用时:36ms
  • 内存:70740kb
  • [2023-07-24 16:12:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const int MAXN = 202020;
const ll MOD = 998244353;

int n; ll a[2 * MAXN], s[20][2 * MAXN], dp[2 * MAXN];
int main() {
    cin.tie(0); ios_base::sync_with_stdio(0);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[n + i] = a[i];
    }
    for (int i = 1; i <= 2 * n; i++) {
        s[0][i] = a[i];
    }
    for (int j = 1; j < 20; j++) {
        for (int i = (1 << j); i <= 2 * n; i++)
            s[j][i] = s[j - 1][i] & s[j - 1][i - (1 << (j - 1))];
    }
    ll ans = 0;
    for (int r = n + 1; r >= 1; ) {
        dp[r - 1] = 1;
        for (int i = r; i <= n; i++) dp[i] = 1;
        for (int i = n + 1; i <= 2 * n; i++) {
            ll x = a[i];
            int p = i;
            for (int j = 19; j >= 0; j--) {
                if ((x & s[j][p]) != 0) {
                    x = x & s[j][p];
                    p = p - (1 << j);
                }
                dp[i] = (dp[i - 1] + dp[i - 1]) % MOD;
                if (p != 0)
                    dp[i] = (dp[i] + MOD - dp[p - 1]) % MOD;
            }
        }
        int l = r;
        while (l >= 1 && (a[l] & a[r]) == a[r]) --l;

        ans = (ans + dp[n + r - 1] - dp[n + l - 1] + MOD) % MOD;
        r = l;
    }
    ll x = a[1];
    for (int i = 2; i <= n; i++) x &= a[i];

    if (x != 0) ans = (ans + MOD - n) % MOD;
    cout << ans << '\n';
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 9576kb

input:

1
1

output:

1

result:

ok single line: '1'

Test #2:

score: 0
Accepted
time: 2ms
memory: 9628kb

input:

1
1152921504606846975

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 25ms
memory: 70560kb

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: 36ms
memory: 70740kb

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: -100
Time Limit Exceeded

input:

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

output:


result: