QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#378287#1944. Circle of FriendsohiostatescarletWA 159ms57596kbC++171.7kb2024-04-06 10:50:262024-04-06 10:50:27

Judging History

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

  • [2024-04-06 10:50:27]
  • 评测
  • 测评结果:WA
  • 用时:159ms
  • 内存:57596kb
  • [2024-04-06 10:50:26]
  • 提交

answer

#include"bits/stdc++.h"
using namespace std;
#define L long long

L MOD = 998244353;

void solve(vector<L>&nums, vector<L>&dp) {
  L n = nums.size();
  vector<vector<L>> andR(n);
  for (L i = 0; i < n; i++) {
    andR[i].push_back(nums[i]);
    L j = 0;
    L p = 1;
    while (i-2*p+1 >= 0) {
      andR[i].push_back(andR[i][j] & andR[i-p][j]);
      j++;
      p <<= 1;
    }
  }
  dp.assign(n, 0);
  dp[0] = 1;
  vector<L> dpp(n+2, 0);
  dp[0] = dpp[1] = 1;
  dpp[2] = 2;
  for (L i = 1; i < n; i++) {
    L curr = nums[i];
    L p = i;
    L j = andR[i].size()-1;
    while (j >= 0 && p > 0) {
      if (curr & andR[p-1][j]) {
        curr &= andR[p-1][j];
        p -= (1 << j);
        j = min(j, (L)andR[p].size());
      }
      j--;
    }
    // cout << i << " -> " << p << "\n";
    dp[i] = (dpp[i+1] - dpp[p] + MOD) % MOD;
    dpp[i+2] = (dp[i] + dpp[i+1]) % MOD;
  }
  // for (L v : dp) {
  //   cout << v << " ";
  // }
  // cout << '\n';
}

// g++ -std=c++17 -O2 -DLOCAL -o a a.cpp
int main() {
  L n;
  cin >> n;
  vector<L> nums(n,0);
  L all = -1;
  for (L i = 0; i < n; i++) {
    cin >> nums[i];
    all &= nums[i];
  }
  vector<L> dp;
  solve(nums, dp);
  L res = dp[n-1];
  if (all) {
    cout << ((2 * res) % MOD - n + MOD) % MOD << '\n';
    return 0;
  }
  while (nums.size()>2&&nums[0]) {
    // cout << res << '\n';
    while (nums.size()>2 && (nums.back()&nums[0])==nums[0]) {
      nums.pop_back(); n--;
      res = (res + dp[n-1]) % MOD;
    }
    nums[0] = nums[0]&nums.back();
    nums.pop_back(); n--;
    if (nums[0]) {
      solve(nums, dp);
      res = (res + dp[n-1]) % MOD;
    }
  }
  cout << res << "\n";
}

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: 0ms
memory: 3592kb

input:

1
1152921504606846975

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 60ms
memory: 57596kb

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: 134ms
memory: 57464kb

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
Wrong Answer
time: 159ms
memory: 57464kb

input:

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

output:

594170968

result:

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