QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#378127 | #1944. Circle of Friends | ohiostatescarlet | WA | 226ms | 57524kb | C++17 | 1.6kb | 2024-04-06 05:40:48 | 2024-04-06 05:40:49 |
Judging History
answer
#include"bits/stdc++.h"
using namespace std;
#define L long long
L MOD = 998244353;
void solve(vector<L>&nums, vector<L>&dp) {
int n = nums.size();
vector<vector<L>> andR(n);
for (int i = 0; i < n; i++) {
andR[i].push_back(nums[i]);
int j = 0;
int 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 (int i = 1; i < n; i++) {
L curr = nums[i];
int p = i;
int 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, (int)andR[p].size());
}
j--;
}
dp[i] = (dpp[i+1] - dpp[p] + MOD) % MOD;
dpp[i+2] = (dp[i] + dpp[i+1]) % MOD;
}
}
// g++ -std=c++17 -O2 -DLOCAL -o a a.cpp
int main() {
int n;
cin >> n;
vector<L> nums(n,0);
L all = -1;
for (int 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]) {
while (nums.size()>2 && (nums.back()&nums[0])==nums[0]) {
nums.pop_back();
n--;
res = (res + dp[n-2]) % MOD;
}
if (nums.size()) {
nums[0] = nums[0]&nums.back();
nums.pop_back();
n--;
solve(nums, dp);
res = (res + dp[n-1]) % MOD;
}
}
cout << res << "\n";
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
input:
1 1
output:
1
result:
ok single line: '1'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3540kb
input:
1 1152921504606846975
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 62ms
memory: 57524kb
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: 142ms
memory: 57476kb
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: 226ms
memory: 57444kb
input:
200000 18031990763159554 108095195748368386 36029346783428610 184085739649376272 577639437895209218 72057594042191904 4508276314083330 9078671805521920 144255925580990466 432490704060547904 72059793094738017 562967269607456 26424786302976 68719476738 333275855713337352 11370333479109156 290271086772...
output:
84686674
result:
wrong answer 1st lines differ - expected: '697849429', found: '84686674'